ebourg 2004/09/21 11:14:44 Modified: configuration/src/test/org/apache/commons/configuration/beanutils TestConfigurationDynaBean.java Log: Code formating Revision Changes Path 1.4 +481 -356 jakarta-commons/configuration/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java Index: TestConfigurationDynaBean.java =================================================================== RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/beanutils/TestConfigurationDynaBean.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestConfigurationDynaBean.java 20 Sep 2004 15:55:08 -0000 1.3 +++ TestConfigurationDynaBean.java 21 Sep 2004 18:14:44 -0000 1.4 @@ -1,18 +1,18 @@ /* * Copyright 2001-2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.apache.commons.configuration.beanutils; @@ -33,8 +33,8 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Gladwell</a> * @version $Revision$ */ -public class TestConfigurationDynaBean extends TestCase { - +public class TestConfigurationDynaBean extends TestCase +{ /** * The basic test bean for each test. */ @@ -46,80 +46,90 @@ * when new properties are added to TestBean. */ String[] properties = { - "booleanProperty", - "booleanSecond", - "doubleProperty", - "floatProperty", - "intProperty", - "longProperty", - "mappedProperty.key1", - "mappedProperty.key2", - "mappedProperty.key3", - "mappedIntProperty.key1", - "shortProperty", - "stringProperty", - "byteProperty", - "charProperty" + "booleanProperty", + "booleanSecond", + "doubleProperty", + "floatProperty", + "intProperty", + "longProperty", + "mappedProperty.key1", + "mappedProperty.key2", + "mappedProperty.key3", + "mappedIntProperty.key1", + "shortProperty", + "stringProperty", + "byteProperty", + "charProperty" }; - + Object[] values = { - Boolean.TRUE, - Boolean.TRUE, - new Double(Double.MAX_VALUE), - new Float(Float.MAX_VALUE), - new Integer(Integer.MAX_VALUE), - new Long(Long.MAX_VALUE), - "First Value", - "Second Value", - "Third Value", - new Integer(Integer.MAX_VALUE), - new Short(Short.MAX_VALUE), - "This is a string", - new Byte(Byte.MAX_VALUE), - new Character(Character.MAX_VALUE) + Boolean.TRUE, + Boolean.TRUE, + new Double(Double.MAX_VALUE), + new Float(Float.MAX_VALUE), + new Integer(Integer.MAX_VALUE), + new Long(Long.MAX_VALUE), + "First Value", + "Second Value", + "Third Value", + new Integer(Integer.MAX_VALUE), + new Short(Short.MAX_VALUE), + "This is a string", + new Byte(Byte.MAX_VALUE), + new Character(Character.MAX_VALUE) }; - int[] intArray = { 0, 10, 20, 30, 40 }; - boolean[] booleanArray = { true, false, true, false, true }; - char[] charArray = {'a', 'b', 'c', 'd', 'e' }; - byte[] byteArray = { 0, 10, 20, 30, 40 }; - long[] longArray = { 0, 10, 20, 30, 40 }; - short[] shortArray = { 0, 10, 20, 30, 40 }; - float[] floatArray = { 0, 10, 20, 30, 40 }; - double[] doubleArray = { 0.0, 10.0, 20.0, 30.0, 40.0 }; - String[] stringArray = { "String 0", "String 1", "String 2", "String 3", "String 4" }; + int[] intArray = {0, 10, 20, 30, 40}; + boolean[] booleanArray = {true, false, true, false, true}; + char[] charArray = {'a', 'b', 'c', 'd', 'e'}; + byte[] byteArray = {0, 10, 20, 30, 40}; + long[] longArray = {0, 10, 20, 30, 40}; + short[] shortArray = {0, 10, 20, 30, 40}; + float[] floatArray = {0, 10, 20, 30, 40}; + double[] doubleArray = {0.0, 10.0, 20.0, 30.0, 40.0}; + String[] stringArray = {"String 0", "String 1", "String 2", "String 3", "String 4"}; /** * Construct a new instance of this test case. * @param name Name of the test case */ - public TestConfigurationDynaBean(String name) { + public TestConfigurationDynaBean(String name) + { super(name); } /** * Set up instance variables required by this test case. */ - public void setUp() throws Exception { + public void setUp() throws Exception + { BaseConfiguration configuration = new BaseConfiguration(); - for(int i = 0; i < properties.length ; i++) + for (int i = 0; i < properties.length; i++) + { configuration.setProperty(properties[i], values[i]); + } - for(int a = 0; a < intArray.length ; a++) - configuration.addProperty("intIndexed",new Integer(intArray[a])); + for (int a = 0; a < intArray.length; a++) + { + configuration.addProperty("intIndexed", new Integer(intArray[a])); + } - for(int a = 0; a < stringArray.length ; a++) - configuration.addProperty("stringIndexed",stringArray[a]); + for (int a = 0; a < stringArray.length; a++) + { + configuration.addProperty("stringIndexed", stringArray[a]); + } List list = new ArrayList(); - for(int i = 0 ; i < stringArray.length ; i++) + for (int i = 0; i < stringArray.length; i++) + { list.add(stringArray[i]); + } configuration.addProperty("listIndexed", list); bean = new ConfigurationDynaBean(configuration); - bean.set("listIndexed",list); + bean.set("listIndexed", list); bean.set("intArray", intArray); bean.set("booleanArray", booleanArray); bean.set("charArray", charArray); @@ -135,32 +145,41 @@ /** * Tear down instance variables required by this test case. */ - public void tearDown() { + public void tearDown() + { bean = null; } /** * Corner cases on getDynaProperty invalid arguments. */ - public void testGetDescriptorArguments() { - - try { - DynaProperty descriptor = - bean.getDynaClass().getDynaProperty("unknown"); - assertNull("Unknown property descriptor should be null", - descriptor); - } catch (Throwable t) { + public void testGetDescriptorArguments() + { + try + { + DynaProperty descriptor = bean.getDynaClass().getDynaProperty("unknown"); + assertNull("Unknown property descriptor should be null", descriptor); + } + catch (Throwable t) + { fail("Threw " + t + " instead of returning null"); } - try { + try + { bean.getDynaClass().getDynaProperty(null); fail("Should throw IllegalArgumentException"); - } catch (java.lang.IllegalArgumentException e) { + } + catch (java.lang.IllegalArgumentException e) + { ; // Expected response - } catch(AssertionFailedError e) { + } + catch (AssertionFailedError e) + { ; // ignore other failed responses - } catch(Throwable t) { + } + catch (Throwable t) + { fail("Threw '" + t + "' instead of 'IllegalArgumentException'"); } } @@ -168,35 +187,40 @@ /** * Positive getDynaProperty on property <code>booleanProperty</code>. */ - public void testGetDescriptorBoolean() { + public void testGetDescriptorBoolean() + { testGetDescriptorBase("booleanProperty", Boolean.TYPE); } /** * Positive getDynaProperty on property <code>doubleProperty</code>. */ - public void testGetDescriptorDouble() { + public void testGetDescriptorDouble() + { testGetDescriptorBase("doubleProperty", Double.TYPE); } /** * Positive getDynaProperty on property <code>floatProperty</code>. */ - public void testGetDescriptorFloat() { + public void testGetDescriptorFloat() + { testGetDescriptorBase("floatProperty", Float.TYPE); } /** * Positive getDynaProperty on property <code>intProperty</code>. */ - public void testGetDescriptorInt() { + public void testGetDescriptorInt() + { testGetDescriptorBase("intProperty", Integer.TYPE); } /** * Positive getDynaProperty on property <code>longProperty</code>. */ - public void testGetDescriptorLong() { + public void testGetDescriptorLong() + { testGetDescriptorBase("longProperty", Long.TYPE); } @@ -204,21 +228,24 @@ * Positive getDynaProperty on property <code>booleanSecond</code> * that uses an "is" method as the getter. */ - public void testGetDescriptorSecond() { + public void testGetDescriptorSecond() + { testGetDescriptorBase("booleanSecond", Boolean.TYPE); } /** * Positive getDynaProperty on property <code>shortProperty</code>. */ - public void testGetDescriptorShort() { + public void testGetDescriptorShort() + { testGetDescriptorBase("shortProperty", Short.TYPE); } /** * Positive getDynaProperty on property <code>stringProperty</code>. */ - public void testGetDescriptorString() { + public void testGetDescriptorString() + { testGetDescriptorBase("stringProperty", String.class); } @@ -226,50 +253,73 @@ * Positive test for getDynaPropertys(). Each property name * listed in <code>properties</code> should be returned exactly once. */ - public void testGetDescriptors() { + public void testGetDescriptors() + { DynaProperty pd[] = bean.getDynaClass().getDynaProperties(); assertNotNull("Got descriptors", pd); int count[] = new int[properties.length]; - for (int i = 0; i < pd.length; i++) { + for (int i = 0; i < pd.length; i++) + { String name = pd[i].getName(); - for (int j = 0; j < properties.length; j++) { + for (int j = 0; j < properties.length; j++) + { if (name.equals(properties[j])) + { count[j]++; + } } } - for (int j = 0; j < properties.length; j++) { + + for (int j = 0; j < properties.length; j++) + { if (count[j] < 0) + { fail("Missing property " + properties[j]); + } else if (count[j] > 1) + { fail("Duplicate property " + properties[j]); + } } } /** * Corner cases on getIndexedProperty invalid arguments. */ - public void testGetIndexedArguments() { - try { + public void testGetIndexedArguments() + { + try + { bean.get("intArray", -1); - } catch (IndexOutOfBoundsException e) { + } + catch (IndexOutOfBoundsException e) + { return; // Expected response - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Threw '" + t + "' instead of 'IndexOutOfBoundsException'"); return; } + fail("Should throw IndexOutOfBoundsException"); } /** * Positive and negative tests on getIndexedProperty valid arguments. */ - public void testGetIndexedValues() { + public void testGetIndexedValues() + { Object value = null; - for (int i = 0; i < 5; i++) { - try { + for (int i = 0; i < 5; i++) + { + try + { value = bean.get("intArray", i); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("intArray " + i + " threw " + t); } @@ -277,68 +327,76 @@ assertTrue("intArray index " + i + " did not return Integer.", (value instanceof Integer)); assertEquals("intArray " + i + " returned incorrect value.", i * 10, ((Integer) value).intValue()); - try { + try + { value = bean.get("intIndexed", i); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("intIndexed index " + i + " threw " + t); } assertNotNull("intIndexed index " + i + "returned value " + i, value); - assertTrue("intIndexed index " + i + "returned Integer " + i, - value instanceof Integer); - assertEquals("intIndexed index " + i + "returned correct " + i, i * 10, - ((Integer) value).intValue()); + assertTrue("intIndexed index " + i + "returned Integer " + i, value instanceof Integer); + assertEquals("intIndexed index " + i + "returned correct " + i, i * 10, ((Integer) value).intValue()); - try { + try + { value = bean.get("listIndexed", i); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("listIndexed index " + i + " threw " + t); } assertNotNull("listIndexed index " + i + "returned value " + i, value); - assertTrue("list index " + i + "returned String " + i, - value instanceof String); - assertEquals("listIndexed index " + i + "returned correct " + i, - "String " + i, (String) value); + assertTrue("list index " + i + "returned String " + i, value instanceof String); + assertEquals("listIndexed index " + i + "returned correct " + i, "String " + i, (String) value); - try { + try + { value = bean.get("stringArray", i); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("stringArray index " + i + " threw " + t); } assertNotNull("stringArray index " + i + " returnde null.", value); - assertFalse("stringArray index " + i + " returned array instead of String.", - value.getClass().isArray()); + assertFalse("stringArray index " + i + " returned array instead of String.", value.getClass().isArray()); assertTrue("stringArray index " + i + " returned " - + value.getClass().getName() + "=["+value+"]" + + value.getClass().getName() + "=[" + value + "]" + " instead of String.", value instanceof String); - assertEquals("stringArray returned correct " + i, - "String " + i, (String) value); + assertEquals("stringArray returned correct " + i, "String " + i, (String) value); - try { + try + { value = bean.get("stringIndexed", i); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("stringIndexed " + i + " threw " + t); } assertNotNull("stringIndexed returned value " + i, value); - assertTrue("stringIndexed returned String " + i, - value instanceof String); - assertEquals("stringIndexed returned correct " + i, - "String " + i, (String) value); + assertTrue("stringIndexed returned String " + i, value instanceof String); + assertEquals("stringIndexed returned correct " + i, "String " + i, (String) value); } } /** * Corner cases on getMappedProperty invalid arguments. */ - public void testGetMappedArguments() { - try { + public void testGetMappedArguments() + { + try + { Object value = bean.get("mappedProperty", "unknown"); assertNull("Should not return a value", value); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Threw " + t + " instead of returning null"); } } @@ -346,27 +404,37 @@ /** * Positive and negative tests on getMappedProperty valid arguments. */ - public void testGetMappedValues() { + public void testGetMappedValues() + { Object value = null; - try { + try + { value = bean.get("mappedProperty", "key1"); assertEquals("Can find first value", "First Value", value); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Finding first value threw " + t); } - try { + try + { value = bean.get("mappedProperty", "key2"); assertEquals("Can find second value", "Second Value", value); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Finding second value threw " + t); } - try { + try + { value = bean.get("mappedProperty", "key3"); assertNotNull("Cannot find third value", value); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Finding third value threw " + t); } } @@ -374,12 +442,18 @@ /** * Corner cases on getSimpleProperty invalid arguments. */ - public void testGetSimpleArguments() { - try { + public void testGetSimpleArguments() + { + try + { bean.get(null); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) + { return; // Expected response - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Threw " + t + " instead of IllegalArgumentException"); } fail("Should throw IllegalArgumentException"); @@ -388,445 +462,471 @@ /** * Test getSimpleProperty on a boolean property. */ - public void testGetSimpleBoolean() { - - try { + public void testGetSimpleBoolean() + { + try + { Object value = bean.get("booleanProperty"); assertNotNull("Got a value", value); assertTrue("Got correct type", (value instanceof Boolean)); - assertTrue("Got correct value", - ((Boolean) value).booleanValue() == true); - } catch (Throwable e) { + assertTrue("Got correct value", ((Boolean) value).booleanValue() == true); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Test getSimpleProperty on a double property. */ - public void testGetSimpleDouble() { - - try { + public void testGetSimpleDouble() + { + try + { Object value = bean.get("doubleProperty"); assertNotNull("Got a value", value); assertTrue("Got correct type", (value instanceof Double)); - assertEquals("Got correct value", - ((Double) value).doubleValue(), - (double) Double.MAX_VALUE, - (double) 0.005); - } catch (Throwable t) { + assertEquals("Got correct value", ((Double) value).doubleValue(), Double.MAX_VALUE, 0.005); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a float property. */ - public void testGetSimpleFloat() { - - try { + public void testGetSimpleFloat() + { + try + { Object value = bean.get("floatProperty"); assertNotNull("Got a value", value); assertTrue("Got correct type", (value instanceof Float)); - assertEquals("Got correct value", - ((Float) value).floatValue(), - Float.MAX_VALUE, - (float) 0.005); - } catch (Throwable t) { + assertEquals("Got correct value", ((Float) value).floatValue(), Float.MAX_VALUE, 0.005f); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a int property. */ - public void testGetSimpleInt() { - - try { + public void testGetSimpleInt() + { + try + { Object value = bean.get("intProperty"); assertNotNull("Failed to get value", value); assertTrue("Incorrect type", (value instanceof Integer)); - assertEquals("Incorrect value", - ((Integer) value).intValue(), - Integer.MAX_VALUE); - } catch (Throwable t) { + assertEquals("Incorrect value", ((Integer) value).intValue(), Integer.MAX_VALUE); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a long property. */ - public void testGetSimpleLong() { - - try { + public void testGetSimpleLong() + { + try + { Object value = bean.get("longProperty"); assertNotNull("Got a value", value); assertTrue("Returned incorrect type", (value instanceof Long)); - assertEquals("Returned value of Incorrect value", - ((Long) value).longValue(), - Long.MAX_VALUE); - } catch (Throwable t) { + assertEquals("Returned value of Incorrect value", ((Long) value).longValue(), Long.MAX_VALUE); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a short property. */ - public void testGetSimpleShort() { - - try { + public void testGetSimpleShort() + { + try + { Object value = bean.get("shortProperty"); assertNotNull("Got a value", value); assertTrue("Got correct type", (value instanceof Short)); - assertEquals("Got correct value", - ((Short) value).shortValue(), - Short.MAX_VALUE); - } catch (Throwable t) { + assertEquals("Got correct value", ((Short) value).shortValue(), Short.MAX_VALUE); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a String property. */ - public void testGetSimpleString() { - - try { + public void testGetSimpleString() + { + try + { Object value = bean.get("stringProperty"); assertNotNull("Got a value", value); assertTrue("Got correct type", (value instanceof String)); - assertEquals("Got correct value", - (String) value, - "This is a string"); - } catch (Throwable t) { + assertEquals("Got correct value", (String) value, "This is a string"); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Test <code>contains()</code> method for mapped properties. */ - public void testMappedContains() { - try { + public void testMappedContains() + { + try + { assertTrue("Can't see first key", bean.contains("mappedProperty", "key1")); - } catch (Exception e) { + } + catch (Exception e) + { fail("Exception: " + e); } - try { - assertTrue("Can see unknown key", - !bean.contains("mappedProperty", "Unknown Key")); - } catch (Throwable t) { + try + { + assertTrue("Can see unknown key", !bean.contains("mappedProperty", "Unknown Key")); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Test <code>remove()</code> method for mapped properties. */ - public void testMappedRemove() { - - try { - assertTrue("Can see first key", - bean.contains("mappedProperty", "key1")); + public void testMappedRemove() + { + try + { + assertTrue("Can see first key", bean.contains("mappedProperty", "key1")); bean.remove("mappedProperty", "key1"); - assertTrue("Can not see first key", - !bean.contains("mappedProperty", "key1")); - } catch (Throwable t) { + assertTrue("Can not see first key", !bean.contains("mappedProperty", "key1")); + } + catch (Throwable t) + { fail("Exception: " + t); } - try { - assertTrue("Can not see unknown key", - !bean.contains("mappedProperty", "key4")); + try + { + assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4")); bean.remove("mappedProperty", "key4"); - assertTrue("Can not see unknown key", - !bean.contains("mappedProperty", "key4")); - } catch (Throwable t) { + assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4")); + } + catch (Throwable t) + { fail("Exception: " + t); } - } /** * Corner cases on setIndexedProperty invalid arguments. */ - public void testSetIndexedArguments() { - try { + public void testSetIndexedArguments() + { + try + { bean.set("intArray", -1, new Integer(0)); - } catch (IndexOutOfBoundsException e) { + } + catch (IndexOutOfBoundsException e) + { return; // Expected response - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Threw " + t + " instead of IndexOutOfBoundsException"); } + fail("Should throw IndexOutOfBoundsException"); } /** * Positive and negative tests on setIndexedProperty valid arguments. */ - public void testSetIndexedValues() { + public void testSetIndexedValues() + { Object value = null; - try { + try + { bean.set("intArray", 0, new Integer(1)); - value = (Integer) bean.get("intArray", 0); - } catch (Throwable t) { + value = bean.get("intArray", 0); + } + catch (Throwable t) + { fail("Threw " + t); } assertNotNull("Returned new value 0", value); - assertTrue("Returned Integer new value 0", - value instanceof Integer); - assertEquals("Returned correct new value 0", 1, - ((Integer) value).intValue()); + assertTrue("Returned Integer new value 0", value instanceof Integer); + assertEquals("Returned correct new value 0", 1, ((Integer) value).intValue()); - try { + try + { bean.set("intIndexed", 1, new Integer(11)); - value = (Integer) bean.get("intIndexed", 1); - } catch (Throwable t) { + value = bean.get("intIndexed", 1); + } + catch (Throwable t) + { fail("Threw " + t); } assertNotNull("Returned new value 1", value); - assertTrue("Returned Integer new value 1", - value instanceof Integer); - assertEquals("Returned correct new value 1", 11, - ((Integer) value).intValue()); + assertTrue("Returned Integer new value 1", value instanceof Integer); + assertEquals("Returned correct new value 1", 11, ((Integer) value).intValue()); - try { + try + { bean.set("listIndexed", 2, "New Value 2"); - value = (String) bean.get("listIndexed", 2); - } catch (Throwable t) { + value = bean.get("listIndexed", 2); + } + catch (Throwable t) + { fail("Threw " + t); } assertNotNull("Returned new value 2", value); - assertTrue("Returned String new value 2", - value instanceof String); - assertEquals("Returned correct new value 2", "New Value 2", - (String) value); + assertTrue("Returned String new value 2", value instanceof String); + assertEquals("Returned correct new value 2", "New Value 2", (String) value); - try { + try + { bean.set("stringArray", 3, "New Value 3"); - value = (String) bean.get("stringArray", 3); - } catch (Throwable t) { + value = bean.get("stringArray", 3); + } + catch (Throwable t) + { fail("Threw " + t); } assertNotNull("Returned new value 3", value); - assertTrue("Returned String new value 3", - value instanceof String); - assertEquals("Returned correct new value 3", "New Value 3", - (String) value); + assertTrue("Returned String new value 3", value instanceof String); + assertEquals("Returned correct new value 3", "New Value 3", (String) value); - try { + try + { bean.set("stringIndexed", 4, "New Value 4"); - value = (String) bean.get("stringIndexed", 4); - } catch (Throwable t) { + value = bean.get("stringIndexed", 4); + } + catch (Throwable t) + { fail("Threw " + t); } + assertNotNull("Returned new value 4", value); - assertTrue("Returned String new value 4", - value instanceof String); - assertEquals("Returned correct new value 4", "New Value 4", - (String) value); + assertTrue("Returned String new value 4", value instanceof String); + assertEquals("Returned correct new value 4", "New Value 4", (String) value); } /** * Positive and negative tests on setMappedProperty valid arguments. */ - public void testSetMappedValues() { - - try { + public void testSetMappedValues() + { + try + { bean.set("mappedProperty", "First Key", "New First Value"); - assertEquals("Can replace old value", - "New First Value", - (String) bean.get("mappedProperty", "First Key")); - } catch (Throwable t) { + assertEquals("Can replace old value", "New First Value", (String) bean.get("mappedProperty", "First Key")); + } + catch (Throwable t) + { fail("Finding fourth value threw " + t); } - try { + try + { bean.set("mappedProperty", "Fourth Key", "Fourth Value"); - assertEquals("Can set new value", - "Fourth Value", - (String) bean.get("mappedProperty", "Fourth Key")); - } catch (Throwable t) { + assertEquals("Can set new value", "Fourth Value", (String) bean.get("mappedProperty", "Fourth Key")); + } + catch (Throwable t) + { fail("Finding fourth value threw " + t); } - } /** * Test setSimpleProperty on a boolean property. */ - public void testSetSimpleBoolean() { - - try { - boolean oldValue = - ((Boolean) bean.get("booleanProperty")).booleanValue(); + public void testSetSimpleBoolean() + { + try + { + boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue(); boolean newValue = !oldValue; bean.set("booleanProperty", new Boolean(newValue)); - assertTrue("Matched new value", - newValue == - ((Boolean) bean.get("booleanProperty")).booleanValue()); - } catch (Throwable e) { + assertTrue("Matched new value", newValue == ((Boolean) bean.get("booleanProperty")).booleanValue()); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a double property. */ - public void testSetSimpleDouble() { - - try { - double oldValue = - ((Double) bean.get("doubleProperty")).doubleValue(); + public void testSetSimpleDouble() + { + try + { + double oldValue = ((Double) bean.get("doubleProperty")).doubleValue(); double newValue = oldValue + 1.0; bean.set("doubleProperty", new Double(newValue)); - assertEquals("Matched new value", - newValue, - ((Double) bean.get("doubleProperty")).doubleValue(), - (double) 0.005); - } catch (Throwable e) { + assertEquals("Matched new value", newValue, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a float property. */ - public void testSetSimpleFloat() { - - try { - float oldValue = - ((Float) bean.get("floatProperty")).floatValue(); + public void testSetSimpleFloat() + { + try + { + float oldValue = ((Float) bean.get("floatProperty")).floatValue(); float newValue = oldValue + (float) 1.0; bean.set("floatProperty", new Float(newValue)); - assertEquals("Matched new value", - newValue, - ((Float) bean.get("floatProperty")).floatValue(), - (float) 0.005); - } catch (Throwable e) { + assertEquals("Matched new value", newValue, ((Float) bean.get("floatProperty")).floatValue(), 0.005f); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a int property. */ - public void testSetSimpleInt() { - - try { - int oldValue = - ((Integer) bean.get("intProperty")).intValue(); + public void testSetSimpleInt() + { + try + { + int oldValue = ((Integer) bean.get("intProperty")).intValue(); int newValue = oldValue + 1; bean.set("intProperty", new Integer(newValue)); - assertEquals("Matched new value", - newValue, - ((Integer) bean.get("intProperty")).intValue()); - } catch (Throwable e) { + assertEquals("Matched new value", newValue, ((Integer) bean.get("intProperty")).intValue()); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a long property. */ - public void testSetSimpleLong() { - - try { - long oldValue = - ((Long) bean.get("longProperty")).longValue(); + public void testSetSimpleLong() + { + try + { + long oldValue = ((Long) bean.get("longProperty")).longValue(); long newValue = oldValue + 1; bean.set("longProperty", new Long(newValue)); - assertEquals("Matched new value", - newValue, - ((Long) bean.get("longProperty")).longValue()); - } catch (Throwable e) { + assertEquals("Matched new value", newValue, ((Long) bean.get("longProperty")).longValue()); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a short property. */ - public void testSetSimpleShort() { - - try { - short oldValue = - ((Short) bean.get("shortProperty")).shortValue(); + public void testSetSimpleShort() + { + try + { + short oldValue = ((Short) bean.get("shortProperty")).shortValue(); short newValue = (short) (oldValue + 1); bean.set("shortProperty", new Short(newValue)); - assertEquals("Matched new value", - newValue, - ((Short) bean.get("shortProperty")).shortValue()); - } catch (Throwable e) { + assertEquals("Matched new value", newValue, ((Short) bean.get("shortProperty")).shortValue()); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a String property. */ - public void testSetSimpleString() { - - try { + public void testSetSimpleString() + { + try + { String oldValue = (String) bean.get("stringProperty"); String newValue = oldValue + " Extra Value"; bean.set("stringProperty", newValue); - assertEquals("Matched new value", - newValue, - (String) bean.get("stringProperty")); - } catch (Throwable e) { + assertEquals("Matched new value", newValue, (String) bean.get("stringProperty")); + } + catch (Throwable e) + { fail("Exception: " + e); } - } /** * Tests set on a null value: should throw NPE. */ - public void testAddNullPropertyValue() { - try { + public void testAddNullPropertyValue() + { + try + { bean.set("nullProperty", null); - } catch(NullPointerException e) { + } + catch (NullPointerException e) + { return; - } catch(Throwable t) { + } + catch (Throwable t) + { fail("Threw " + t + " instead of NullPointerException"); return; } fail("Should have thrown NullPointerException"); } + /** * Test the retrieval of a non-existent property. */ - public void testGetNonExistentProperty() { - try { - Object value = bean.get("nonexistProperty"); - } catch (IllegalArgumentException e) { - return; - } catch(Exception e) { + public void testGetNonExistentProperty() + { + try + { + bean.get("nonexistProperty"); + } + catch (IllegalArgumentException e) + { + return; + } + catch (Exception e) + { fail("Threw '" + e + "' instead of java.lang.IllegalArgumentException"); } + fail("Get non-existent property failed to throw java.lang.IllegalArgumentException"); } @@ -836,35 +936,47 @@ * @param name Name of the property to be retrieved * @param type Expected class type of this property */ - protected void testGetDescriptorBase(String name, Class type) { + protected void testGetDescriptorBase(String name, Class type) + { DynaProperty descriptor = null; - try { + try + { descriptor = bean.getDynaClass().getDynaProperty(name); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Threw an exception: " + t); } + assertNotNull("Failed to get descriptor", descriptor); assertEquals("Got incorrect type", type, descriptor.getType()); } - + /** * Tests if accessing a non-indexed property using the index * get method throws an IllegalArgumentException as it * should. */ - public void testNonIndexedPropeties() { + public void testNonIndexedPropeties() + { ConfigurationDynaBean nested = (ConfigurationDynaBean) bean.get("mappedProperty"); - try { + try + { String value = (String) nested.get("key1"); assertEquals("Can find first value", "First Value", value); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Finding first value threw " + t); } - try { + try + { nested.set("key1", "undefined"); assertEquals("Incorrect value returned", "undefined", bean.get("mappedProperty.key1")); - } catch (Throwable t) { + } + catch (Throwable t) + { fail("Finding setting first value threw " + t); } } @@ -874,27 +986,40 @@ * get method throws an IllegalArgumentException as it * should. */ - public void testNestedPropeties() { - try { + public void testNestedPropeties() + { + try + { bean.get("booleanProperty", 0); - } catch(IllegalArgumentException e) { + } + catch (IllegalArgumentException e) + { return; - } catch(Throwable t) { + } + catch (Throwable t) + { fail("Threw " + t + " instead of IllegalArgumentException"); return; } + fail("Should have thrown IllegalArgumentException"); - try { + try + { bean.set("booleanProperty", 0, new Boolean(true)); - } catch(IllegalArgumentException e) { + } + catch (IllegalArgumentException e) + { return; - } catch(Throwable t) { + } + catch (Throwable t) + { fail("Threw " + t + " instead of IllegalArgumentException"); return; } + fail("Should have thrown IllegalArgumentException"); } - + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]