001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.mail; 018 019 import java.net.MalformedURLException; 020 import java.net.URL; 021 022 /** 023 * JUnit test case for EmailAttachment Class 024 * 025 * @since 1.0 026 * @author <a href="mailto:corey.scott@gmail.com">Corey Scott</a> 027 * @version $Id: EmailAttachmentTest.java 511703 2007-02-26 02:45:23Z dion $ 028 */ 029 030 public class EmailAttachmentTest extends BaseEmailTestCase 031 { 032 /** */ 033 private EmailAttachment attachment; 034 035 /** 036 * @param name name 037 */ 038 public EmailAttachmentTest(String name) 039 { 040 super(name); 041 } 042 043 /** 044 * @throws Exception */ 045 protected void setUp() throws Exception 046 { 047 super.setUp(); 048 // reusable objects to be used across multiple tests 049 this.attachment = new EmailAttachment(); 050 } 051 052 /** */ 053 public void testGetSetDescription() 054 { 055 056 for (int i = 0; i < testCharsValid.length; i++) 057 { 058 this.attachment.setDescription(testCharsValid[i]); 059 assertEquals(testCharsValid[i], this.attachment.getDescription()); 060 } 061 } 062 063 /** */ 064 public void testGetSetName() 065 { 066 067 for (int i = 0; i < testCharsValid.length; i++) 068 { 069 this.attachment.setName(testCharsValid[i]); 070 assertEquals(testCharsValid[i], this.attachment.getName()); 071 } 072 } 073 074 /** */ 075 public void testGetSetPath() 076 { 077 078 for (int i = 0; i < testCharsValid.length; i++) 079 { 080 this.attachment.setPath(testCharsValid[i]); 081 assertEquals(testCharsValid[i], this.attachment.getPath()); 082 } 083 } 084 085 /** */ 086 public void testGetSetURL() 087 { 088 String[] tests = 089 { 090 "http://localhost/", 091 "http://www.apache.org/", 092 "http://bad.url.com" }; 093 094 for (int i = 0; i < tests.length; i++) 095 { 096 // TODO: Document why malformed url is ok, or remove the catch 097 try 098 { 099 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 }