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 java.net.MalformedURLException;
20  import java.net.URL;
21  
22  /**
23   * JUnit test case for EmailAttachment Class
24   *
25   * @since 1.0
26   * @author <a href="mailto:corey.scott@gmail.com">Corey Scott</a>
27   * @version $Id: EmailAttachmentTest.java 1420381 2012-12-11 20:18:05Z tn $
28   */
29  public class EmailAttachmentTest extends BaseEmailTestCase
30  {
31      /** */
32      private EmailAttachment attachment;
33  
34      /**
35       * @param name name
36       */
37      public EmailAttachmentTest(String name)
38      {
39          super(name);
40      }
41  
42      /**
43       * @throws Exception  */
44      @Override
45      protected void setUp() throws Exception
46      {
47          super.setUp();
48          // reusable objects to be used across multiple tests
49          this.attachment = new EmailAttachment();
50      }
51  
52      /** */
53      public void testGetSetDescription()
54      {
55  
56          for (int i = 0; i < testCharsValid.length; i++)
57          {
58              this.attachment.setDescription(testCharsValid[i]);
59              assertEquals(testCharsValid[i], this.attachment.getDescription());
60          }
61      }
62  
63      /** */
64      public void testGetSetName()
65      {
66  
67          for (int i = 0; i < testCharsValid.length; i++)
68          {
69              this.attachment.setName(testCharsValid[i]);
70              assertEquals(testCharsValid[i], this.attachment.getName());
71          }
72      }
73  
74      /** */
75      public void testGetSetPath()
76      {
77  
78          for (int i = 0; i < testCharsValid.length; i++)
79          {
80              this.attachment.setPath(testCharsValid[i]);
81              assertEquals(testCharsValid[i], this.attachment.getPath());
82          }
83      }
84  
85      /** */
86      public void testGetSetURL()
87      {
88          String[] tests =
89              {
90                  "http://localhost/",
91                  "http://www.apache.org/",
92                  "http://foo.notexisting.org" };
93  
94          for (int i = 0; i < tests.length; i++)
95          {
96              try
97              {
98                  URL testURL = new URL(tests[i]);
99                  this.attachment.setURL(testURL);
100                 assertEquals(testURL, this.attachment.getURL());
101             }
102             catch (MalformedURLException e)
103             {
104                 fail(e.getMessage());
105             }
106         }
107     }
108 
109     /** */
110     public void testGetSetDisposition()
111     {
112 
113         for (int i = 0; i < testCharsValid.length; i++)
114         {
115             this.attachment.setDisposition(testCharsValid[i]);
116             assertEquals(testCharsValid[i], this.attachment.getDisposition());
117         }
118     }
119 
120 }