1 18 package net.sf.uitags.tagutil; 19 20 import java.util.Arrays ; 21 import java.util.Properties ; 22 23 import junit.framework.TestCase; 24 import net.sf.uitags.testutil.PrivilegedAccessor; 25 26 32 public final class TaglibPropertiesTest extends TestCase { 33 36 private TaglibProperties props; 37 38 43 public static void main(String [] args) { 44 junit.textui.TestRunner.run(TaglibPropertiesTest.class); 45 } 46 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 this.props = TaglibProperties.getInstance(); 51 } 52 53 54 protected void tearDown() throws Exception { 55 super.tearDown(); 56 this.props = null; 57 } 58 59 66 public void testGetInstance() 67 throws IllegalAccessException , NoSuchFieldException { 68 TaglibProperties props1 = TaglibProperties.getInstance(); 69 Properties siteWide1 = 70 (Properties ) PrivilegedAccessor.getValue(props1, "mergedProps"); 71 72 TaglibProperties props2 = TaglibProperties.getInstance(); 73 Properties siteWide2 = 74 (Properties ) PrivilegedAccessor.getValue(props2, "mergedProps"); 75 76 assertSame(siteWide1, siteWide2); 77 } 78 79 84 public void testSetAndGetStringProperty() { 85 String testValue = "dummy test value"; 86 this.props.setRuntimeProperty("testKey", testValue); 87 String value = this.props.get("testKey"); 88 assertEquals(testValue, value); 89 90 this.props.setRuntimeProperty("testKey", (String ) null); 92 assertEquals(testValue, this.props.get("testKey")); 93 } 94 95 99 public void testGetAsNonNullString() { 100 String nonExistantKey = "This is so ridiculous it can never be a key"; 101 try { 102 this.props.get(nonExistantKey); 103 fail("Searching for a non-existant key should throw an exception"); 104 } 105 catch (IllegalStateException e) { 106 } 108 } 109 110 115 public void testSetAndGetStringArrayProperty() { 116 String [] testValues = new String [] { "dummy", "test", "values" }; 117 this.props.setRuntimeProperty( 118 "calendar.listMonths.monthLabels", testValues); 119 assertEquals("dummy,test,values", 120 this.props.get("calendar.listMonths.monthLabels")); 121 assertEquals(Arrays.asList(testValues), Arrays.asList( 122 this.props.getAsArray("calendar.listMonths.monthLabels"))); 123 124 this.props.setRuntimeProperty( 126 "calendar.listMonths.monthLabels", (String []) null); 127 assertEquals(Arrays.asList(testValues), Arrays.asList( 128 this.props.getAsArray("calendar.listMonths.monthLabels"))); 129 } 130 131 136 public void testGetAsEmptyStringArray() { 137 String nonExistantKey = "This is so ridiculous it can never be a key"; 138 try { 139 this.props.getAsArray(nonExistantKey); 140 fail("Searching for a non-existant key should throw an exception"); 141 } 142 catch (IllegalStateException e) { 143 } 145 } 146 } | Popular Tags |