1 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 29 30 public 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 } 87 | Popular Tags |