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 511703 2007-02-26 02:45:23Z dion $
28   */
29  
30  public class EmailAttachmentTest extends BaseEmailTestCase
31  {
32      /** */
33      private EmailAttachment attachment;
34  
35      /**
36       * @param name name
37       */
38      public EmailAttachmentTest(String name)
39      {
40          super(name);
41      }
42  
43      /**
44       * @throws Exception  */
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://bad.url.com" };
93  
94          for (int i = 0; i < tests.length; i++)
95          {
96              // TODO: Document why malformed url is ok, or remove the catch
97              try
98              {
99                  URL testURL = new URL(tests[i]);
100                 this.attachment.setURL(testURL);
101                 assertEquals(testURL, this.attachment.getURL());
102             }
103             catch (MalformedURLException e)
104             {
105                 e.printStackTrace();
106                 continue;
107             }
108         }
109     }
110 
111     /** */
112     public void testGetSetDisposition()
113     {
114 
115         for (int i = 0; i < testCharsValid.length; i++)
116         {
117             this.attachment.setDisposition(testCharsValid[i]);
118             assertEquals(testCharsValid[i], this.attachment.getDisposition());
119         }
120     }
121 
122 }