View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.mail;
18  
19  import static org.junit.Assert.*;
20  
21  import java.net.URL;
22  
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  /**
27   * JUnit test case for EmailAttachment Class.
28   *
29   * @since 1.0
30   * @version $Id: EmailAttachmentTest.java 1523306 2013-09-14 19:54:01Z tn $
31   */
32  public class EmailAttachmentTest extends AbstractEmailTest
33  {
34      private EmailAttachment attachment;
35  
36      @Before
37      public void setUpAttachmentTest()
38      {
39          attachment = new EmailAttachment();
40      }
41  
42      @Test
43      public void testGetSetDescription()
44      {
45          for (String validChar : testCharsValid)
46          {
47              attachment.setDescription(validChar);
48              assertEquals(validChar, attachment.getDescription());
49          }
50      }
51  
52      @Test
53      public void testGetSetName()
54      {
55          for (String validChar : testCharsValid)
56          {
57              attachment.setName(validChar);
58              assertEquals(validChar, attachment.getName());
59          }
60      }
61  
62      @Test
63      public void testGetSetPath()
64      {
65          for (String validChar : testCharsValid)
66          {
67              attachment.setPath(validChar);
68              assertEquals(validChar, attachment.getPath());
69          }
70      }
71  
72      @Test
73      public void testGetSetURL() throws Exception
74      {
75          String[] tests =
76              {
77                  "http://localhost/",
78                  "http://www.apache.org/",
79                  "http://foo.notexisting.org" };
80  
81          for (String urlString : tests)
82          {
83              URL testURL = new URL(urlString);
84              attachment.setURL(testURL);
85              assertEquals(testURL, attachment.getURL());
86          }
87      }
88  
89      @Test
90      public void testGetSetDisposition()
91      {
92          for (String validChar : testCharsValid)
93          {
94              attachment.setDisposition(validChar);
95              assertEquals(validChar, attachment.getDisposition());
96          }
97      }
98  
99  }