source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/types/EnumeratedAttributeTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 2.8 KB
Line 
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
18package org.apache.tools.ant.types;
19
20import org.apache.tools.ant.BuildException;
21
22import junit.framework.TestCase;
23import junit.framework.AssertionFailedError;
24
25/**
26 * JUnit 3 testcases for org.apache.tools.ant.EnumeratedAttribute.
27 *
28 */
29
30public class EnumeratedAttributeTest extends TestCase {
31
32 private static String[] expected = {"a", "b", "c"};
33
34 public EnumeratedAttributeTest(String 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 other) {
71 fail("unexpected death of TestNull: "+other.getMessage());
72 }
73 }
74
75 public static class TestNormal extends EnumeratedAttribute {
76 public String[] getValues() {
77 return expected;
78 }
79 }
80
81 public static class TestNull extends EnumeratedAttribute {
82 public String[] getValues() {
83 return null;
84 }
85 }
86}
Note: See TracBrowser for help on using the repository browser.