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: */
018:
019: package org.apache.tools.ant.taskdefs.email;
020:
021: import junit.framework.TestCase;
022:
023: /**
024: * @since Ant 1.6
025: */
026: public class EmailAddressTest extends TestCase {
027:
028: public EmailAddressTest(String name) {
029: super (name);
030: }
031:
032: public void setUp() {
033: }
034:
035: public void test1() {
036: expectNameAddress(new EmailAddress("address (name)"));
037: }
038:
039: public void test2() {
040: expectNameAddress(new EmailAddress("(name) address"));
041: }
042:
043: public void test3() {
044: expectNameAddress(new EmailAddress("name <address>"));
045: }
046:
047: public void test4() {
048: expectNameAddress(new EmailAddress("<address> name"));
049: }
050:
051: public void test5() {
052: expectNameAddress(new EmailAddress("<address> (name)"));
053: }
054:
055: public void test6() {
056: expectNameAddress(new EmailAddress("(name) <address>"));
057: }
058:
059: public void test7() {
060: expectNameAddress2(new EmailAddress("address (<name>)"));
061: }
062:
063: public void test8() {
064: expectNameAddress2(new EmailAddress("(<name>) address"));
065: }
066:
067: public void test9() {
068: expectNameAddress3(new EmailAddress("address"));
069: }
070:
071: public void testA() {
072: expectNameAddress3(new EmailAddress("<address>"));
073: }
074:
075: public void testB() {
076: expectNameAddress3(new EmailAddress(" <address> "));
077: }
078:
079: public void testC() {
080: expectNameAddress3(new EmailAddress("< address >"));
081: }
082:
083: public void testD() {
084: expectNameAddress3(new EmailAddress(" < address > "));
085: }
086:
087: private void expectNameAddress(EmailAddress e) {
088: assertEquals("name", e.getName());
089: assertEquals("address", e.getAddress());
090: }
091:
092: // where the name contains <>
093: private void expectNameAddress2(EmailAddress e) {
094: assertEquals("<name>", e.getName());
095: assertEquals("address", e.getAddress());
096: }
097:
098: // where only an address is supplied
099: private void expectNameAddress3(EmailAddress e) {
100: assertTrue("Expected null, found <" + e.getName() + ">", e
101: .getName() == null);
102: assertEquals("address", e.getAddress());
103: }
104: }
|