KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > EnumeratedAttributeTest


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.types;
19
20 import org.apache.tools.ant.BuildException;
21
22 import junit.framework.TestCase;
23 import junit.framework.AssertionFailedError;
24
25 /**
26  * JUnit 3 testcases for org.apache.tools.ant.EnumeratedAttribute.
27  *
28  */

29
30 public class EnumeratedAttributeTest extends TestCase {
31
32     private static String JavaDoc[] expected = {"a", "b", "c"};
33
34     public EnumeratedAttributeTest(String JavaDoc name) {
35         super(name);
36     }
37
38     public void testContains() {
39         EnumeratedAttribute t1 = new TestNormal();
40         for (int i=0; i<expected.length; i++) {
41             assertTrue(expected[i]+" is in TestNormal",
42                    t1.containsValue(expected[i]));
43             assertTrue(expected[i].toUpperCase()+" is in TestNormal",
44                    !t1.containsValue(expected[i].toUpperCase()));
45         }
46         assertTrue("TestNormal doesn\'t have \"d\" attribute",
47                !t1.containsValue("d"));
48         assertTrue("TestNull doesn\'t have \"d\" attribute and doesn\'t die",
49                !(new TestNull()).containsValue("d"));
50     }
51
52     public void testExceptions() {
53         EnumeratedAttribute t1 = new TestNormal();
54         for (int i=0; i<expected.length; i++) {
55             try {
56                 t1.setValue(expected[i]);
57             } catch (BuildException be) {
58                 fail("unexpected exception for value "+expected[i]);
59             }
60         }
61         try {
62             t1.setValue("d");
63             fail("expected exception for value \"d\"");
64         } catch (BuildException be) {
65         }
66         try {
67             (new TestNull()).setValue("d");
68             fail("expected exception for value \"d\" in TestNull");
69         } catch (BuildException be) {
70         } catch (Throwable JavaDoc other) {
71             fail("unexpected death of TestNull: "+other.getMessage());
72         }
73     }
74
75     public static class TestNormal extends EnumeratedAttribute {
76         public String JavaDoc[] getValues() {
77             return expected;
78         }
79     }
80
81     public static class TestNull extends EnumeratedAttribute {
82         public String JavaDoc[] getValues() {
83             return null;
84         }
85     }
86 }
87
Popular Tags