This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch 1.X in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/1.X by this push: new 6e015f75 Port some tests to JUnit 5 6e015f75 is described below commit 6e015f75a5a0161a97afd1e0824446f6487f9512 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Fri Jun 6 19:05:36 2025 -0400 Port some tests to JUnit 5 --- .../commons/beanutils/BasicDynaBeanTestCase.java | 489 +++++++-------------- .../commons/beanutils/BeanComparatorTestCase.java | 149 +++---- .../commons/beanutils/WrapDynaBeanTestCase.java | 166 +++---- 3 files changed, 270 insertions(+), 534 deletions(-) diff --git a/src/test/java/org/apache/commons/beanutils/BasicDynaBeanTestCase.java b/src/test/java/org/apache/commons/beanutils/BasicDynaBeanTestCase.java index 61f53db7..1be26edf 100644 --- a/src/test/java/org/apache/commons/beanutils/BasicDynaBeanTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/BasicDynaBeanTestCase.java @@ -17,6 +17,12 @@ package org.apache.commons.beanutils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; @@ -26,110 +32,54 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** - * <p>Test Case for the <code>BasicDynaBean</code> implementation class. - * These tests were based on the ones in <code>PropertyUtilsTestCase</code> - * because the two classes provide similar levels of functionality.</p> + * <p> + * Test Case for the <code>BasicDynaBean</code> implementation class. These tests were based on the ones in <code>PropertyUtilsTestCase</code> because the two + * classes provide similar levels of functionality. + * </p> * */ - -public class BasicDynaBeanTestCase extends TestCase { +public class BasicDynaBeanTestCase { /** - * The set of property names we expect to have returned when calling - * <code>getDynaProperties()</code>. You should update this list - * when new properties are added to TestBean. + * The set of property names we expect to have returned when calling <code>getDynaProperties()</code>. You should update this list when new properties are + * added to TestBean. */ - protected final static String[] properties = { - "booleanProperty", - "booleanSecond", - "doubleProperty", - "floatProperty", - "intArray", - "intIndexed", - "intProperty", - "listIndexed", - "longProperty", - "mappedProperty", - "mappedIntProperty", - "nullProperty", - "shortProperty", - "stringArray", - "stringIndexed", - "stringProperty", - }; - - /** - * Return the tests included in this test suite. - */ - public static Test suite() { - - return new TestSuite(BasicDynaBeanTestCase.class); - - } - + protected final static String[] properties = { "booleanProperty", "booleanSecond", "doubleProperty", "floatProperty", "intArray", "intIndexed", + "intProperty", "listIndexed", "longProperty", "mappedProperty", "mappedIntProperty", "nullProperty", "shortProperty", "stringArray", + "stringIndexed", "stringProperty", }; /** * The basic test bean for each test. */ protected DynaBean bean; /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public BasicDynaBeanTestCase(final String name) { - - super(name); - - } - - /** - * Create and return a <code>DynaClass</code> instance for our test - * <code>DynaBean</code>. + * Create and return a <code>DynaClass</code> instance for our test <code>DynaBean</code>. */ protected DynaClass createDynaClass() { - final int intArray[] = {}; final String stringArray[] = {}; - - return new BasicDynaClass - ("TestDynaClass", null, - new DynaProperty[]{ - new DynaProperty("booleanProperty", Boolean.TYPE), - new DynaProperty("booleanSecond", Boolean.TYPE), - new DynaProperty("doubleProperty", Double.TYPE), - new DynaProperty("floatProperty", Float.TYPE), - new DynaProperty("intArray", intArray.getClass()), - new DynaProperty("intIndexed", intArray.getClass()), - new DynaProperty("intProperty", Integer.TYPE), - new DynaProperty("listIndexed", List.class), - new DynaProperty("longProperty", Long.TYPE), - new DynaProperty("mappedProperty", Map.class), - new DynaProperty("mappedIntProperty", Map.class), - new DynaProperty("nullProperty", String.class), - new DynaProperty("shortProperty", Short.TYPE), - new DynaProperty("stringArray", stringArray.getClass()), - new DynaProperty("stringIndexed", stringArray.getClass()), - new DynaProperty("stringProperty", String.class), - }); - + return new BasicDynaClass("TestDynaClass", null, new DynaProperty[] { new DynaProperty("booleanProperty", Boolean.TYPE), + new DynaProperty("booleanSecond", Boolean.TYPE), new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE), + new DynaProperty("intArray", intArray.getClass()), new DynaProperty("intIndexed", intArray.getClass()), + new DynaProperty("intProperty", Integer.TYPE), new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE), + new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class), new DynaProperty("nullProperty", String.class), + new DynaProperty("shortProperty", Short.TYPE), new DynaProperty("stringArray", stringArray.getClass()), + new DynaProperty("stringIndexed", stringArray.getClass()), new DynaProperty("stringProperty", String.class), }); } /** * Set up instance variables required by this test case. */ - @Override + @BeforeEach public void setUp() throws Exception { - // Instantiate a new DynaBean instance final DynaClass dynaClass = createDynaClass(); bean = dynaClass.newInstance(); - // Initialize the DynaBean's property values (like TestBean) bean.set("booleanProperty", Boolean.valueOf(true)); bean.set("booleanSecond", Boolean.valueOf(true)); @@ -158,40 +108,32 @@ public class BasicDynaBeanTestCase extends TestCase { bean.set("mappedIntProperty", mappedIntProperty); // Property "nullProperty" is not initialized, so it should return null bean.set("shortProperty", Short.valueOf((short) 987)); - final String stringArray[] = - { "String 0", "String 1", "String 2", "String 3", "String 4" }; + final String stringArray[] = { "String 0", "String 1", "String 2", "String 3", "String 4" }; bean.set("stringArray", stringArray); - final String stringIndexed[] = - { "String 0", "String 1", "String 2", "String 3", "String 4" }; + final String stringIndexed[] = { "String 0", "String 1", "String 2", "String 3", "String 4" }; bean.set("stringIndexed", stringIndexed); bean.set("stringProperty", "This is a string"); - } /** * Tear down instance variables required by this test case. */ - @Override + @AfterEach public void tearDown() { - bean = null; - } /** * Corner cases on getDynaProperty invalid arguments. */ + @Test public void testGetDescriptorArguments() { - try { - final DynaProperty descriptor = - bean.getDynaClass().getDynaProperty("unknown"); - assertNull("Unknown property descriptor should be null", - descriptor); + final DynaProperty descriptor = bean.getDynaClass().getDynaProperty("unknown"); + assertNull(descriptor, "Unknown property descriptor should be null"); } catch (final Throwable t) { fail("Threw " + t + " instead of returning null"); } - try { bean.getDynaClass().getDynaProperty(null); fail("Should throw IllegalArgumentException"); @@ -200,7 +142,6 @@ public class BasicDynaBeanTestCase extends TestCase { } catch (final Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException"); } - } /** @@ -210,71 +151,62 @@ public class BasicDynaBeanTestCase extends TestCase { * @param type Expected class type of this property */ protected void testGetDescriptorBase(final String name, final Class<?> type) { - try { - final DynaProperty descriptor = - bean.getDynaClass().getDynaProperty(name); - assertNotNull("Got descriptor", descriptor); - assertEquals("Got correct type", type, descriptor.getType()); + final DynaProperty descriptor = bean.getDynaClass().getDynaProperty(name); + assertNotNull(descriptor, "Got descriptor"); + assertEquals(type, descriptor.getType(), "Got correct type"); } catch (final Throwable t) { fail("Threw an exception: " + t); } - } /** * Positive getDynaProperty on property <code>booleanProperty</code>. */ + @Test public void testGetDescriptorBoolean() { - testGetDescriptorBase("booleanProperty", Boolean.TYPE); - } /** * Positive getDynaProperty on property <code>doubleProperty</code>. */ + @Test public void testGetDescriptorDouble() { - testGetDescriptorBase("doubleProperty", Double.TYPE); - } /** * Positive getDynaProperty on property <code>floatProperty</code>. */ + @Test public void testGetDescriptorFloat() { - testGetDescriptorBase("floatProperty", Float.TYPE); - } /** * Positive getDynaProperty on property <code>intProperty</code>. */ + @Test public void testGetDescriptorInt() { - testGetDescriptorBase("intProperty", Integer.TYPE); - } /** * Positive getDynaProperty on property <code>longProperty</code>. */ + @Test public void testGetDescriptorLong() { - testGetDescriptorBase("longProperty", Long.TYPE); - } /** - * Positive test for getDynaPropertys(). Each property name - * listed in <code>properties</code> should be returned exactly once. + * Positive test for getDynaPropertys(). Each property name listed in <code>properties</code> should be returned exactly once. */ + @Test public void testGetDescriptors() { - final DynaProperty pd[] = bean.getDynaClass().getDynaProperties(); - assertNotNull("Got descriptors", pd); + assertNotNull(pd, "Got descriptors"); final int count[] = new int[properties.length]; for (final DynaProperty element : pd) { final String name = element.getName(); @@ -291,42 +223,37 @@ public class BasicDynaBeanTestCase extends TestCase { fail("Duplicate property " + properties[j]); } } - } /** - * Positive getDynaProperty on property <code>booleanSecond</code> - * that uses an "is" method as the getter. + * Positive getDynaProperty on property <code>booleanSecond</code> that uses an "is" method as the getter. */ + @Test public void testGetDescriptorSecond() { - testGetDescriptorBase("booleanSecond", Boolean.TYPE); - } /** * Positive getDynaProperty on property <code>shortProperty</code>. */ + @Test public void testGetDescriptorShort() { - testGetDescriptorBase("shortProperty", Short.TYPE); - } /** * Positive getDynaProperty on property <code>stringProperty</code>. */ + @Test public void testGetDescriptorString() { - testGetDescriptorBase("stringProperty", String.class); - } /** * Corner cases on getIndexedProperty invalid arguments. */ + @Test public void testGetIndexedArguments() { - try { bean.get("intArray", -1); fail("Should throw IndexOutOfBoundsException"); @@ -335,126 +262,102 @@ public class BasicDynaBeanTestCase extends TestCase { } catch (final Throwable t) { fail("Threw " + t + " instead of IndexOutOfBoundsException"); } - } /** * Positive and negative tests on getIndexedProperty valid arguments. */ + @Test public void testGetIndexedValues() { - Object value = null; - for (int i = 0; i < 5; i++) { - try { value = bean.get("intArray", i); - assertNotNull("intArray returned value " + i, value); - assertTrue("intArray returned Integer " + i, - value instanceof Integer); - assertEquals("intArray returned correct " + i, i * 10, - ((Integer) value).intValue()); + assertNotNull(value, "intArray returned value " + i); + assertTrue(value instanceof Integer, "intArray returned Integer " + i); + assertEquals(i * 10, ((Integer) value).intValue(), "intArray returned correct " + i); } catch (final Throwable t) { fail("intArray " + i + " threw " + t); } - try { value = bean.get("intIndexed", i); - assertNotNull("intIndexed returned value " + i, value); - assertTrue("intIndexed returned Integer " + i, - value instanceof Integer); - assertEquals("intIndexed returned correct " + i, i * 10, - ((Integer) value).intValue()); + assertNotNull(value, "intIndexed returned value " + i); + assertTrue(value instanceof Integer, "intIndexed returned Integer " + i); + assertEquals(i * 10, ((Integer) value).intValue(), "intIndexed returned correct " + i); } catch (final Throwable t) { fail("intIndexed " + i + " threw " + t); } - try { value = bean.get("listIndexed", i); - assertNotNull("listIndexed returned value " + i, value); - assertTrue("list returned String " + i, - value instanceof String); - assertEquals("listIndexed returned correct " + i, - "String " + i, (String) value); + assertNotNull(value, "listIndexed returned value " + i); + assertTrue(value instanceof String, "list returned String " + i); + assertEquals("String " + i, (String) value, "listIndexed returned correct " + i); } catch (final Throwable t) { fail("listIndexed " + i + " threw " + t); } - try { value = bean.get("stringArray", i); - assertNotNull("stringArray returned value " + i, value); - assertTrue("stringArray returned String " + i, - value instanceof String); - assertEquals("stringArray returned correct " + i, - "String " + i, (String) value); + assertNotNull(value, "stringArray returned value " + i); + assertTrue(value instanceof String, "stringArray returned String " + i); + assertEquals("String " + i, (String) value, "stringArray returned correct " + i); } catch (final Throwable t) { fail("stringArray " + i + " threw " + t); } - try { value = bean.get("stringIndexed", i); - assertNotNull("stringIndexed returned value " + i, value); - assertTrue("stringIndexed returned String " + i, - value instanceof String); - assertEquals("stringIndexed returned correct " + i, - "String " + i, (String) value); + assertNotNull(value, "stringIndexed returned value " + i); + assertTrue(value instanceof String, "stringIndexed returned String " + i); + assertEquals("String " + i, (String) value, "stringIndexed returned correct " + i); } catch (final Throwable t) { fail("stringIndexed " + i + " threw " + t); } - } - } /** * Corner cases on getMappedProperty invalid arguments. */ + @Test public void testGetMappedArguments() { - try { final Object value = bean.get("mappedProperty", "unknown"); - assertNull("Should not return a value", value); + assertNull(value, "Should not return a value"); } catch (final Throwable t) { fail("Threw " + t + " instead of returning null"); } - } /** * Positive and negative tests on getMappedProperty valid arguments. */ + @Test public void testGetMappedValues() { - Object value = null; - try { value = bean.get("mappedProperty", "First Key"); - assertEquals("Can find first value", "First Value", value); + assertEquals("First Value", value, "Can find first value"); } catch (final Throwable t) { fail("Finding first value threw " + t); } - try { value = bean.get("mappedProperty", "Second Key"); - assertEquals("Can find second value", "Second Value", value); + assertEquals("Second Value", value, "Can find second value"); } catch (final Throwable t) { fail("Finding second value threw " + t); } - try { value = bean.get("mappedProperty", "Third Key"); - assertNull("Can not find third value", value); + assertNull(value, "Can not find third value"); } catch (final Throwable t) { fail("Finding third value threw " + t); } - } /** * Corner cases on getSimpleProperty invalid arguments. */ + @Test public void testGetSimpleArguments() { - try { bean.get(null); fail("Should throw IllegalArgumentException"); @@ -463,188 +366,156 @@ public class BasicDynaBeanTestCase extends TestCase { } catch (final Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException"); } - } /** * Test getSimpleProperty on a boolean property. */ + @Test public void testGetSimpleBoolean() { - try { final Object value = bean.get("booleanProperty"); - assertNotNull("Got a value", value); - assertTrue("Got correct type", value instanceof Boolean); - assertTrue("Got correct value", - ((Boolean) value).booleanValue()); + assertNotNull(value, "Got a value"); + assertTrue(value instanceof Boolean, "Got correct type"); + assertTrue(((Boolean) value).booleanValue(), "Got correct value"); } catch (final Throwable e) { fail("Exception: " + e); } - } /** * Test getSimpleProperty on a double property. */ + @Test public void testGetSimpleDouble() { - try { final Object value = bean.get("doubleProperty"); - assertNotNull("Got a value", value); - assertTrue("Got correct type", value instanceof Double); - assertEquals("Got correct value", - ((Double) value).doubleValue(), - 321.0, 0.005); + assertNotNull(value, "Got a value"); + assertTrue(value instanceof Double, "Got correct type"); + assertEquals(((Double) value).doubleValue(), 321.0, 0.005, "Got correct value"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a float property. */ + @Test public void testGetSimpleFloat() { - try { final 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) 123.0, - (float) 0.005); + assertNotNull(value, "Got a value"); + assertTrue(value instanceof Float, "Got correct type"); + assertEquals(((Float) value).floatValue(), (float) 123.0, (float) 0.005, "Got correct value"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a int property. */ + @Test public void testGetSimpleInt() { - try { final Object value = bean.get("intProperty"); - assertNotNull("Got a value", value); - assertTrue("Got correct type", value instanceof Integer); - assertEquals("Got correct value", - ((Integer) value).intValue(), - 123); + assertNotNull(value, "Got a value"); + assertTrue(value instanceof Integer, "Got correct type"); + assertEquals(((Integer) value).intValue(), 123, "Got correct value"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a long property. */ + @Test public void testGetSimpleLong() { - try { final Object value = bean.get("longProperty"); - assertNotNull("Got a value", value); - assertTrue("Got correct type", value instanceof Long); - assertEquals("Got correct value", - ((Long) value).longValue(), - 321); + assertNotNull(value, "Got a value"); + assertTrue(value instanceof Long, "Got correct type"); + assertEquals(((Long) value).longValue(), 321, "Got correct value"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a short property. */ + @Test public void testGetSimpleShort() { - try { final 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) 987); + assertNotNull(value, "Got a value"); + assertTrue(value instanceof Short, "Got correct type"); + assertEquals(((Short) value).shortValue(), (short) 987, "Got correct value"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test getSimpleProperty on a String property. */ + @Test public void testGetSimpleString() { - try { final 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"); + assertNotNull(value, "Got a value"); + assertTrue(value instanceof String, "Got correct type"); + assertEquals((String) value, "This is a string", "Got correct value"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test <code>contains()</code> method for mapped properties. */ + @Test public void testMappedContains() { - try { - assertTrue("Can see first key", - bean.contains("mappedProperty", "First Key")); + assertTrue(bean.contains("mappedProperty", "First Key"), "Can see first key"); } catch (final Throwable t) { fail("Exception: " + t); } - try { - assertTrue("Can not see unknown key", - !bean.contains("mappedProperty", "Unknown Key")); + assertTrue(!bean.contains("mappedProperty", "Unknown Key"), "Can not see unknown key"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test <code>remove()</code> method for mapped properties. */ + @Test public void testMappedRemove() { - try { - assertTrue("Can see first key", - bean.contains("mappedProperty", "First Key")); + assertTrue(bean.contains("mappedProperty", "First Key"), "Can see first key"); bean.remove("mappedProperty", "First Key"); - assertTrue("Can not see first key", - !bean.contains("mappedProperty", "First Key")); + assertTrue(!bean.contains("mappedProperty", "First Key"), "Can not see first key"); } catch (final Throwable t) { fail("Exception: " + t); } - try { - assertTrue("Can not see unknown key", - !bean.contains("mappedProperty", "Unknown Key")); + assertTrue(!bean.contains("mappedProperty", "Unknown Key"), "Can not see unknown key"); bean.remove("mappedProperty", "Unknown Key"); - assertTrue("Can not see unknown key", - !bean.contains("mappedProperty", "Unknown Key")); + assertTrue(!bean.contains("mappedProperty", "Unknown Key"), "Can not see unknown key"); } catch (final Throwable t) { fail("Exception: " + t); } - } /** * Test serialization and deserialization. */ + @Test public void testSerialization() { - // Serialize the test bean final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { @@ -655,19 +526,16 @@ public class BasicDynaBeanTestCase extends TestCase { } catch (final Exception e) { fail("Exception during serialization: " + e); } - // Deserialize the test bean try { bean = null; - final ByteArrayInputStream bais = - new ByteArrayInputStream(baos.toByteArray()); + final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ObjectInputStream ois = new ObjectInputStream(bais); bean = (DynaBean) ois.readObject(); bais.close(); } catch (final Exception e) { fail("Exception during deserialization: " + e); } - // Confirm property values testGetDescriptorArguments(); testGetDescriptorBoolean(); @@ -693,7 +561,6 @@ public class BasicDynaBeanTestCase extends TestCase { testGetSimpleString(); testMappedContains(); testMappedRemove(); - // Ensure that we can create a new instance of the same DynaClass try { bean = bean.getDynaClass().newInstance(); @@ -710,14 +577,13 @@ public class BasicDynaBeanTestCase extends TestCase { testGetDescriptorShort(); testGetDescriptorString(); testGetDescriptors(); - } /** * Corner cases on setIndexedProperty invalid arguments. */ + @Test public void testSetIndexedArguments() { - try { bean.set("intArray", -1, Integer.valueOf(0)); fail("Should throw IndexOutOfBoundsException"); @@ -726,235 +592,182 @@ public class BasicDynaBeanTestCase extends TestCase { } catch (final Throwable t) { fail("Threw " + t + " instead of IndexOutOfBoundsException"); } - } /** * Positive and negative tests on setIndexedProperty valid arguments. */ + @Test public void testSetIndexedValues() { - Object value = null; - try { bean.set("intArray", 0, Integer.valueOf(1)); value = bean.get("intArray", 0); - 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()); + assertNotNull(value, "Returned new value 0"); + assertTrue(value instanceof Integer, "Returned Integer new value 0"); + assertEquals(1, ((Integer) value).intValue(), "Returned correct new value 0"); } catch (final Throwable t) { fail("Threw " + t); } - try { bean.set("intIndexed", 1, Integer.valueOf(11)); value = bean.get("intIndexed", 1); - 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()); + assertNotNull(value, "Returned new value 1"); + assertTrue(value instanceof Integer, "Returned Integer new value 1"); + assertEquals(11, ((Integer) value).intValue(), "Returned correct new value 1"); } catch (final Throwable t) { fail("Threw " + t); } - try { bean.set("listIndexed", 2, "New Value 2"); value = bean.get("listIndexed", 2); - 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); + assertNotNull(value, "Returned new value 2"); + assertTrue(value instanceof String, "Returned String new value 2"); + assertEquals("New Value 2", (String) value, "Returned correct new value 2"); } catch (final Throwable t) { fail("Threw " + t); } - try { bean.set("stringArray", 3, "New Value 3"); value = bean.get("stringArray", 3); - 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); + assertNotNull(value, "Returned new value 3"); + assertTrue(value instanceof String, "Returned String new value 3"); + assertEquals("New Value 3", (String) value, "Returned correct new value 3"); } catch (final Throwable t) { fail("Threw " + t); } - try { bean.set("stringIndexed", 4, "New Value 4"); value = bean.get("stringIndexed", 4); - 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); + assertNotNull(value, "Returned new value 4"); + assertTrue(value instanceof String, "Returned String new value 4"); + assertEquals("New Value 4", (String) value, "Returned correct new value 4"); } catch (final Throwable t) { fail("Threw " + t); } - } /** * Positive and negative tests on setMappedProperty valid arguments. */ + @Test 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")); + assertEquals("New First Value", (String) bean.get("mappedProperty", "First Key"), "Can replace old value"); } catch (final Throwable t) { fail("Finding fourth value threw " + t); } - try { bean.set("mappedProperty", "Fourth Key", "Fourth Value"); - assertEquals("Can set new value", - "Fourth Value", - (String) bean.get("mappedProperty", "Fourth Key")); + assertEquals("Fourth Value", (String) bean.get("mappedProperty", "Fourth Key"), "Can set new value"); } catch (final Throwable t) { fail("Finding fourth value threw " + t); } - } /** * Test setSimpleProperty on a boolean property. */ + @Test public void testSetSimpleBoolean() { - try { - final boolean oldValue = - ((Boolean) bean.get("booleanProperty")).booleanValue(); + final boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue(); final boolean newValue = !oldValue; bean.set("booleanProperty", Boolean.valueOf(newValue)); - assertTrue("Matched new value", - newValue == - ((Boolean) bean.get("booleanProperty")).booleanValue()); + assertTrue(newValue == ((Boolean) bean.get("booleanProperty")).booleanValue(), "Matched new value"); } catch (final Throwable e) { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a double property. */ + @Test public void testSetSimpleDouble() { - try { - final double oldValue = - ((Double) bean.get("doubleProperty")).doubleValue(); + final double oldValue = ((Double) bean.get("doubleProperty")).doubleValue(); final double newValue = oldValue + 1.0; bean.set("doubleProperty", Double.valueOf(newValue)); - assertEquals("Matched new value", - newValue, - ((Double) bean.get("doubleProperty")).doubleValue(), - 0.005); + assertEquals(newValue, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005, "Matched new value"); } catch (final Throwable e) { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a float property. */ + @Test public void testSetSimpleFloat() { - try { - final float oldValue = - ((Float) bean.get("floatProperty")).floatValue(); + final float oldValue = ((Float) bean.get("floatProperty")).floatValue(); final float newValue = oldValue + (float) 1.0; bean.set("floatProperty", Float.valueOf(newValue)); - assertEquals("Matched new value", - newValue, - ((Float) bean.get("floatProperty")).floatValue(), - (float) 0.005); + assertEquals(newValue, ((Float) bean.get("floatProperty")).floatValue(), (float) 0.005, "Matched new value"); } catch (final Throwable e) { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a int property. */ + @Test public void testSetSimpleInt() { - try { - final int oldValue = - ((Integer) bean.get("intProperty")).intValue(); + final int oldValue = ((Integer) bean.get("intProperty")).intValue(); final int newValue = oldValue + 1; bean.set("intProperty", Integer.valueOf(newValue)); - assertEquals("Matched new value", - newValue, - ((Integer) bean.get("intProperty")).intValue()); + assertEquals(newValue, ((Integer) bean.get("intProperty")).intValue(), "Matched new value"); } catch (final Throwable e) { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a long property. */ + @Test public void testSetSimpleLong() { - try { - final long oldValue = - ((Long) bean.get("longProperty")).longValue(); + final long oldValue = ((Long) bean.get("longProperty")).longValue(); final long newValue = oldValue + 1; bean.set("longProperty", Long.valueOf(newValue)); - assertEquals("Matched new value", - newValue, - ((Long) bean.get("longProperty")).longValue()); + assertEquals(newValue, ((Long) bean.get("longProperty")).longValue(), "Matched new value"); } catch (final Throwable e) { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a short property. */ + @Test public void testSetSimpleShort() { - try { - final short oldValue = - ((Short) bean.get("shortProperty")).shortValue(); + final short oldValue = ((Short) bean.get("shortProperty")).shortValue(); final short newValue = (short) (oldValue + 1); bean.set("shortProperty", Short.valueOf(newValue)); - assertEquals("Matched new value", - newValue, - ((Short) bean.get("shortProperty")).shortValue()); + assertEquals(newValue, ((Short) bean.get("shortProperty")).shortValue(), "Matched new value"); } catch (final Throwable e) { fail("Exception: " + e); } - } /** * Test setSimpleProperty on a String property. */ + @Test public void testSetSimpleString() { - try { final String oldValue = (String) bean.get("stringProperty"); final String newValue = oldValue + " Extra Value"; bean.set("stringProperty", newValue); - assertEquals("Matched new value", - newValue, - (String) bean.get("stringProperty")); + assertEquals(newValue, (String) bean.get("stringProperty"), "Matched new value"); } catch (final Throwable e) { fail("Exception: " + e); } - } - } diff --git a/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java b/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java index b9f785e9..36737cfc 100644 --- a/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/BeanComparatorTestCase.java @@ -17,56 +17,41 @@ package org.apache.commons.beanutils; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * <p> - * Test Case for the BeanComparator class. + * Test Case for the BeanComparator class. * */ - -public class BeanComparatorTestCase extends TestCase { +public class BeanComparatorTestCase { - /** - * Return the tests included in this test suite. - */ - public static Test suite() { - return new TestSuite(BeanComparatorTestCase.class); - } /** * The test beans for each test. */ protected TestBean bean; protected AlphaBean alphaBean1; - protected AlphaBean alphaBean2; - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public BeanComparatorTestCase(final String name) { - super(name); - } - /** * Set up instance variables required by this test case. */ - @Override + @BeforeEach public void setUp() { bean = new TestBean(); alphaBean1 = new AlphaBean("alphaBean1"); alphaBean2 = new AlphaBean("alphaBean2"); - } /** * Tear down instance variables required by this test case. */ - @Override + @AfterEach public void tearDown() { bean = null; alphaBean1 = null; @@ -74,131 +59,111 @@ public class BeanComparatorTestCase extends TestCase { } /** - * tests comparing one bean against itself. + * tests comparing one bean against itself. */ + @Test public void testCompareBeanAgainstSelf() { - final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>( - "name"); + final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("name"); final int result = beanComparator.compare(alphaBean1, alphaBean1); - assertTrue("Comparator did not sort properly. Result:" + result, - result == 0); + assertTrue(result == 0, "Comparator did not sort properly. Result:" + result); } /** - * tests comparing two beans via their name using the default Comparator where they have the same value. + * tests comparing two beans via their name using the default Comparator where they have the same value. */ + @Test public void testCompareIdentical() { alphaBean1 = new AlphaBean("alphabean"); alphaBean2 = new AlphaBean("alphabean"); - final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>( - "name"); + final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("name"); final int result = beanComparator.compare(alphaBean1, alphaBean2); - assertTrue("Comparator did not sort properly. Result:" + result, - result == 0); + assertTrue(result == 0, "Comparator did not sort properly. Result:" + result); } /** - * tests comparing two beans on a boolean property, which is not possible. + * tests comparing two beans on a boolean property, which is not possible. */ + @Test public void testCompareOnBooleanProperty() { try { - final TestBean testBeanA = new TestBean(); - final TestBean testBeanB = new TestBean(); - - testBeanA.setBooleanProperty(true); - testBeanB.setBooleanProperty(false); - - final BeanComparator<TestBean> beanComparator = new BeanComparator<>("booleanProperty"); - beanComparator.compare(testBeanA, testBeanB); - - // **** java.lang.Boolean implements Comparable from JDK 1.5 onwards - // so this test no longer fails - // fail("BeanComparator should throw an exception when comparing two booleans."); - - } - catch (final ClassCastException cce){ - // Expected result + final TestBean testBeanA = new TestBean(); + final TestBean testBeanB = new TestBean(); + testBeanA.setBooleanProperty(true); + testBeanB.setBooleanProperty(false); + final BeanComparator<TestBean> beanComparator = new BeanComparator<>("booleanProperty"); + beanComparator.compare(testBeanA, testBeanB); + // **** java.lang.Boolean implements Comparable from JDK 1.5 onwards + // so this test no longer fails + // fail("BeanComparator should throw an exception when comparing two booleans."); + } catch (final ClassCastException cce) { + // Expected result } } /** - * tests comparing two beans who don't have a property + * tests comparing two beans who don't have a property */ + @Test public void testCompareOnMissingProperty() { try { - final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("bogusName"); - beanComparator.compare(alphaBean2, alphaBean1); - fail("should not be able to compare"); - - } - catch (final Exception e) { - assertTrue("Wrong exception was thrown: " + e, e.toString().indexOf("Unknown property") > -1); + final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("bogusName"); + beanComparator.compare(alphaBean2, alphaBean1); + fail("should not be able to compare"); + } catch (final Exception e) { + assertTrue(e.toString().indexOf("Unknown property") > -1, "Wrong exception was thrown: " + e); } } /** - * tests comparing two beans via their name using the default Comparator, but with one of the beans - * being null. + * tests comparing two beans via their name using the default Comparator, but with one of the beans being null. */ + @Test public void testCompareWithNulls() { try { - final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("name"); - beanComparator.compare(alphaBean2, null); - - fail("Should not be able to compare a null value."); - } - catch (final Exception e) { + final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("name"); + beanComparator.compare(alphaBean2, null); + fail("Should not be able to compare a null value."); + } catch (final Exception e) { // expected result } } /** - * tests comparing two beans on a boolean property, then changing the property and testing + * tests comparing two beans on a boolean property, then changing the property and testing */ + @Test public void testSetProperty() { final TestBean testBeanA = new TestBean(); final TestBean testBeanB = new TestBean(); - testBeanA.setDoubleProperty(5.5); testBeanB.setDoubleProperty(1.0); - - final BeanComparator<TestBean> beanComparator = new BeanComparator<>( - "doubleProperty"); + final BeanComparator<TestBean> beanComparator = new BeanComparator<>("doubleProperty"); int result = beanComparator.compare(testBeanA, testBeanB); - - assertTrue("Comparator did not sort properly. Result:" + result, - result == 1); - + assertTrue(result == 1, "Comparator did not sort properly. Result:" + result); testBeanA.setStringProperty("string 1"); testBeanB.setStringProperty("string 2"); - beanComparator.setProperty("stringProperty"); - result = beanComparator.compare(testBeanA, testBeanB); - - assertTrue("Comparator did not sort properly. Result:" + result, - result == -1); + assertTrue(result == -1, "Comparator did not sort properly. Result:" + result); } /** - * tests comparing two beans via their name using the default Comparator + * tests comparing two beans via their name using the default Comparator */ + @Test public void testSimpleCompare() { - final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>( - "name"); + final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("name"); final int result = beanComparator.compare(alphaBean1, alphaBean2); - assertTrue("Comparator did not sort properly. Result:" + result, - result == -1); + assertTrue(result == -1, "Comparator did not sort properly. Result:" + result); } /** - * tests comparing two beans via their name using the default Comparator, but the inverse + * tests comparing two beans via their name using the default Comparator, but the inverse */ + @Test public void testSimpleCompareInverse() { - final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>( - "name"); + final BeanComparator<AlphaBean> beanComparator = new BeanComparator<>("name"); final int result = beanComparator.compare(alphaBean2, alphaBean1); - assertTrue("Comparator did not sort properly. Result:" + result, - result == 1); + assertTrue(result == 1, "Comparator did not sort properly. Result:" + result); } } diff --git a/src/test/java/org/apache/commons/beanutils/WrapDynaBeanTestCase.java b/src/test/java/org/apache/commons/beanutils/WrapDynaBeanTestCase.java index b44b78c7..45160652 100644 --- a/src/test/java/org/apache/commons/beanutils/WrapDynaBeanTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/WrapDynaBeanTestCase.java @@ -17,46 +17,31 @@ package org.apache.commons.beanutils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** - * <p>Test Case for the <code>WrapDynaBean</code> implementation class. - * These tests were based on the ones in <code>PropertyUtilsTestCase</code> - * because the two classes provide similar levels of functionality.</p> - * + * <p> + * Test Case for the <code>WrapDynaBean</code> implementation class. These tests were based on the ones in <code>PropertyUtilsTestCase</code> because the two + * classes provide similar levels of functionality. + * </p> */ - public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { /** - * Return the tests included in this test suite. - */ - public static Test suite() { - - return new TestSuite(WrapDynaBeanTestCase.class); - - } - - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public WrapDynaBeanTestCase(final String name) { - - super(name); - - } - - /** - * Helper method for testing whether basic access to properties works as - * expected. + * Helper method for testing whether basic access to properties works as expected. */ private void checkSimplePropertyAccess() { // Invalid getter @@ -66,7 +51,6 @@ public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { } catch (final IllegalArgumentException t) { // Expected result } - // Invalid setter try { bean.set("invalidProperty", "XYZ"); @@ -74,20 +58,18 @@ public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { } catch (final IllegalArgumentException t) { // Expected result } - // Set up initial Value String testValue = "Original Value"; final String testProperty = "stringProperty"; - final TestBean instance = (TestBean)((WrapDynaBean)bean).getInstance(); + final TestBean instance = (TestBean) ((WrapDynaBean) bean).getInstance(); instance.setStringProperty(testValue); - assertEquals("Check String property", testValue, instance.getStringProperty()); - + assertEquals(testValue, instance.getStringProperty(), "Check String property"); // Test Valid Get & Set try { testValue = "Some new value"; bean.set(testProperty, testValue); - assertEquals("Test Set", testValue, instance.getStringProperty()); - assertEquals("Test Get", testValue, bean.get(testProperty)); + assertEquals(testValue, instance.getStringProperty(), "Test Set"); + assertEquals(testValue, bean.get(testProperty), "Test Get"); } catch (final IllegalArgumentException t) { fail("Get threw exception: " + t); } @@ -97,7 +79,6 @@ public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { * Do serialization and deserialization. */ private Object serializeDeserialize(final Object target, final String text) { - // Serialize the test object final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { @@ -108,12 +89,10 @@ public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { } catch (final Exception e) { fail(text + ": Exception during serialization: " + e); } - // Deserialize the test object Object result = null; try { - final ByteArrayInputStream bais = - new ByteArrayInputStream(baos.toByteArray()); + final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ObjectInputStream ois = new ObjectInputStream(bais); result = ois.readObject(); bais.close(); @@ -121,64 +100,60 @@ public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { fail(text + ": Exception during deserialization: " + e); } return result; - } /** * Set up instance variables required by this test case. */ - @Override + @BeforeEach public void setUp() throws Exception { - bean = new WrapDynaBean(new TestBean()); - } /** * Tear down instance variables required by this test case. */ - @Override + @AfterEach public void tearDown() { - bean = null; - } /** Tests getInstance method */ + @Test public void testGetInstance() { final AlphaBean alphaBean = new AlphaBean("Now On Air... John Peel"); final WrapDynaBean dynaBean = new WrapDynaBean(alphaBean); final Object wrappedInstance = dynaBean.getInstance(); - assertTrue("Object type is AlphaBean", wrappedInstance instanceof AlphaBean); + assertTrue(wrappedInstance instanceof AlphaBean, "Object type is AlphaBean"); final AlphaBean wrappedAlphaBean = (AlphaBean) wrappedInstance; - assertTrue("Same Object", wrappedAlphaBean == alphaBean); + assertTrue(wrappedAlphaBean == alphaBean, "Same Object"); } /** * Tests whether caching works for WrapDynaClass objects. */ + @Test public void testGetWrapDynaClassFromCache() { final WrapDynaClass clazz = WrapDynaClass.createDynaClass(TestBean.class); - assertSame("Instance not cached", clazz, - WrapDynaClass.createDynaClass(TestBean.class)); + assertSame(clazz, WrapDynaClass.createDynaClass(TestBean.class), "Instance not cached"); } /** - * Tests whether the PropertyUtilsBean instance associated with a WrapDynaClass is - * taken into account when accessing an instance from the cache. + * Tests whether the PropertyUtilsBean instance associated with a WrapDynaClass is taken into account when accessing an instance from the cache. */ + @Test public void testGetWrapDynaClassFromCacheWithPropUtils() { final WrapDynaClass clazz = WrapDynaClass.createDynaClass(TestBean.class); final PropertyUtilsBean pu = new PropertyUtilsBean(); final WrapDynaClass clazz2 = WrapDynaClass.createDynaClass(TestBean.class, pu); - assertNotSame("Got same instance from cache", clazz, clazz2); + assertNotSame(clazz, clazz2, "Got same instance from cache"); } /** * The <code>set()</code> method. */ + @Test public void testIndexedProperties() { - // Invalid getter try { bean.get("invalidProperty", 0); @@ -186,7 +161,6 @@ public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { } catch (final IllegalArgumentException t) { // Expected result } - // Invalid setter try { bean.set("invalidProperty", 0, "XYZ"); @@ -194,150 +168,134 @@ public class WrapDynaBeanTestCase extends BasicDynaBeanTestCase { } catch (final IllegalArgumentException t) { // Expected result } - // Set up initial Value String testValue = "Original Value"; final String testProperty = "stringIndexed"; - final TestBean instance = (TestBean)((WrapDynaBean)bean).getInstance(); + final TestBean instance = (TestBean) ((WrapDynaBean) bean).getInstance(); instance.setStringIndexed(0, testValue); - assertEquals("Check String property", testValue, instance.getStringIndexed(0)); - + assertEquals(testValue, instance.getStringIndexed(0), "Check String property"); // Test Valid Get & Set try { testValue = "Some new value"; bean.set(testProperty, 0, testValue); - assertEquals("Test Set", testValue, instance.getStringIndexed(0)); - assertEquals("Test Get", testValue, bean.get(testProperty, 0)); + assertEquals(testValue, instance.getStringIndexed(0), "Test Set"); + assertEquals(testValue, bean.get(testProperty, 0), "Test Get"); } catch (final IllegalArgumentException t) { fail("Get threw exception: " + t); } - } /** * Tests whether a WrapDynaClass can be provided when constructing a bean. */ + @Test public void testInitWithDynaClass() { final WrapDynaClass clazz = WrapDynaClass.createDynaClass(TestBean.class); bean = new WrapDynaBean(new TestBean(), clazz); - assertSame("Wrong DynaClass", clazz, bean.getDynaClass()); + assertSame(clazz, bean.getDynaClass(), "Wrong DynaClass"); checkSimplePropertyAccess(); } /** - * Tests whether a custom PropertyUtilsBean instance can be used for introspection of - * bean properties. + * Tests whether a custom PropertyUtilsBean instance can be used for introspection of bean properties. */ + @Test public void testIntrospectionWithCustomPropUtils() { final PropertyUtilsBean pu = new PropertyUtilsBean(); pu.addBeanIntrospector(new FluentPropertyBeanIntrospector()); - final WrapDynaClass dynaClass = WrapDynaClass.createDynaClass( - FluentIntrospectionTestBean.class, pu); + final WrapDynaClass dynaClass = WrapDynaClass.createDynaClass(FluentIntrospectionTestBean.class, pu); final FluentIntrospectionTestBean obj = new FluentIntrospectionTestBean(); bean = new WrapDynaBean(obj, dynaClass); bean.set("fluentProperty", "testvalue"); - assertEquals("Property not set", "testvalue", obj.getStringProperty()); + assertEquals("testvalue", obj.getStringProperty(), "Property not set"); } /** - * The <code>contains()</code> method is not supported by the - * <code>WrapDynaBean</code> implementation class. + * The <code>contains()</code> method is not supported by the <code>WrapDynaBean</code> implementation class. */ + @Test @Override public void testMappedContains() { - try { - assertTrue("Can see first key", - bean.contains("mappedProperty", "First Key")); + assertTrue(bean.contains("mappedProperty", "First Key"), "Can see first key"); fail("Should have thrown UnsupportedOperationException"); } catch (final UnsupportedOperationException t) { // Expected result } catch (final Throwable t) { fail("Exception: " + t); } - try { - assertTrue("Can not see unknown key", - !bean.contains("mappedProperty", "Unknown Key")); + assertTrue(!bean.contains("mappedProperty", "Unknown Key"), "Can not see unknown key"); fail("Should have thrown UnsupportedOperationException"); } catch (final UnsupportedOperationException t) { // Expected result } catch (final Throwable t) { fail("Exception: " + t); } - } /** - * The <code>remove()</code> method is not supported by the - * <code>WrapDynaBean</code> implementation class. + * The <code>remove()</code> method is not supported by the <code>WrapDynaBean</code> implementation class. */ + @Test @Override public void testMappedRemove() { - try { - assertTrue("Can see first key", - bean.contains("mappedProperty", "First Key")); + assertTrue(bean.contains("mappedProperty", "First Key"), "Can see first key"); bean.remove("mappedProperty", "First Key"); fail("Should have thrown UnsupportedOperationException"); - // assertTrue("Can not see first key", - // !bean.contains("mappedProperty", "First Key")); + // assertTrue("Can not see first key", + // !bean.contains("mappedProperty", "First Key")); } catch (final UnsupportedOperationException t) { // Expected result } catch (final Throwable t) { fail("Exception: " + t); } - try { - assertTrue("Can not see unknown key", - !bean.contains("mappedProperty", "Unknown Key")); + assertTrue(!bean.contains("mappedProperty", "Unknown Key"), "Can not see unknown key"); bean.remove("mappedProperty", "Unknown Key"); fail("Should have thrown UnsupportedOperationException"); - // assertTrue("Can not see unknown key", - // !bean.contains("mappedProperty", "Unknown Key")); + // assertTrue("Can not see unknown key", + // !bean.contains("mappedProperty", "Unknown Key")); } catch (final UnsupportedOperationException t) { // Expected result } catch (final Throwable t) { fail("Exception: " + t); } - } /** Tests the newInstance implementation for WrapDynaClass */ + @Test public void testNewInstance() throws Exception { final WrapDynaClass dynaClass = WrapDynaClass.createDynaClass(AlphaBean.class); final Object createdInstance = dynaClass.newInstance(); - assertTrue("Object type is WrapDynaBean", createdInstance instanceof WrapDynaBean); + assertTrue(createdInstance instanceof WrapDynaBean, "Object type is WrapDynaBean"); final WrapDynaBean dynaBean = (WrapDynaBean) createdInstance; - assertTrue("Object type is AlphaBean", dynaBean.getInstance() instanceof AlphaBean); + assertTrue(dynaBean.getInstance() instanceof AlphaBean, "Object type is AlphaBean"); } /** - * Serialization and deserialization tests. - * (WrapDynaBean is now serializable, although WrapDynaClass still is not) + * Serialization and deserialization tests. (WrapDynaBean is now serializable, although WrapDynaClass still is not) */ @Override + @Test public void testSerialization() { - // Create a bean and set a value final WrapDynaBean origBean = new WrapDynaBean(new TestBean()); final Integer newValue = Integer.valueOf(789); - assertEquals("origBean default", Integer.valueOf(123), origBean.get("intProperty")); + assertEquals(Integer.valueOf(123), origBean.get("intProperty"), "origBean default"); origBean.set("intProperty", newValue); - assertEquals("origBean new value", newValue, origBean.get("intProperty")); - + assertEquals(newValue, origBean.get("intProperty"), "origBean new value"); // Serialize/Deserialize & test value - final WrapDynaBean bean = (WrapDynaBean)serializeDeserialize(origBean, "First Test"); - assertEquals("bean value", newValue, bean.get("intProperty")); - + final WrapDynaBean bean = (WrapDynaBean) serializeDeserialize(origBean, "First Test"); + assertEquals(newValue, bean.get("intProperty"), "bean value"); } /** * The <code>set()</code> method. */ + @Test public void testSimpleProperties() { - checkSimplePropertyAccess(); - } }