You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/09/02 00:30:01 UTC
(commons-beanutils) branch master updated: Don't hide stack traces from JUnit!
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push:
new c1a145c8 Don't hide stack traces from JUnit!
c1a145c8 is described below
commit c1a145c8c7ec16043ab057693ef94576f8ef402e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Sep 1 20:29:56 2024 -0400
Don't hide stack traces from JUnit!
- Use assertThrows
---
.../commons/beanutils2/BeanComparatorTestCase.java | 2 -
.../commons/beanutils2/BeanUtilsBeanTestCase.java | 428 +++----
.../commons/beanutils2/DynaBeanUtilsTestCase.java | 403 +++----
.../beanutils2/DynaPropertyUtilsTestCase.java | 822 +++----------
.../commons/beanutils2/PropertyUtilsTestCase.java | 1210 ++++++--------------
5 files changed, 817 insertions(+), 2048 deletions(-)
diff --git a/src/test/java/org/apache/commons/beanutils2/BeanComparatorTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanComparatorTestCase.java
index 6169ef56..99ca159c 100644
--- a/src/test/java/org/apache/commons/beanutils2/BeanComparatorTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/BeanComparatorTestCase.java
@@ -113,7 +113,6 @@ public class BeanComparatorTestCase {
final BeanComparator<AlphaBean, String> beanComparator = new BeanComparator<>("bogusName");
beanComparator.compare(alphaBean2, alphaBean1);
fail("should not be able to compare");
-
} catch (final Exception e) {
assertTrue(e.toString().contains("Unknown property"), () -> "Wrong exception was thrown: " + e);
}
@@ -127,7 +126,6 @@ public class BeanComparatorTestCase {
try {
final BeanComparator<AlphaBean, String> beanComparator = new BeanComparator<>("name");
beanComparator.compare(alphaBean2, null);
-
fail("Should not be able to compare a null value.");
} catch (final Exception e) {
// expected result
diff --git a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java
index af40f674..1ffc7fea 100644
--- a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-import java.lang.reflect.InvocationTargetException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
@@ -177,8 +176,7 @@ public class BeanUtilsBeanTestCase {
final String[] results = beanUtils.getArrayProperty(bean, "intArray");
final int[] values = bean.getIntArray();
- assertEquals(results.length, values.length,
- "Converted array size not equal to property array size.");
+ assertEquals(results.length, values.length, "Converted array size not equal to property array size.");
for (int i = 0, size = values.length; i < size; i++) {
assertEquals(values[i] + "", results[i], "Value " + i + " incorrectly converted ");
}
@@ -424,8 +422,7 @@ public class BeanUtilsBeanTestCase {
fail("Threw " + t);
}
assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length");
- assertEquals(testUtilDate.toString(), bean.getStringArray()[0],
- "java.util.Date[] --> String[] value ");
+ assertEquals(testUtilDate.toString(), bean.getStringArray()[0], "java.util.Date[] --> String[] value ");
}
/**
@@ -698,38 +695,28 @@ public class BeanUtilsBeanTestCase {
* tests the string and int arrays of TestBean
*/
@Test
- public void testGetArrayProperty() {
- try {
- String[] arr = BeanUtils.getArrayProperty(bean, "stringArray");
- final String[] comp = bean.getStringArray();
-
- assertEquals(comp.length, arr.length, "String array length = " + comp.length);
-
- arr = BeanUtils.getArrayProperty(bean, "intArray");
- final int[] iarr = bean.getIntArray();
-
- assertEquals(iarr.length, arr.length, "String array length = " + iarr.length);
-
- // Test property which isn't array or collection
- arr = BeanUtils.getArrayProperty(bean, "shortProperty");
- final String shortAsString = "" + bean.getShortProperty();
- assertEquals(1, arr.length, "Short List Test lth");
- assertEquals(shortAsString, arr[0], "Short Test value");
-
- // Test comma delimited list
- bean.setStringProperty("ABC");
- arr = BeanUtils.getArrayProperty(bean, "stringProperty");
- assertEquals(1, arr.length, "Delimited List Test lth");
- assertEquals("ABC", arr[0], "Delimited List Test value1");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetArrayProperty() throws Exception {
+ String[] arr = BeanUtils.getArrayProperty(bean, "stringArray");
+ final String[] comp = bean.getStringArray();
+
+ assertEquals(comp.length, arr.length, "String array length = " + comp.length);
+
+ arr = BeanUtils.getArrayProperty(bean, "intArray");
+ final int[] iarr = bean.getIntArray();
+ assertEquals(iarr.length, arr.length, "String array length = " + iarr.length);
+
+ // Test property which isn't array or collection
+ arr = BeanUtils.getArrayProperty(bean, "shortProperty");
+ final String shortAsString = "" + bean.getShortProperty();
+ assertEquals(1, arr.length, "Short List Test lth");
+ assertEquals(shortAsString, arr[0], "Short Test value");
+
+ // Test comma delimited list
+ bean.setStringProperty("ABC");
+ arr = BeanUtils.getArrayProperty(bean, "stringProperty");
+ assertEquals(1, arr.length, "Delimited List Test lth");
+ assertEquals("ABC", arr[0], "Delimited List Test value1");
}
/**
@@ -752,66 +739,41 @@ public class BeanUtilsBeanTestCase {
* tests getting a 'whatever' property
*/
@Test
- public void testGetGeneralProperty() {
- try {
- final String val = BeanUtils.getProperty(bean, "nested.intIndexed[2]");
- final String comp = String.valueOf(bean.getIntIndexed(2));
-
- assertEquals(val, comp, "nested.intIndexed[2] == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetGeneralProperty() throws Exception {
+ final String val = BeanUtils.getProperty(bean, "nested.intIndexed[2]");
+ final String comp = String.valueOf(bean.getIntIndexed(2));
+
+ assertEquals(val, comp, "nested.intIndexed[2] == " + comp);
}
/**
* tests getting an indexed property
*/
@Test
- public void testGetIndexedProperty1() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed[3]");
- String comp = String.valueOf(bean.getIntIndexed(3));
- assertEquals(val, comp, "intIndexed[3] == " + comp);
-
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed[3]");
- comp = bean.getStringIndexed(3);
- assertEquals(val, comp, "stringIndexed[3] == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetIndexedProperty1() throws Exception {
+ String val = BeanUtils.getIndexedProperty(bean, "intIndexed[3]");
+ String comp = String.valueOf(bean.getIntIndexed(3));
+ assertEquals(val, comp, "intIndexed[3] == " + comp);
+
+ val = BeanUtils.getIndexedProperty(bean, "stringIndexed[3]");
+ comp = bean.getStringIndexed(3);
+ assertEquals(val, comp, "stringIndexed[3] == " + comp);
}
/**
* tests getting an indexed property
*/
@Test
- public void testGetIndexedProperty2() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed", 3);
- String comp = String.valueOf(bean.getIntIndexed(3));
+ public void testGetIndexedProperty2() throws Exception {
+ String val = BeanUtils.getIndexedProperty(bean, "intIndexed", 3);
+ String comp = String.valueOf(bean.getIntIndexed(3));
- assertEquals(val, comp, "intIndexed,3 == " + comp);
+ assertEquals(val, comp, "intIndexed,3 == " + comp);
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed", 3);
- comp = bean.getStringIndexed(3);
+ val = BeanUtils.getIndexedProperty(bean, "stringIndexed", 3);
+ comp = bean.getStringIndexed(3);
- assertEquals(val, comp, "stringIndexed,3 == " + comp);
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ assertEquals(val, comp, "stringIndexed,3 == " + comp);
}
/**
@@ -847,37 +809,21 @@ public class BeanUtilsBeanTestCase {
* tests getting a nested property
*/
@Test
- public void testGetNestedProperty() {
- try {
- final String val = BeanUtils.getNestedProperty(bean, "nested.stringProperty");
- final String comp = bean.getNested().getStringProperty();
- assertEquals(val, comp, "nested.StringProperty == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetNestedProperty() throws Exception {
+ final String val = BeanUtils.getNestedProperty(bean, "nested.stringProperty");
+ final String comp = bean.getNested().getStringProperty();
+ assertEquals(val, comp, "nested.StringProperty == " + comp);
}
/**
* tests getting a 'whatever' property
*/
@Test
- public void testGetSimpleProperty() {
- try {
- final String val = BeanUtils.getSimpleProperty(bean, "shortProperty");
- final String comp = String.valueOf(bean.getShortProperty());
-
- assertEquals(val, comp, "shortProperty == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetSimpleProperty() throws Exception {
+ final String val = BeanUtils.getSimpleProperty(bean, "shortProperty");
+ final String comp = String.valueOf(bean.getShortProperty());
+
+ assertEquals(val, comp, "shortProperty == " + comp);
}
/**
@@ -901,8 +847,7 @@ public class BeanUtilsBeanTestCase {
BeanUtils.setProperty(bean, "mapproperty(this.that.the-other)", "some.dotty.value");
- assertEquals("some.dotty.value", bean.getMapproperty("this.that.the-other"),
- "Mapped property set correctly");
+ assertEquals("some.dotty.value", bean.getMapproperty("this.that.the-other"), "Mapped property set correctly");
}
@Test
@@ -916,198 +861,140 @@ public class BeanUtilsBeanTestCase {
* Test populate() method on individual array elements.
*/
@Test
- public void testPopulateArrayElements() {
-
- try {
+ public void testPopulateArrayElements() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("intIndexed[0]", "100");
+ map.put("intIndexed[2]", "120");
+ map.put("intIndexed[4]", "140");
- final HashMap<String, Object> map = new HashMap<>();
- map.put("intIndexed[0]", "100");
- map.put("intIndexed[2]", "120");
- map.put("intIndexed[4]", "140");
+ BeanUtils.populate(bean, map);
- BeanUtils.populate(bean, map);
+ assertEquals(100, bean.getIntIndexed(0), "intIndexed[0] is 100");
+ assertEquals(10, bean.getIntIndexed(1), "intIndexed[1] is 10");
+ assertEquals(120, bean.getIntIndexed(2), "intIndexed[2] is 120");
+ assertEquals(30, bean.getIntIndexed(3), "intIndexed[3] is 30");
+ assertEquals(140, bean.getIntIndexed(4), "intIndexed[4] is 140");
- assertEquals(100, bean.getIntIndexed(0), "intIndexed[0] is 100");
- assertEquals(10, bean.getIntIndexed(1), "intIndexed[1] is 10");
- assertEquals(120, bean.getIntIndexed(2), "intIndexed[2] is 120");
- assertEquals(30, bean.getIntIndexed(3), "intIndexed[3] is 30");
- assertEquals(140, bean.getIntIndexed(4), "intIndexed[4] is 140");
+ map.clear();
+ map.put("stringIndexed[1]", "New String 1");
+ map.put("stringIndexed[3]", "New String 3");
- map.clear();
- map.put("stringIndexed[1]", "New String 1");
- map.put("stringIndexed[3]", "New String 3");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("String 0", bean.getStringIndexed(0), "stringIndexed[0] is \"String 0\"");
- assertEquals("New String 1", bean.getStringIndexed(1), "stringIndexed[1] is \"New String 1\"");
- assertEquals("String 2", bean.getStringIndexed(2), "stringIndexed[2] is \"String 2\"");
- assertEquals("New String 3", bean.getStringIndexed(3), "stringIndexed[3] is \"New String 3\"");
- assertEquals("String 4", bean.getStringIndexed(4), "stringIndexed[4] is \"String 4\"");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
+ BeanUtils.populate(bean, map);
+ assertEquals("String 0", bean.getStringIndexed(0), "stringIndexed[0] is \"String 0\"");
+ assertEquals("New String 1", bean.getStringIndexed(1), "stringIndexed[1] is \"New String 1\"");
+ assertEquals("String 2", bean.getStringIndexed(2), "stringIndexed[2] is \"String 2\"");
+ assertEquals("New String 3", bean.getStringIndexed(3), "stringIndexed[3] is \"New String 3\"");
+ assertEquals("String 4", bean.getStringIndexed(4), "stringIndexed[4] is \"String 4\"");
}
/**
* Test populate() method on array properties as a whole.
*/
@Test
- public void testPopulateArrayProperties() {
-
- try {
+ public void testPopulateArrayProperties() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ int[] intArray = { 123, 456, 789 };
+ map.put("intArray", intArray);
+ String[] stringArray = { "New String 0", "New String 1" };
+ map.put("stringArray", stringArray);
- final HashMap<String, Object> map = new HashMap<>();
- int[] intArray = { 123, 456, 789 };
- map.put("intArray", intArray);
- String[] stringArray = { "New String 0", "New String 1" };
- map.put("stringArray", stringArray);
-
- BeanUtils.populate(bean, map);
-
- intArray = bean.getIntArray();
- assertNotNull(intArray, "intArray is present");
- assertEquals(3, intArray.length, "intArray length");
- assertEquals(123, intArray[0], "intArray[0]");
- assertEquals(456, intArray[1], "intArray[1]");
- assertEquals(789, intArray[2], "intArray[2]");
- stringArray = bean.getStringArray();
- assertNotNull(stringArray, "stringArray is present");
- assertEquals(2, stringArray.length, "stringArray length");
- assertEquals("New String 0", stringArray[0], "stringArray[0]");
- assertEquals("New String 1", stringArray[1], "stringArray[1]");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
+ BeanUtils.populate(bean, map);
+ intArray = bean.getIntArray();
+ assertNotNull(intArray, "intArray is present");
+ assertEquals(3, intArray.length, "intArray length");
+ assertEquals(123, intArray[0], "intArray[0]");
+ assertEquals(456, intArray[1], "intArray[1]");
+ assertEquals(789, intArray[2], "intArray[2]");
+ stringArray = bean.getStringArray();
+ assertNotNull(stringArray, "stringArray is present");
+ assertEquals(2, stringArray.length, "stringArray length");
+ assertEquals("New String 0", stringArray[0], "stringArray[0]");
+ assertEquals("New String 1", stringArray[1], "stringArray[1]");
}
/**
* Test populate() on mapped properties.
*/
@Test
- public void testPopulateMapped() {
+ public void testPopulateMapped() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("mappedProperty(First Key)", "New First Value");
+ map.put("mappedProperty(Third Key)", "New Third Value");
- try {
-
- final HashMap<String, Object> map = new HashMap<>();
- map.put("mappedProperty(First Key)", "New First Value");
- map.put("mappedProperty(Third Key)", "New Third Value");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("New First Value", bean.getMappedProperty("First Key"),
- "mappedProperty(First Key)");
- assertEquals("Second Value", bean.getMappedProperty("Second Key"), "mappedProperty(Second Key)");
- assertEquals("New Third Value", bean.getMappedProperty("Third Key"),
- "mappedProperty(Third Key)");
- assertNull(bean.getMappedProperty("Fourth Key"), "mappedProperty(Fourth Key");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
+ BeanUtils.populate(bean, map);
+ assertEquals("New First Value", bean.getMappedProperty("First Key"), "mappedProperty(First Key)");
+ assertEquals("Second Value", bean.getMappedProperty("Second Key"), "mappedProperty(Second Key)");
+ assertEquals("New Third Value", bean.getMappedProperty("Third Key"), "mappedProperty(Third Key)");
+ assertNull(bean.getMappedProperty("Fourth Key"), "mappedProperty(Fourth Key");
}
/**
* Test populate() method on nested properties.
*/
@Test
- public void testPopulateNested() {
-
- try {
-
- final HashMap<String, Object> map = new HashMap<>();
- map.put("nested.booleanProperty", "false");
- // booleanSecond is left at true
- map.put("nested.doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("nested.intProperty", "543");
- // longProperty is left at 321
- map.put("nested.shortProperty", "654");
- // stringProperty is left at "This is a string"
- map.put("nested.writeOnlyProperty", "New writeOnlyProperty value");
-
- BeanUtils.populate(bean, map);
-
- assertTrue(!bean.getNested().getBooleanProperty(), "booleanProperty is false");
- assertTrue(bean.getNested().isBooleanSecond(), "booleanSecond is true");
- assertEquals(432.0, bean.getNested().getDoubleProperty(), 0.005, "doubleProperty is 432.0");
- assertEquals((float) 123.0, bean.getNested().getFloatProperty(), (float) 0.005,
- "floatProperty is 123.0");
- assertEquals(543, bean.getNested().getIntProperty(), "intProperty is 543");
- assertEquals(321, bean.getNested().getLongProperty(), "longProperty is 321");
- assertEquals((short) 654, bean.getNested().getShortProperty(), "shortProperty is 654");
- assertEquals("This is a string", bean.getNested().getStringProperty(),
- "stringProperty is \"This is a string\"");
- assertEquals("New writeOnlyProperty value", bean.getNested().getWriteOnlyPropertyValue(),
- "writeOnlyProperty is \"New writeOnlyProperty value\"");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
+ public void testPopulateNested() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("nested.booleanProperty", "false");
+ // booleanSecond is left at true
+ map.put("nested.doubleProperty", "432.0");
+ // floatProperty is left at 123.0
+ map.put("nested.intProperty", "543");
+ // longProperty is left at 321
+ map.put("nested.shortProperty", "654");
+ // stringProperty is left at "This is a string"
+ map.put("nested.writeOnlyProperty", "New writeOnlyProperty value");
+
+ BeanUtils.populate(bean, map);
+
+ assertTrue(!bean.getNested().getBooleanProperty(), "booleanProperty is false");
+ assertTrue(bean.getNested().isBooleanSecond(), "booleanSecond is true");
+ assertEquals(432.0, bean.getNested().getDoubleProperty(), 0.005, "doubleProperty is 432.0");
+ assertEquals((float) 123.0, bean.getNested().getFloatProperty(), (float) 0.005, "floatProperty is 123.0");
+ assertEquals(543, bean.getNested().getIntProperty(), "intProperty is 543");
+ assertEquals(321, bean.getNested().getLongProperty(), "longProperty is 321");
+ assertEquals((short) 654, bean.getNested().getShortProperty(), "shortProperty is 654");
+ assertEquals("This is a string", bean.getNested().getStringProperty(), "stringProperty is \"This is a string\"");
+ assertEquals("New writeOnlyProperty value", bean.getNested().getWriteOnlyPropertyValue(), "writeOnlyProperty is \"New writeOnlyProperty value\"");
}
/**
* Test populate() method on scalar properties.
*/
@Test
- public void testPopulateScalar() {
-
- try {
-
- bean.setNullProperty("Non-null value");
-
- final HashMap<String, Object> map = new HashMap<>();
- map.put("booleanProperty", "false");
- // booleanSecond is left at true
- map.put("byteProperty", "111");
- map.put("doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("intProperty", "543");
- map.put("longProperty", "");
- map.put("nullProperty", null);
- map.put("shortProperty", "654");
- // stringProperty is left at "This is a string"
- map.put("writeOnlyProperty", "New writeOnlyProperty value");
- map.put("readOnlyProperty", "New readOnlyProperty value");
-
- BeanUtils.populate(bean, map);
-
- assertTrue(!bean.getBooleanProperty(), "booleanProperty is false");
- assertTrue(bean.isBooleanSecond(), "booleanSecond is true");
- assertEquals((byte) 111, bean.getByteProperty(), "byteProperty is 111");
- assertEquals(432.0, bean.getDoubleProperty(), 0.005, "doubleProperty is 432.0");
- assertEquals((float) 123.0, bean.getFloatProperty(), (float) 0.005, "floatProperty is 123.0");
- assertEquals(543, bean.getIntProperty(), "intProperty is 543");
- assertEquals(0, bean.getLongProperty(), "longProperty is 0");
- assertNull(bean.getNullProperty(), "nullProperty is null");
- assertEquals((short) 654, bean.getShortProperty(), "shortProperty is 654");
- assertEquals("This is a string", bean.getStringProperty(),
- "stringProperty is \"This is a string\"");
- assertEquals("New writeOnlyProperty value", bean.getWriteOnlyPropertyValue(),
- "writeOnlyProperty is \"New writeOnlyProperty value\"");
- assertEquals("Read Only String Property", bean.getReadOnlyProperty(),
- "readOnlyProperty is \"Read Only String Property\"");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
+ public void testPopulateScalar() throws Exception {
+ bean.setNullProperty("Non-null value");
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("booleanProperty", "false");
+ // booleanSecond is left at true
+ map.put("byteProperty", "111");
+ map.put("doubleProperty", "432.0");
+ // floatProperty is left at 123.0
+ map.put("intProperty", "543");
+ map.put("longProperty", "");
+ map.put("nullProperty", null);
+ map.put("shortProperty", "654");
+ // stringProperty is left at "This is a string"
+ map.put("writeOnlyProperty", "New writeOnlyProperty value");
+ map.put("readOnlyProperty", "New readOnlyProperty value");
+
+ BeanUtils.populate(bean, map);
+
+ assertTrue(!bean.getBooleanProperty(), "booleanProperty is false");
+ assertTrue(bean.isBooleanSecond(), "booleanSecond is true");
+ assertEquals((byte) 111, bean.getByteProperty(), "byteProperty is 111");
+ assertEquals(432.0, bean.getDoubleProperty(), 0.005, "doubleProperty is 432.0");
+ assertEquals((float) 123.0, bean.getFloatProperty(), (float) 0.005, "floatProperty is 123.0");
+ assertEquals(543, bean.getIntProperty(), "intProperty is 543");
+ assertEquals(0, bean.getLongProperty(), "longProperty is 0");
+ assertNull(bean.getNullProperty(), "nullProperty is null");
+ assertEquals((short) 654, bean.getShortProperty(), "shortProperty is 654");
+ assertEquals("This is a string", bean.getStringProperty(), "stringProperty is \"This is a string\"");
+ assertEquals("New writeOnlyProperty value", bean.getWriteOnlyPropertyValue(), "writeOnlyProperty is \"New writeOnlyProperty value\"");
+ assertEquals("Read Only String Property", bean.getReadOnlyProperty(), "readOnlyProperty is \"Read Only String Property\"");
}
/** Tests that separate instances can register separate instances */
@@ -1163,15 +1050,13 @@ public class BeanUtilsBeanTestCase {
map.put("sub-key-3", "sub-value-3");
bean.getMapProperty().put("mappedMap", map);
- assertEquals("sub-value-3", ((Map<?, ?>) bean.getMapProperty().get("mappedMap")).get("sub-key-3"),
- "BEFORE");
+ assertEquals("sub-value-3", ((Map<?, ?>) bean.getMapProperty().get("mappedMap")).get("sub-key-3"), "BEFORE");
try {
BeanUtils.setProperty(bean, "mapProperty(mappedMap)(sub-key-3)", "SUB-KEY-3-UPDATED");
} catch (final Throwable t) {
fail("Threw " + t + "");
}
- assertEquals("SUB-KEY-3-UPDATED", ((Map<?, ?>) bean.getMapProperty().get("mappedMap")).get("sub-key-3"),
- "AFTER");
+ assertEquals("SUB-KEY-3-UPDATED", ((Map<?, ?>) bean.getMapProperty().get("mappedMap")).get("sub-key-3"), "AFTER");
}
/**
@@ -1246,8 +1131,7 @@ public class BeanUtilsBeanTestCase {
fail("Threw " + t);
}
assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length");
- assertEquals(testUtilDate.toString(), bean.getStringArray()[0],
- "java.util.Date[] --> String[] value ");
+ assertEquals(testUtilDate.toString(), bean.getStringArray()[0], "java.util.Date[] --> String[] value ");
}
/**
diff --git a/src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java
index 823c8ab4..752f63d9 100644
--- a/src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java
@@ -25,7 +25,6 @@ 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.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -667,333 +666,223 @@ public class DynaBeanUtilsTestCase {
* tests the string and int arrays of TestBean
*/
@Test
- public void testGetArrayProperty() {
- try {
- String[] arr = BeanUtils.getArrayProperty(bean, "stringArray");
- final String[] comp = (String[]) bean.get("stringArray");
-
- assertEquals(comp.length, arr.length, "String array length = " + comp.length);
+ public void testGetArrayProperty() throws Exception {
+ String[] arr = BeanUtils.getArrayProperty(bean, "stringArray");
+ final String[] comp = (String[]) bean.get("stringArray");
- arr = BeanUtils.getArrayProperty(bean, "intArray");
- final int[] iarr = (int[]) bean.get("intArray");
+ assertEquals(comp.length, arr.length, "String array length = " + comp.length);
- assertEquals(iarr.length, arr.length, "String array length = " + iarr.length);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ arr = BeanUtils.getArrayProperty(bean, "intArray");
+ final int[] iarr = (int[]) bean.get("intArray");
+ assertEquals(iarr.length, arr.length, "String array length = " + iarr.length);
}
/**
* tests getting a 'whatever' property
*/
@Test
- public void testGetGeneralProperty() {
- try {
- final String val = BeanUtils.getProperty(bean, "nested.intIndexed[2]");
- final String comp = String.valueOf(bean.get("intIndexed", 2));
-
- assertEquals(val, comp, "nested.intIndexed[2] == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetGeneralProperty() throws Exception {
+ final String val = BeanUtils.getProperty(bean, "nested.intIndexed[2]");
+ final String comp = String.valueOf(bean.get("intIndexed", 2));
+
+ assertEquals(val, comp, "nested.intIndexed[2] == " + comp);
}
/**
* tests getting an indexed property
*/
@Test
- public void testGetIndexedProperty1() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed[3]");
- String comp = String.valueOf(bean.get("intIndexed", 3));
- assertEquals(val, comp, "intIndexed[3] == " + comp);
-
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed[3]");
- comp = (String) bean.get("stringIndexed", 3);
- assertEquals(val, comp, "stringIndexed[3] == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetIndexedProperty1() throws Exception {
+ String val = BeanUtils.getIndexedProperty(bean, "intIndexed[3]");
+ String comp = String.valueOf(bean.get("intIndexed", 3));
+ assertEquals(val, comp, "intIndexed[3] == " + comp);
+
+ val = BeanUtils.getIndexedProperty(bean, "stringIndexed[3]");
+ comp = (String) bean.get("stringIndexed", 3);
+ assertEquals(val, comp, "stringIndexed[3] == " + comp);
}
/**
* tests getting an indexed property
*/
@Test
- public void testGetIndexedProperty2() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed", 3);
- String comp = String.valueOf(bean.get("intIndexed", 3));
-
- assertEquals(val, comp, "intIndexed,3 == " + comp);
+ public void testGetIndexedProperty2() throws Exception {
+ String val = BeanUtils.getIndexedProperty(bean, "intIndexed", 3);
+ String comp = String.valueOf(bean.get("intIndexed", 3));
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed", 3);
- comp = (String) bean.get("stringIndexed", 3);
+ assertEquals(val, comp, "intIndexed,3 == " + comp);
- assertEquals(val, comp, "stringIndexed,3 == " + comp);
+ val = BeanUtils.getIndexedProperty(bean, "stringIndexed", 3);
+ comp = (String) bean.get("stringIndexed", 3);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ assertEquals(val, comp, "stringIndexed,3 == " + comp);
}
/**
* tests getting a nested property
*/
@Test
- public void testGetNestedProperty() {
- try {
- final String val = BeanUtils.getNestedProperty(bean, "nested.stringProperty");
- final String comp = nested.getStringProperty();
- assertEquals(val, comp, "nested.StringProperty == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetNestedProperty() throws Exception {
+ final String val = BeanUtils.getNestedProperty(bean, "nested.stringProperty");
+ final String comp = nested.getStringProperty();
+ assertEquals(val, comp, "nested.StringProperty == " + comp);
}
/**
* tests getting a 'whatever' property
*/
@Test
- public void testGetSimpleProperty() {
- try {
- final String val = BeanUtils.getSimpleProperty(bean, "shortProperty");
- final String comp = String.valueOf(bean.get("shortProperty"));
-
- assertEquals(val, comp, "shortProperty == " + comp);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetSimpleProperty() throws Exception {
+ final String val = BeanUtils.getSimpleProperty(bean, "shortProperty");
+ final String comp = String.valueOf(bean.get("shortProperty"));
+
+ assertEquals(val, comp, "shortProperty == " + comp);
}
/**
* Test populate() method on individual array elements.
*/
@Test
- public void testPopulateArrayElements() {
-
- try {
-
- final HashMap<String, Object> map = new HashMap<>();
- map.put("intIndexed[0]", "100");
- map.put("intIndexed[2]", "120");
- map.put("intIndexed[4]", "140");
-
- BeanUtils.populate(bean, map);
- final Integer intIndexed0 = (Integer) bean.get("intIndexed", 0);
- assertEquals(100, intIndexed0.intValue(), "intIndexed[0] is 100");
- final Integer intIndexed1 = (Integer) bean.get("intIndexed", 1);
- assertEquals(10, intIndexed1.intValue(), "intIndexed[1] is 10");
- final Integer intIndexed2 = (Integer) bean.get("intIndexed", 2);
- assertEquals(120, intIndexed2.intValue(), "intIndexed[2] is 120");
- final Integer intIndexed3 = (Integer) bean.get("intIndexed", 3);
- assertEquals(30, intIndexed3.intValue(), "intIndexed[3] is 30");
- final Integer intIndexed4 = (Integer) bean.get("intIndexed", 4);
- assertEquals(140, intIndexed4.intValue(), "intIndexed[4] is 140");
-
- map.clear();
- map.put("stringIndexed[1]", "New String 1");
- map.put("stringIndexed[3]", "New String 3");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("String 0", (String) bean.get("stringIndexed", 0),
- "stringIndexed[0] is \"String 0\"");
- assertEquals("New String 1", (String) bean.get("stringIndexed", 1),
- "stringIndexed[1] is \"New String 1\"");
- assertEquals("String 2", (String) bean.get("stringIndexed", 2),
- "stringIndexed[2] is \"String 2\"");
- assertEquals("New String 3", (String) bean.get("stringIndexed", 3),
- "stringIndexed[3] is \"New String 3\"");
- assertEquals("String 4", (String) bean.get("stringIndexed", 4),
- "stringIndexed[4] is \"String 4\"");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
+ public void testPopulateArrayElements() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("intIndexed[0]", "100");
+ map.put("intIndexed[2]", "120");
+ map.put("intIndexed[4]", "140");
+
+ BeanUtils.populate(bean, map);
+ final Integer intIndexed0 = (Integer) bean.get("intIndexed", 0);
+ assertEquals(100, intIndexed0.intValue(), "intIndexed[0] is 100");
+ final Integer intIndexed1 = (Integer) bean.get("intIndexed", 1);
+ assertEquals(10, intIndexed1.intValue(), "intIndexed[1] is 10");
+ final Integer intIndexed2 = (Integer) bean.get("intIndexed", 2);
+ assertEquals(120, intIndexed2.intValue(), "intIndexed[2] is 120");
+ final Integer intIndexed3 = (Integer) bean.get("intIndexed", 3);
+ assertEquals(30, intIndexed3.intValue(), "intIndexed[3] is 30");
+ final Integer intIndexed4 = (Integer) bean.get("intIndexed", 4);
+ assertEquals(140, intIndexed4.intValue(), "intIndexed[4] is 140");
+
+ map.clear();
+ map.put("stringIndexed[1]", "New String 1");
+ map.put("stringIndexed[3]", "New String 3");
+
+ BeanUtils.populate(bean, map);
+
+ assertEquals("String 0", (String) bean.get("stringIndexed", 0), "stringIndexed[0] is \"String 0\"");
+ assertEquals("New String 1", (String) bean.get("stringIndexed", 1), "stringIndexed[1] is \"New String 1\"");
+ assertEquals("String 2", (String) bean.get("stringIndexed", 2), "stringIndexed[2] is \"String 2\"");
+ assertEquals("New String 3", (String) bean.get("stringIndexed", 3), "stringIndexed[3] is \"New String 3\"");
+ assertEquals("String 4", (String) bean.get("stringIndexed", 4), "stringIndexed[4] is \"String 4\"");
}
/**
* Test populate() method on array properties as a whole.
*/
@Test
- public void testPopulateArrayProperties() {
-
- try {
+ public void testPopulateArrayProperties() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ // int[] intArray = new int[] { 123, 456, 789 };
+ final String[] intArrayIn = { "123", "456", "789" };
+ map.put("intArray", intArrayIn);
+ String[] stringArray = { "New String 0", "New String 1" };
+ map.put("stringArray", stringArray);
- final HashMap<String, Object> map = new HashMap<>();
- // int[] intArray = new int[] { 123, 456, 789 };
- final String[] intArrayIn = { "123", "456", "789" };
- map.put("intArray", intArrayIn);
- String[] stringArray = { "New String 0", "New String 1" };
- map.put("stringArray", stringArray);
-
- BeanUtils.populate(bean, map);
-
- final int[] intArray = (int[]) bean.get("intArray");
- assertNotNull(intArray, "intArray is present");
- assertEquals(3, intArray.length, "intArray length");
- assertEquals(123, intArray[0], "intArray[0]");
- assertEquals(456, intArray[1], "intArray[1]");
- assertEquals(789, intArray[2], "intArray[2]");
- stringArray = (String[]) bean.get("stringArray");
- assertNotNull(stringArray, "stringArray is present");
- assertEquals(2, stringArray.length, "stringArray length");
- assertEquals("New String 0", stringArray[0], "stringArray[0]");
- assertEquals("New String 1", stringArray[1], "stringArray[1]");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
+ BeanUtils.populate(bean, map);
+ final int[] intArray = (int[]) bean.get("intArray");
+ assertNotNull(intArray, "intArray is present");
+ assertEquals(3, intArray.length, "intArray length");
+ assertEquals(123, intArray[0], "intArray[0]");
+ assertEquals(456, intArray[1], "intArray[1]");
+ assertEquals(789, intArray[2], "intArray[2]");
+ stringArray = (String[]) bean.get("stringArray");
+ assertNotNull(stringArray, "stringArray is present");
+ assertEquals(2, stringArray.length, "stringArray length");
+ assertEquals("New String 0", stringArray[0], "stringArray[0]");
+ assertEquals("New String 1", stringArray[1], "stringArray[1]");
}
/**
* Test populate() on mapped properties.
*/
@Test
- public void testPopulateMapped() {
-
- try {
-
- final HashMap<String, Object> map = new HashMap<>();
- map.put("mappedProperty(First Key)", "New First Value");
- map.put("mappedProperty(Third Key)", "New Third Value");
-
- BeanUtils.populate(bean, map);
+ public void testPopulateMapped() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("mappedProperty(First Key)", "New First Value");
+ map.put("mappedProperty(Third Key)", "New Third Value");
- assertEquals("New First Value", (String) bean.get("mappedProperty", "First Key"),
- "mappedProperty(First Key)");
- assertEquals("Second Value", (String) bean.get("mappedProperty", "Second Key"),
- "mappedProperty(Second Key)");
- assertEquals("New Third Value", (String) bean.get("mappedProperty", "Third Key"),
- "mappedProperty(Third Key)");
- assertNull(bean.get("mappedProperty", "Fourth Key"), "mappedProperty(Fourth Key");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
+ BeanUtils.populate(bean, map);
+ assertEquals("New First Value", (String) bean.get("mappedProperty", "First Key"), "mappedProperty(First Key)");
+ assertEquals("Second Value", (String) bean.get("mappedProperty", "Second Key"), "mappedProperty(Second Key)");
+ assertEquals("New Third Value", (String) bean.get("mappedProperty", "Third Key"), "mappedProperty(Third Key)");
+ assertNull(bean.get("mappedProperty", "Fourth Key"), "mappedProperty(Fourth Key");
}
/**
* Test populate() method on nested properties.
*/
@Test
- public void testPopulateNested() {
-
- try {
-
- final HashMap<String, Object> map = new HashMap<>();
- map.put("nested.booleanProperty", "false");
- // booleanSecond is left at true
- map.put("nested.doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("nested.intProperty", "543");
- // longProperty is left at 321
- map.put("nested.shortProperty", "654");
- // stringProperty is left at "This is a string"
-
- BeanUtils.populate(bean, map);
-
- final TestBean nested = (TestBean) bean.get("nested");
- assertFalse(nested.getBooleanProperty(), "booleanProperty is false");
- assertTrue(nested.isBooleanSecond(), "booleanSecond is true");
- assertEquals(432.0, nested.getDoubleProperty(), 0.005, "doubleProperty is 432.0");
- assertEquals((float) 123.0, nested.getFloatProperty(), (float) 0.005, "floatProperty is 123.0");
- assertEquals(543, nested.getIntProperty(), "intProperty is 543");
- assertEquals(321, nested.getLongProperty(), "longProperty is 321");
- assertEquals((short) 654, nested.getShortProperty(), "shortProperty is 654");
- assertEquals("This is a string", nested.getStringProperty(),
- "stringProperty is \"This is a string\"");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
+ public void testPopulateNested() throws Exception {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("nested.booleanProperty", "false");
+ // booleanSecond is left at true
+ map.put("nested.doubleProperty", "432.0");
+ // floatProperty is left at 123.0
+ map.put("nested.intProperty", "543");
+ // longProperty is left at 321
+ map.put("nested.shortProperty", "654");
+ // stringProperty is left at "This is a string"
+
+ BeanUtils.populate(bean, map);
+
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertFalse(nested.getBooleanProperty(), "booleanProperty is false");
+ assertTrue(nested.isBooleanSecond(), "booleanSecond is true");
+ assertEquals(432.0, nested.getDoubleProperty(), 0.005, "doubleProperty is 432.0");
+ assertEquals((float) 123.0, nested.getFloatProperty(), (float) 0.005, "floatProperty is 123.0");
+ assertEquals(543, nested.getIntProperty(), "intProperty is 543");
+ assertEquals(321, nested.getLongProperty(), "longProperty is 321");
+ assertEquals((short) 654, nested.getShortProperty(), "shortProperty is 654");
+ assertEquals("This is a string", nested.getStringProperty(), "stringProperty is \"This is a string\"");
}
/**
* Test populate() method on scalar properties.
*/
@Test
- public void testPopulateScalar() {
-
- try {
-
- bean.set("nullProperty", "non-null value");
-
- final HashMap<String, Object> map = new HashMap<>();
- map.put("booleanProperty", "false");
- // booleanSecond is left at true
- map.put("doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("intProperty", "543");
- // longProperty is left at 321
- map.put("nullProperty", null);
- map.put("shortProperty", "654");
- // stringProperty is left at "This is a string"
-
- BeanUtils.populate(bean, map);
-
- final Boolean booleanProperty = (Boolean) bean.get("booleanProperty");
- assertFalse(booleanProperty.booleanValue(), "booleanProperty is false");
- final Boolean booleanSecond = (Boolean) bean.get("booleanSecond");
- assertTrue(booleanSecond.booleanValue(), "booleanSecond is true");
- final Double doubleProperty = (Double) bean.get("doubleProperty");
- assertEquals(432.0, doubleProperty.doubleValue(), 0.005, "doubleProperty is 432.0");
- final Float floatProperty = (Float) bean.get("floatProperty");
- assertEquals((float) 123.0, floatProperty.floatValue(), (float) 0.005, "floatProperty is 123.0");
- final Integer intProperty = (Integer) bean.get("intProperty");
- assertEquals(543, intProperty.intValue(), "intProperty is 543");
- final Long longProperty = (Long) bean.get("longProperty");
- assertEquals(321, longProperty.longValue(), "longProperty is 321");
- assertNull(bean.get("nullProperty"), "nullProperty is null");
- final Short shortProperty = (Short) bean.get("shortProperty");
- assertEquals((short) 654, shortProperty.shortValue(), "shortProperty is 654");
- assertEquals("This is a string", (String) bean.get("stringProperty"),
- "stringProperty is \"This is a string\"");
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
+ public void testPopulateScalar() throws Exception {
+ bean.set("nullProperty", "non-null value");
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("booleanProperty", "false");
+ // booleanSecond is left at true
+ map.put("doubleProperty", "432.0");
+ // floatProperty is left at 123.0
+ map.put("intProperty", "543");
+ // longProperty is left at 321
+ map.put("nullProperty", null);
+ map.put("shortProperty", "654");
+ // stringProperty is left at "This is a string"
+
+ BeanUtils.populate(bean, map);
+
+ final Boolean booleanProperty = (Boolean) bean.get("booleanProperty");
+ assertFalse(booleanProperty.booleanValue(), "booleanProperty is false");
+ final Boolean booleanSecond = (Boolean) bean.get("booleanSecond");
+ assertTrue(booleanSecond.booleanValue(), "booleanSecond is true");
+ final Double doubleProperty = (Double) bean.get("doubleProperty");
+ assertEquals(432.0, doubleProperty.doubleValue(), 0.005, "doubleProperty is 432.0");
+ final Float floatProperty = (Float) bean.get("floatProperty");
+ assertEquals((float) 123.0, floatProperty.floatValue(), (float) 0.005, "floatProperty is 123.0");
+ final Integer intProperty = (Integer) bean.get("intProperty");
+ assertEquals(543, intProperty.intValue(), "intProperty is 543");
+ final Long longProperty = (Long) bean.get("longProperty");
+ assertEquals(321, longProperty.longValue(), "longProperty is 321");
+ assertNull(bean.get("nullProperty"), "nullProperty is null");
+ final Short shortProperty = (Short) bean.get("shortProperty");
+ assertEquals((short) 654, shortProperty.shortValue(), "shortProperty is 654");
+ assertEquals("This is a string", (String) bean.get("stringProperty"), "stringProperty is \"This is a string\"");
}
/**
diff --git a/src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java
index d4ba3de9..2ea8aa34 100644
--- a/src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java
@@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -164,8 +163,7 @@ public class DynaPropertyUtilsTestCase {
// Scalar properties
assertEquals(false, ((Boolean) bean.get("booleanProperty")).booleanValue(), "booleanProperty");
assertEquals(333.0, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005, "doubleProperty");
- assertEquals((float) 222.0, ((Float) bean.get("floatProperty")).floatValue(), (float) 0.005,
- "floatProperty");
+ assertEquals((float) 222.0, ((Float) bean.get("floatProperty")).floatValue(), (float) 0.005, "floatProperty");
assertEquals(111, ((Integer) bean.get("intProperty")).intValue(), "intProperty");
assertEquals(444, ((Long) bean.get("longProperty")).longValue(), "longProperty");
assertEquals((short) 555, ((Short) bean.get("shortProperty")).shortValue(), "shortProperty");
@@ -465,19 +463,14 @@ public class DynaPropertyUtilsTestCase {
public void testGetMappedPeriods() {
bean.set("mappedProperty", "key.with.a.dot", "Special Value");
- assertEquals("Special Value", (String) bean.get("mappedProperty", "key.with.a.dot"),
- "Can retrieve directly");
+ assertEquals("Special Value", (String) bean.get("mappedProperty", "key.with.a.dot"), "Can retrieve directly");
try {
- assertEquals("Special Value",
- PropertyUtils.getMappedProperty(bean, "mappedProperty", "key.with.a.dot"),
- "Can retrieve via getMappedProperty");
+ assertEquals("Special Value", PropertyUtils.getMappedProperty(bean, "mappedProperty", "key.with.a.dot"), "Can retrieve via getMappedProperty");
} catch (final Exception e) {
fail("Thew exception: " + e);
}
try {
- assertEquals("Special Value",
- PropertyUtils.getNestedProperty(bean, "mappedProperty(key.with.a.dot)"),
- "Can retrieve via getNestedProperty");
+ assertEquals("Special Value", PropertyUtils.getNestedProperty(bean, "mappedProperty(key.with.a.dot)"), "Can retrieve via getNestedProperty");
} catch (final Exception e) {
fail("Thew exception: " + e);
}
@@ -485,8 +478,7 @@ public class DynaPropertyUtilsTestCase {
bean.set("mappedObjects", "nested.property", new TestBean());
assertNotNull(bean.get("mappedObjects", "nested.property"), "Can retrieve directly");
try {
- assertEquals("This is a string", PropertyUtils.getNestedProperty(bean, "mappedObjects(nested.property).stringProperty"),
- "Can retrieve nested");
+ assertEquals("This is a string", PropertyUtils.getNestedProperty(bean, "mappedObjects(nested.property).stringProperty"), "Can retrieve nested");
} catch (final Exception e) {
fail("Thew exception: " + e);
}
@@ -500,19 +492,14 @@ public class DynaPropertyUtilsTestCase {
public void testGetMappedSlashes() {
bean.set("mappedProperty", "key/with/a/slash", "Special Value");
- assertEquals("Special Value", bean.get("mappedProperty", "key/with/a/slash"),
- "Can retrieve directly");
+ assertEquals("Special Value", bean.get("mappedProperty", "key/with/a/slash"), "Can retrieve directly");
try {
- assertEquals("Special Value",
- PropertyUtils.getMappedProperty(bean, "mappedProperty", "key/with/a/slash"),
- "Can retrieve via getMappedProperty");
+ assertEquals("Special Value", PropertyUtils.getMappedProperty(bean, "mappedProperty", "key/with/a/slash"), "Can retrieve via getMappedProperty");
} catch (final Exception e) {
fail("Thew exception: " + e);
}
try {
- assertEquals("Special Value",
- PropertyUtils.getNestedProperty(bean, "mappedProperty(key/with/a/slash)"),
- "Can retrieve via getNestedProperty");
+ assertEquals("Special Value", PropertyUtils.getNestedProperty(bean, "mappedProperty(key/with/a/slash)"), "Can retrieve via getNestedProperty");
} catch (final Exception e) {
fail("Thew exception: " + e);
}
@@ -520,8 +507,7 @@ public class DynaPropertyUtilsTestCase {
bean.set("mappedObjects", "nested/property", new TestBean());
assertNotNull(bean.get("mappedObjects", "nested/property"), "Can retrieve directly");
try {
- assertEquals("This is a string", PropertyUtils.getNestedProperty(bean, "mappedObjects(nested/property).stringProperty"),
- "Can retrieve nested");
+ assertEquals("This is a string", PropertyUtils.getNestedProperty(bean, "mappedObjects(nested/property).stringProperty"), "Can retrieve nested");
} catch (final Exception e) {
fail("Thew exception: " + e);
}
@@ -620,215 +606,104 @@ public class DynaPropertyUtilsTestCase {
* Test getNestedProperty on a boolean property.
*/
@Test
- public void testGetNestedBoolean() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.booleanProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Boolean.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals(((Boolean) value).booleanValue(), nested.getBooleanProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedBoolean() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.booleanProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Boolean.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals(((Boolean) value).booleanValue(), nested.getBooleanProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a double property.
*/
@Test
- public void testGetNestedDouble() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.doubleProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Double.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals(((Double) value).doubleValue(), nested.getDoubleProperty(), 0.005,
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedDouble() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.doubleProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Double.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals(((Double) value).doubleValue(), nested.getDoubleProperty(), 0.005, "Got correct value");
}
/**
* Test getNestedProperty on a float property.
*/
@Test
- public void testGetNestedFloat() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.floatProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Float.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals(((Float) value).floatValue(), nested.getFloatProperty(), (float) 0.005,
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedFloat() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.floatProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Float.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals(((Float) value).floatValue(), nested.getFloatProperty(), (float) 0.005, "Got correct value");
}
/**
* Test getNestedProperty on an int property.
*/
@Test
- public void testGetNestedInt() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.intProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Integer.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals(((Integer) value).intValue(), nested.getIntProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedInt() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.intProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Integer.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals(((Integer) value).intValue(), nested.getIntProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a long property.
*/
@Test
- public void testGetNestedLong() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.longProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Long.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals(((Long) value).longValue(), nested.getLongProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedLong() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.longProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Long.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals(((Long) value).longValue(), nested.getLongProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a read-only String property.
*/
@Test
- public void testGetNestedReadOnly() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.readOnlyProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(String.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals((String) value, nested.getReadOnlyProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedReadOnly() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.readOnlyProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(String.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals((String) value, nested.getReadOnlyProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a short property.
*/
@Test
- public void testGetNestedShort() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.shortProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Short.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals(((Short) value).shortValue(), nested.getShortProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedShort() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.shortProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Short.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals(((Short) value).shortValue(), nested.getShortProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a String property.
*/
@Test
- public void testGetNestedString() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.stringProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(String.class, value, "Got correct type");
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals((String) value, nested.getStringProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedString() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.stringProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(String.class, value, "Got correct type");
+ final TestBean nested = (TestBean) bean.get("nested");
+ assertEquals((String) value, nested.getStringProperty(), "Got correct value");
}
/**
* Negative test getNestedProperty on an unknown property.
*/
@Test
- public void testGetNestedUnknown() {
-
- try {
- PropertyUtils.getNestedProperty(bean, "nested.unknown");
- fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- // Correct result for this test
- }
-
+ public void testGetNestedUnknown() throws Exception {
+ assertThrows(NoSuchMethodException.class, () -> PropertyUtils.getNestedProperty(bean, "nested.unknown"));
}
/**
@@ -844,155 +719,75 @@ public class DynaPropertyUtilsTestCase {
* Test getSimpleProperty on a boolean property.
*/
@Test
- public void testGetSimpleBoolean() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "booleanProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Boolean.class, value, "Got correct type");
- assertTrue(((Boolean) value).booleanValue(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleBoolean() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "booleanProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Boolean.class, value, "Got correct type");
+ assertTrue(((Boolean) value).booleanValue(), "Got correct value");
}
/**
* Test getSimpleProperty on a double property.
*/
@Test
- public void testGetSimpleDouble() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "doubleProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Double.class, value, "Got correct type");
- assertEquals(((Double) value).doubleValue(), 321.0, 0.005, "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleDouble() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "doubleProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Double.class, value, "Got correct type");
+ assertEquals(((Double) value).doubleValue(), 321.0, 0.005, "Got correct value");
}
/**
* Test getSimpleProperty on a float property.
*/
@Test
- public void testGetSimpleFloat() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "floatProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Float.class, value, "Got correct type");
- assertEquals(((Float) value).floatValue(), (float) 123.0, (float) 0.005, "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleFloat() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "floatProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Float.class, value, "Got correct type");
+ assertEquals(((Float) value).floatValue(), (float) 123.0, (float) 0.005, "Got correct value");
}
/**
* Negative test getSimpleProperty on an indexed property.
*/
@Test
- public void testGetSimpleIndexed() {
-
- try {
- PropertyUtils.getSimpleProperty(bean, "intIndexed[0]");
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- // Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleIndexed() throws Exception {
+ assertThrows(IllegalArgumentException.class, () -> PropertyUtils.getSimpleProperty(bean, "intIndexed[0]"));
}
/**
* Test getSimpleProperty on an int property.
*/
@Test
- public void testGetSimpleInt() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "intProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Integer.class, value, "Got correct type");
- assertEquals(((Integer) value).intValue(), 123, "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleInt() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "intProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Integer.class, value, "Got correct type");
+ assertEquals(((Integer) value).intValue(), 123, "Got correct value");
}
/**
* Test getSimpleProperty on a long property.
*/
@Test
- public void testGetSimpleLong() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "longProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Long.class, value, "Got correct type");
- assertEquals(((Long) value).longValue(), 321, "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleLong() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "longProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Long.class, value, "Got correct type");
+ assertEquals(((Long) value).longValue(), 321, "Got correct value");
}
/**
* Negative test getSimpleProperty on a nested property.
*/
@Test
- public void testGetSimpleNested() {
-
+ public void testGetSimpleNested() throws Exception {
try {
PropertyUtils.getSimpleProperty(bean, "nested.stringProperty");
fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
} catch (final IllegalArgumentException e) {
// Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
}
}
@@ -1001,67 +796,35 @@ public class DynaPropertyUtilsTestCase {
* Test getSimpleProperty on a short property.
*/
@Test
- public void testGetSimpleShort() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "shortProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Short.class, value, "Got correct type");
- assertEquals(((Short) value).shortValue(), (short) 987, "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleShort() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "shortProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Short.class, value, "Got correct type");
+ assertEquals(((Short) value).shortValue(), (short) 987, "Got correct value");
}
/**
* Test getSimpleProperty on a String property.
*/
@Test
- public void testGetSimpleString() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "stringProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(String.class, value, "Got correct type");
- assertEquals((String) value, "This is a string", "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleString() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "stringProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(String.class, value, "Got correct type");
+ assertEquals((String) value, "This is a string", "Got correct value");
}
/**
* Negative test getSimpleProperty on an unknown property.
*/
@Test
- public void testGetSimpleUnknown() {
-
+ public void testGetSimpleUnknown() throws Exception {
try {
PropertyUtils.getSimpleProperty(bean, "unknown");
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
- assertEquals("Unknown property 'unknown' on dynaclass '" + bean.getDynaClass() + "'",
- e.getMessage());
+ assertEquals("Unknown property 'unknown' on dynaclass '" + bean.getDynaClass() + "'", e.getMessage());
}
}
@@ -1397,134 +1160,67 @@ public class DynaPropertyUtilsTestCase {
* Test setNextedProperty on a boolean property.
*/
@Test
- public void testSetNestedBoolean() {
-
- try {
- final boolean oldValue = nested.getBooleanProperty();
- final boolean newValue = !oldValue;
- PropertyUtils.setNestedProperty(bean, "nested.booleanProperty", Boolean.valueOf(newValue));
- assertEquals(newValue, nested.getBooleanProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedBoolean() throws Exception {
+ final boolean oldValue = nested.getBooleanProperty();
+ final boolean newValue = !oldValue;
+ PropertyUtils.setNestedProperty(bean, "nested.booleanProperty", Boolean.valueOf(newValue));
+ assertEquals(newValue, nested.getBooleanProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a double property.
*/
@Test
- public void testSetNestedDouble() {
-
- try {
- final double oldValue = nested.getDoubleProperty();
- final double newValue = oldValue + 1.0;
- PropertyUtils.setNestedProperty(bean, "nested.doubleProperty", Double.valueOf(newValue));
- assertEquals(newValue, nested.getDoubleProperty(), 0.005, "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedDouble() throws Exception {
+ final double oldValue = nested.getDoubleProperty();
+ final double newValue = oldValue + 1.0;
+ PropertyUtils.setNestedProperty(bean, "nested.doubleProperty", Double.valueOf(newValue));
+ assertEquals(newValue, nested.getDoubleProperty(), 0.005, "Matched new value");
}
/**
* Test setNestedProperty on a float property.
*/
@Test
- public void testSetNestedFloat() {
-
- try {
- final float oldValue = nested.getFloatProperty();
- final float newValue = oldValue + (float) 1.0;
- PropertyUtils.setNestedProperty(bean, "nested.floatProperty", Float.valueOf(newValue));
- assertEquals(newValue, nested.getFloatProperty(), (float) 0.005, "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedFloat() throws Exception {
+ final float oldValue = nested.getFloatProperty();
+ final float newValue = oldValue + (float) 1.0;
+ PropertyUtils.setNestedProperty(bean, "nested.floatProperty", Float.valueOf(newValue));
+ assertEquals(newValue, nested.getFloatProperty(), (float) 0.005, "Matched new value");
}
/**
* Test setNestedProperty on a int property.
*/
@Test
- public void testSetNestedInt() {
-
- try {
- final int oldValue = nested.getIntProperty();
- final int newValue = oldValue + 1;
- PropertyUtils.setNestedProperty(bean, "nested.intProperty", Integer.valueOf(newValue));
- assertEquals(newValue, nested.getIntProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedInt() throws Exception {
+ final int oldValue = nested.getIntProperty();
+ final int newValue = oldValue + 1;
+ PropertyUtils.setNestedProperty(bean, "nested.intProperty", Integer.valueOf(newValue));
+ assertEquals(newValue, nested.getIntProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a long property.
*/
@Test
- public void testSetNestedLong() {
-
- try {
- final long oldValue = nested.getLongProperty();
- final long newValue = oldValue + 1;
- PropertyUtils.setNestedProperty(bean, "nested.longProperty", Long.valueOf(newValue));
- assertEquals(newValue, nested.getLongProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedLong() throws Exception {
+ final long oldValue = nested.getLongProperty();
+ final long newValue = oldValue + 1;
+ PropertyUtils.setNestedProperty(bean, "nested.longProperty", Long.valueOf(newValue));
+ assertEquals(newValue, nested.getLongProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a read-only String property.
*/
@Test
- public void testSetNestedReadOnly() {
-
+ public void testSetNestedReadOnly() throws Exception {
try {
final String oldValue = nested.getWriteOnlyPropertyValue();
final String newValue = oldValue + " Extra Value";
PropertyUtils.setNestedProperty(bean, "nested.readOnlyProperty", newValue);
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
}
@@ -1535,65 +1231,34 @@ public class DynaPropertyUtilsTestCase {
* Test setNestedProperty on a short property.
*/
@Test
- public void testSetNestedShort() {
-
- try {
- final short oldValue = nested.getShortProperty();
- short newValue = oldValue;
- newValue++;
- PropertyUtils.setNestedProperty(bean, "nested.shortProperty", Short.valueOf(newValue));
- assertEquals(newValue, nested.getShortProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedShort() throws Exception {
+ final short oldValue = nested.getShortProperty();
+ short newValue = oldValue;
+ newValue++;
+ PropertyUtils.setNestedProperty(bean, "nested.shortProperty", Short.valueOf(newValue));
+ assertEquals(newValue, nested.getShortProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a String property.
*/
@Test
- public void testSetNestedString() {
-
- try {
- final String oldValue = nested.getStringProperty();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setNestedProperty(bean, "nested.stringProperty", newValue);
- assertEquals(newValue, nested.getStringProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedString() throws Exception {
+ final String oldValue = nested.getStringProperty();
+ final String newValue = oldValue + " Extra Value";
+ PropertyUtils.setNestedProperty(bean, "nested.stringProperty", newValue);
+ assertEquals(newValue, nested.getStringProperty(), "Matched new value");
}
/**
* Test setNestedProperty on an unknown property name.
*/
@Test
- public void testSetNestedUnknown() {
-
+ public void testSetNestedUnknown() throws Exception {
try {
final String newValue = "New String Value";
PropertyUtils.setNestedProperty(bean, "nested.unknown", newValue);
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
}
@@ -1604,23 +1269,11 @@ public class DynaPropertyUtilsTestCase {
* Test setNestedProperty on a write-only String property.
*/
@Test
- public void testSetNestedWriteOnly() {
-
- try {
- final String oldValue = nested.getWriteOnlyPropertyValue();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setNestedProperty(bean, "nested.writeOnlyProperty", newValue);
- assertEquals(newValue, nested.getWriteOnlyPropertyValue(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedWriteOnly() throws Exception {
+ final String oldValue = nested.getWriteOnlyPropertyValue();
+ final String newValue = oldValue + " Extra Value";
+ PropertyUtils.setNestedProperty(bean, "nested.writeOnlyProperty", newValue);
+ assertEquals(newValue, nested.getWriteOnlyPropertyValue(), "Matched new value");
}
/**
@@ -1636,229 +1289,118 @@ public class DynaPropertyUtilsTestCase {
* Test setSimpleProperty on a boolean property.
*/
@Test
- public void testSetSimpleBoolean() {
-
- try {
- final boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue();
- final boolean newValue = !oldValue;
- PropertyUtils.setSimpleProperty(bean, "booleanProperty", Boolean.valueOf(newValue));
- assertEquals(newValue, ((Boolean) bean.get("booleanProperty")).booleanValue(),
- "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleBoolean() throws Exception {
+ final boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue();
+ final boolean newValue = !oldValue;
+ PropertyUtils.setSimpleProperty(bean, "booleanProperty", Boolean.valueOf(newValue));
+ assertEquals(newValue, ((Boolean) bean.get("booleanProperty")).booleanValue(), "Matched new value");
}
/**
* Test setSimpleProperty on a double property.
*/
@Test
- public void testSetSimpleDouble() {
-
- try {
- final double oldValue = ((Double) bean.get("doubleProperty")).doubleValue();
- final double newValue = oldValue + 1.0;
- PropertyUtils.setSimpleProperty(bean, "doubleProperty", Double.valueOf(newValue));
- assertEquals(newValue, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005,
- "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleDouble() throws Exception {
+ final double oldValue = ((Double) bean.get("doubleProperty")).doubleValue();
+ final double newValue = oldValue + 1.0;
+ PropertyUtils.setSimpleProperty(bean, "doubleProperty", Double.valueOf(newValue));
+ assertEquals(newValue, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005, "Matched new value");
}
/**
* Test setSimpleProperty on a float property.
*/
@Test
- public void testSetSimpleFloat() {
-
- try {
- final float oldValue = ((Float) bean.get("floatProperty")).floatValue();
- final float newValue = oldValue + (float) 1.0;
- PropertyUtils.setSimpleProperty(bean, "floatProperty", Float.valueOf(newValue));
- assertEquals(newValue, ((Float) bean.get("floatProperty")).floatValue(), (float) 0.005,
- "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleFloat() throws Exception {
+ final float oldValue = ((Float) bean.get("floatProperty")).floatValue();
+ final float newValue = oldValue + (float) 1.0;
+ PropertyUtils.setSimpleProperty(bean, "floatProperty", Float.valueOf(newValue));
+ assertEquals(newValue, ((Float) bean.get("floatProperty")).floatValue(), (float) 0.005, "Matched new value");
}
/**
* Negative test setSimpleProperty on an indexed property.
*/
@Test
- public void testSetSimpleIndexed() {
-
+ public void testSetSimpleIndexed() throws Exception {
try {
PropertyUtils.setSimpleProperty(bean, "stringIndexed[0]", "New String Value");
fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
} catch (final IllegalArgumentException e) {
// Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
}
-
}
/**
* Test setSimpleProperty on a int property.
*/
@Test
- public void testSetSimpleInt() {
-
- try {
- final int oldValue = ((Integer) bean.get("intProperty")).intValue();
- final int newValue = oldValue + 1;
- PropertyUtils.setSimpleProperty(bean, "intProperty", Integer.valueOf(newValue));
- assertEquals(newValue, ((Integer) bean.get("intProperty")).intValue(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleInt() throws Exception {
+ final int oldValue = ((Integer) bean.get("intProperty")).intValue();
+ final int newValue = oldValue + 1;
+ PropertyUtils.setSimpleProperty(bean, "intProperty", Integer.valueOf(newValue));
+ assertEquals(newValue, ((Integer) bean.get("intProperty")).intValue(), "Matched new value");
}
/**
* Test setSimpleProperty on a long property.
*/
@Test
- public void testSetSimpleLong() {
-
- try {
- final long oldValue = ((Long) bean.get("longProperty")).longValue();
- final long newValue = oldValue + 1;
- PropertyUtils.setSimpleProperty(bean, "longProperty", Long.valueOf(newValue));
- assertEquals(newValue, ((Long) bean.get("longProperty")).longValue(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleLong() throws Exception {
+ final long oldValue = ((Long) bean.get("longProperty")).longValue();
+ final long newValue = oldValue + 1;
+ PropertyUtils.setSimpleProperty(bean, "longProperty", Long.valueOf(newValue));
+ assertEquals(newValue, ((Long) bean.get("longProperty")).longValue(), "Matched new value");
}
/**
* Negative test setSimpleProperty on a nested property.
*/
@Test
- public void testSetSimpleNested() {
-
+ public void testSetSimpleNested() throws Exception {
try {
PropertyUtils.setSimpleProperty(bean, "nested.stringProperty", "New String Value");
fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
} catch (final IllegalArgumentException e) {
// Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
}
-
}
/**
* Test setSimpleProperty on a short property.
*/
@Test
- public void testSetSimpleShort() {
-
- try {
- final short oldValue = ((Short) bean.get("shortProperty")).shortValue();
- short newValue = oldValue;
- newValue++;
- PropertyUtils.setSimpleProperty(bean, "shortProperty", Short.valueOf(newValue));
- assertEquals(newValue, ((Short) bean.get("shortProperty")).shortValue(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleShort() throws Exception {
+ final short oldValue = ((Short) bean.get("shortProperty")).shortValue();
+ short newValue = oldValue;
+ newValue++;
+ PropertyUtils.setSimpleProperty(bean, "shortProperty", Short.valueOf(newValue));
+ assertEquals(newValue, ((Short) bean.get("shortProperty")).shortValue(), "Matched new value");
}
/**
* Test setSimpleProperty on a String property.
*/
@Test
- public void testSetSimpleString() {
-
- try {
- final String oldValue = (String) bean.get("stringProperty");
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setSimpleProperty(bean, "stringProperty", newValue);
- assertEquals(newValue, (String) bean.get("stringProperty"), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleString() throws Exception {
+ final String oldValue = (String) bean.get("stringProperty");
+ final String newValue = oldValue + " Extra Value";
+ PropertyUtils.setSimpleProperty(bean, "stringProperty", newValue);
+ assertEquals(newValue, (String) bean.get("stringProperty"), "Matched new value");
}
/**
* Test setSimpleProperty on an unknown property name.
*/
@Test
- public void testSetSimpleUnknown() {
-
+ public void testSetSimpleUnknown() throws Exception {
try {
final String newValue = "New String Value";
PropertyUtils.setSimpleProperty(bean, "unknown", newValue);
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
- assertEquals("Unknown property 'unknown' on dynaclass '" + bean.getDynaClass() + "'",
- e.getMessage());
+ assertEquals("Unknown property 'unknown' on dynaclass '" + bean.getDynaClass() + "'", e.getMessage());
}
}
diff --git a/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
index a3e9ac79..d08b331e 100644
--- a/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
@@ -371,78 +371,64 @@ public class PropertyUtilsTestCase {
* @param name Name of the property to be retrieved
* @param read Expected name of the read method (or null)
* @param write Expected name of the write method (or null)
+ * @throws NoSuchMethodException
+ * @throws InvocationTargetException
+ * @throws IllegalAccessException
*/
- private void testGetDescriptorBase(final String name, final String read, final String write) {
-
- try {
- final PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(bean, name);
- if (read == null && write == null) {
- assertNull(pd, "Got descriptor");
- return;
- }
- assertNotNull(pd, "Got descriptor");
- final Method rm = pd.getReadMethod();
- if (read != null) {
- assertNotNull(rm, "Got read method");
- assertEquals(rm.getName(), read, "Got correct read method");
- } else {
- assertNull(rm, "Got read method");
- }
- final Method wm = pd.getWriteMethod();
- if (write != null) {
- assertNotNull(wm, "Got write method");
- assertEquals(wm.getName(), write, "Got correct write method");
- } else {
- assertNull(wm, "Got write method");
- }
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
+ private void testGetDescriptorBase(final String name, final String read, final String write)
+ throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+ final PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(bean, name);
+ if (read == null && write == null) {
+ assertNull(pd, "Got descriptor");
+ return;
+ }
+ assertNotNull(pd, "Got descriptor");
+ final Method rm = pd.getReadMethod();
+ if (read != null) {
+ assertNotNull(rm, "Got read method");
+ assertEquals(rm.getName(), read, "Got correct read method");
+ } else {
+ assertNull(rm, "Got read method");
+ }
+ final Method wm = pd.getWriteMethod();
+ if (write != null) {
+ assertNotNull(wm, "Got write method");
+ assertEquals(wm.getName(), write, "Got correct write method");
+ } else {
+ assertNull(wm, "Got write method");
}
-
}
/**
* Positive getPropertyDescriptor on property {@code booleanProperty}.
*/
@Test
- public void testGetDescriptorBoolean() {
-
+ public void testGetDescriptorBoolean() throws Exception {
testGetDescriptorBase("booleanProperty", "getBooleanProperty", "setBooleanProperty");
-
}
/**
* Positive getPropertyDescriptor on property {@code doubleProperty}.
*/
@Test
- public void testGetDescriptorDouble() {
-
+ public void testGetDescriptorDouble() throws Exception {
testGetDescriptorBase("doubleProperty", "getDoubleProperty", "setDoubleProperty");
-
}
/**
* Positive getPropertyDescriptor on property {@code floatProperty}.
*/
@Test
- public void testGetDescriptorFloat() {
-
+ public void testGetDescriptorFloat() throws Exception {
testGetDescriptorBase("floatProperty", "getFloatProperty", "setFloatProperty");
-
}
/**
* Positive getPropertyDescriptor on property {@code intProperty}.
*/
@Test
- public void testGetDescriptorInt() {
-
+ public void testGetDescriptorInt() throws Exception {
testGetDescriptorBase("intProperty", "getIntProperty", "setIntProperty");
-
}
/**
@@ -472,10 +458,8 @@ public class PropertyUtilsTestCase {
* Positive getPropertyDescriptor on property {@code longProperty}.
*/
@Test
- public void testGetDescriptorLong() {
-
+ public void testGetDescriptorLong() throws Exception {
testGetDescriptorBase("longProperty", "getLongProperty", "setLongProperty");
-
}
/**
@@ -516,10 +500,8 @@ public class PropertyUtilsTestCase {
* Positive getPropertyDescriptor on property {@code readOnlyProperty}.
*/
@Test
- public void testGetDescriptorReadOnly() {
-
+ public void testGetDescriptorReadOnly() throws Exception {
testGetDescriptorBase("readOnlyProperty", "getReadOnlyProperty", null);
-
}
/**
@@ -561,7 +543,7 @@ public class PropertyUtilsTestCase {
* Positive getPropertyDescriptor on property {@code booleanSecond} that uses an "is" method as the getter.
*/
@Test
- public void testGetDescriptorSecond() {
+ public void testGetDescriptorSecond() throws Exception {
testGetDescriptorBase("booleanSecond", "isBooleanSecond", "setBooleanSecond");
}
@@ -569,7 +551,7 @@ public class PropertyUtilsTestCase {
* Positive getPropertyDescriptor on property {@code shortProperty}.
*/
@Test
- public void testGetDescriptorShort() {
+ public void testGetDescriptorShort() throws Exception {
testGetDescriptorBase("shortProperty", "getShortProperty", "setShortProperty");
}
@@ -577,7 +559,7 @@ public class PropertyUtilsTestCase {
* Positive getPropertyDescriptor on property {@code stringProperty}.
*/
@Test
- public void testGetDescriptorString() {
+ public void testGetDescriptorString() throws Exception {
testGetDescriptorBase("stringProperty", "getStringProperty", "setStringProperty");
}
@@ -585,7 +567,7 @@ public class PropertyUtilsTestCase {
* Negative getPropertyDescriptor on property {@code unknown}.
*/
@Test
- public void testGetDescriptorUnknown() {
+ public void testGetDescriptorUnknown() throws Exception {
testGetDescriptorBase("unknown", null, null);
}
@@ -593,7 +575,7 @@ public class PropertyUtilsTestCase {
* Positive getPropertyDescriptor on property {@code writeOnlyProperty}.
*/
@Test
- public void testGetDescriptorWriteOnly() {
+ public void testGetDescriptorWriteOnly() throws Exception {
testGetDescriptorBase("writeOnlyProperty", null, "setWriteOnlyProperty");
}
@@ -1190,205 +1172,98 @@ public class PropertyUtilsTestCase {
* Test getNestedProperty on a boolean property.
*/
@Test
- public void testGetNestedBoolean() {
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.booleanProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Boolean.class, value, "Got correct type");
- assertEquals(((Boolean) value).booleanValue(), bean.getNested().getBooleanProperty(),
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
+ public void testGetNestedBoolean() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.booleanProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Boolean.class, value, "Got correct type");
+ assertEquals(((Boolean) value).booleanValue(), bean.getNested().getBooleanProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a double property.
*/
@Test
- public void testGetNestedDouble() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.doubleProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Double.class, value, "Got correct type");
- assertEquals(((Double) value).doubleValue(), bean.getNested().getDoubleProperty(), 0.005,
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedDouble() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.doubleProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Double.class, value, "Got correct type");
+ assertEquals(((Double) value).doubleValue(), bean.getNested().getDoubleProperty(), 0.005, "Got correct value");
}
/**
* Test getNestedProperty on a float property.
*/
@Test
- public void testGetNestedFloat() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.floatProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Float.class, value, "Got correct type");
- assertEquals(((Float) value).floatValue(), bean.getNested().getFloatProperty(), (float) 0.005,
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedFloat() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.floatProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Float.class, value, "Got correct type");
+ assertEquals(((Float) value).floatValue(), bean.getNested().getFloatProperty(), (float) 0.005, "Got correct value");
}
/**
* Test getNestedProperty on an int property.
*/
@Test
- public void testGetNestedInt() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.intProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Integer.class, value, "Got correct type");
- assertEquals(((Integer) value).intValue(), bean.getNested().getIntProperty(),
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedInt() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.intProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Integer.class, value, "Got correct type");
+ assertEquals(((Integer) value).intValue(), bean.getNested().getIntProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a long property.
*/
@Test
- public void testGetNestedLong() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.longProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Long.class, value, "Got correct type");
- assertEquals(((Long) value).longValue(), bean.getNested().getLongProperty(),
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedLong() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.longProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Long.class, value, "Got correct type");
+ assertEquals(((Long) value).longValue(), bean.getNested().getLongProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a read-only String property.
*/
@Test
- public void testGetNestedReadOnly() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.readOnlyProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(String.class, value, "Got correct type");
- assertEquals((String) value, bean.getReadOnlyProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedReadOnly() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.readOnlyProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(String.class, value, "Got correct type");
+ assertEquals((String) value, bean.getReadOnlyProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a short property.
*/
@Test
- public void testGetNestedShort() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.shortProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Short.class, value, "Got correct type");
- assertEquals(((Short) value).shortValue(), bean.getNested().getShortProperty(),
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedShort() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.shortProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Short.class, value, "Got correct type");
+ assertEquals(((Short) value).shortValue(), bean.getNested().getShortProperty(), "Got correct value");
}
/**
* Test getNestedProperty on a String property.
*/
@Test
- public void testGetNestedString() {
-
- try {
- final Object value = PropertyUtils.getNestedProperty(bean, "nested.stringProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(String.class, value, "Got correct type");
- assertEquals((String) value, bean.getNested().getStringProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetNestedString() throws Exception {
+ final Object value = PropertyUtils.getNestedProperty(bean, "nested.stringProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(String.class, value, "Got correct type");
+ assertEquals((String) value, bean.getNested().getStringProperty(), "Got correct value");
}
/**
* Negative test getNestedProperty on an unknown property.
*/
@Test
- public void testGetNestedUnknown() {
-
+ public void testGetNestedUnknown() throws Exception {
try {
PropertyUtils.getNestedProperty(bean, "nested.unknown");
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
}
@@ -1399,17 +1274,10 @@ public class PropertyUtilsTestCase {
* Test getNestedProperty on a write-only String property.
*/
@Test
- public void testGetNestedWriteOnly() {
-
+ public void testGetNestedWriteOnly() throws Exception {
try {
PropertyUtils.getNestedProperty(bean, "writeOnlyProperty");
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
}
@@ -1420,116 +1288,109 @@ public class PropertyUtilsTestCase {
* Test getPropertyType() on all kinds of properties.
*/
@Test
- public void testGetPropertyType() {
+ public void testGetPropertyType() throws Exception {
Class<?> clazz = null;
final int[] intArray = {};
final String[] stringArray = {};
- try {
-
- // Scalar and Indexed Properties
- clazz = PropertyUtils.getPropertyType(bean, "booleanProperty");
- assertEquals(Boolean.TYPE, clazz, "booleanProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "booleanSecond");
- assertEquals(Boolean.TYPE, clazz, "booleanSecond type");
- clazz = PropertyUtils.getPropertyType(bean, "doubleProperty");
- assertEquals(Double.TYPE, clazz, "doubleProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "dupProperty");
- assertEquals(String.class, clazz, "dupProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "floatProperty");
- assertEquals(Float.TYPE, clazz, "floatProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "intArray");
- assertEquals(intArray.getClass(), clazz, "intArray type");
- clazz = PropertyUtils.getPropertyType(bean, "intIndexed");
- assertEquals(Integer.TYPE, clazz, "intIndexed type");
- clazz = PropertyUtils.getPropertyType(bean, "intProperty");
- assertEquals(Integer.TYPE, clazz, "intProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "listIndexed");
- assertEquals(List.class, clazz, "listIndexed type");
- clazz = PropertyUtils.getPropertyType(bean, "longProperty");
- assertEquals(Long.TYPE, clazz, "longProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "mappedProperty");
- assertEquals(String.class, clazz, "mappedProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "mappedIntProperty");
- assertEquals(Integer.TYPE, clazz, "mappedIntProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "readOnlyProperty");
- assertEquals(String.class, clazz, "readOnlyProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "shortProperty");
- assertEquals(Short.TYPE, clazz, "shortProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "stringArray");
- assertEquals(stringArray.getClass(), clazz, "stringArray type");
- clazz = PropertyUtils.getPropertyType(bean, "stringIndexed");
- assertEquals(String.class, clazz, "stringIndexed type");
- clazz = PropertyUtils.getPropertyType(bean, "stringProperty");
- assertEquals(String.class, clazz, "stringProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "writeOnlyProperty");
- assertEquals(String.class, clazz, "writeOnlyProperty type");
-
- // Nested Properties
- clazz = PropertyUtils.getPropertyType(bean, "nested.booleanProperty");
- assertEquals(Boolean.TYPE, clazz, "booleanProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.booleanSecond");
- assertEquals(Boolean.TYPE, clazz, "booleanSecond type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.doubleProperty");
- assertEquals(Double.TYPE, clazz, "doubleProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.dupProperty");
- assertEquals(String.class, clazz, "dupProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.floatProperty");
- assertEquals(Float.TYPE, clazz, "floatProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.intArray");
- assertEquals(intArray.getClass(), clazz, "intArray type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.intIndexed");
- assertEquals(Integer.TYPE, clazz, "intIndexed type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.intProperty");
- assertEquals(Integer.TYPE, clazz, "intProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.listIndexed");
- assertEquals(List.class, clazz, "listIndexed type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.longProperty");
- assertEquals(Long.TYPE, clazz, "longProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.mappedProperty");
- assertEquals(String.class, clazz, "mappedProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.mappedIntProperty");
- assertEquals(Integer.TYPE, clazz, "mappedIntProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.readOnlyProperty");
- assertEquals(String.class, clazz, "readOnlyProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.shortProperty");
- assertEquals(Short.TYPE, clazz, "shortProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.stringArray");
- assertEquals(stringArray.getClass(), clazz, "stringArray type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.stringIndexed");
- assertEquals(String.class, clazz, "stringIndexed type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.stringProperty");
- assertEquals(String.class, clazz, "stringProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nested.writeOnlyProperty");
- assertEquals(String.class, clazz, "writeOnlyProperty type");
-
- // Nested DynaBean
- clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean");
- assertEquals(DynaBean.class, clazz, "nestedDynaBean type");
- clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.stringProperty");
- assertEquals(String.class, clazz, "nestedDynaBean.stringProperty type");
- clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nestedBean");
- assertEquals(TestBean.class, clazz, "nestedDynaBean.nestedBean type");
- clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nestedBean.nestedDynaBean");
- assertEquals(DynaBean.class, clazz, "nestedDynaBean.nestedBean.nestedDynaBean type");
- clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nestedBean.nestedDynaBean.stringProperty");
- assertEquals(String.class, clazz, "nestedDynaBean.nestedBean.nestedDynaBean.stringPropert type");
-
- // test Null
- clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nullDynaBean");
- assertEquals(DynaBean.class, clazz, "nestedDynaBean.nullDynaBean type");
- try {
- clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nullDynaBean.foo");
- fail("Expected NestedNullException for nestedDynaBean.nullDynaBean.foo");
- } catch (final NestedNullException e) {
- // expected
- }
-
- } catch (final Exception e) {
- fail("Exception: " + e.getMessage());
+ // Scalar and Indexed Properties
+ clazz = PropertyUtils.getPropertyType(bean, "booleanProperty");
+ assertEquals(Boolean.TYPE, clazz, "booleanProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "booleanSecond");
+ assertEquals(Boolean.TYPE, clazz, "booleanSecond type");
+ clazz = PropertyUtils.getPropertyType(bean, "doubleProperty");
+ assertEquals(Double.TYPE, clazz, "doubleProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "dupProperty");
+ assertEquals(String.class, clazz, "dupProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "floatProperty");
+ assertEquals(Float.TYPE, clazz, "floatProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "intArray");
+ assertEquals(intArray.getClass(), clazz, "intArray type");
+ clazz = PropertyUtils.getPropertyType(bean, "intIndexed");
+ assertEquals(Integer.TYPE, clazz, "intIndexed type");
+ clazz = PropertyUtils.getPropertyType(bean, "intProperty");
+ assertEquals(Integer.TYPE, clazz, "intProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "listIndexed");
+ assertEquals(List.class, clazz, "listIndexed type");
+ clazz = PropertyUtils.getPropertyType(bean, "longProperty");
+ assertEquals(Long.TYPE, clazz, "longProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "mappedProperty");
+ assertEquals(String.class, clazz, "mappedProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "mappedIntProperty");
+ assertEquals(Integer.TYPE, clazz, "mappedIntProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "readOnlyProperty");
+ assertEquals(String.class, clazz, "readOnlyProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "shortProperty");
+ assertEquals(Short.TYPE, clazz, "shortProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "stringArray");
+ assertEquals(stringArray.getClass(), clazz, "stringArray type");
+ clazz = PropertyUtils.getPropertyType(bean, "stringIndexed");
+ assertEquals(String.class, clazz, "stringIndexed type");
+ clazz = PropertyUtils.getPropertyType(bean, "stringProperty");
+ assertEquals(String.class, clazz, "stringProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "writeOnlyProperty");
+ assertEquals(String.class, clazz, "writeOnlyProperty type");
+
+ // Nested Properties
+ clazz = PropertyUtils.getPropertyType(bean, "nested.booleanProperty");
+ assertEquals(Boolean.TYPE, clazz, "booleanProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.booleanSecond");
+ assertEquals(Boolean.TYPE, clazz, "booleanSecond type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.doubleProperty");
+ assertEquals(Double.TYPE, clazz, "doubleProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.dupProperty");
+ assertEquals(String.class, clazz, "dupProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.floatProperty");
+ assertEquals(Float.TYPE, clazz, "floatProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.intArray");
+ assertEquals(intArray.getClass(), clazz, "intArray type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.intIndexed");
+ assertEquals(Integer.TYPE, clazz, "intIndexed type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.intProperty");
+ assertEquals(Integer.TYPE, clazz, "intProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.listIndexed");
+ assertEquals(List.class, clazz, "listIndexed type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.longProperty");
+ assertEquals(Long.TYPE, clazz, "longProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.mappedProperty");
+ assertEquals(String.class, clazz, "mappedProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.mappedIntProperty");
+ assertEquals(Integer.TYPE, clazz, "mappedIntProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.readOnlyProperty");
+ assertEquals(String.class, clazz, "readOnlyProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.shortProperty");
+ assertEquals(Short.TYPE, clazz, "shortProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.stringArray");
+ assertEquals(stringArray.getClass(), clazz, "stringArray type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.stringIndexed");
+ assertEquals(String.class, clazz, "stringIndexed type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.stringProperty");
+ assertEquals(String.class, clazz, "stringProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nested.writeOnlyProperty");
+ assertEquals(String.class, clazz, "writeOnlyProperty type");
+
+ // Nested DynaBean
+ clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean");
+ assertEquals(DynaBean.class, clazz, "nestedDynaBean type");
+ clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.stringProperty");
+ assertEquals(String.class, clazz, "nestedDynaBean.stringProperty type");
+ clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nestedBean");
+ assertEquals(TestBean.class, clazz, "nestedDynaBean.nestedBean type");
+ clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nestedBean.nestedDynaBean");
+ assertEquals(DynaBean.class, clazz, "nestedDynaBean.nestedBean.nestedDynaBean type");
+ clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nestedBean.nestedDynaBean.stringProperty");
+ assertEquals(String.class, clazz, "nestedDynaBean.nestedBean.nestedDynaBean.stringPropert type");
+
+ // test Null
+ clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nullDynaBean");
+ assertEquals(DynaBean.class, clazz, "nestedDynaBean.nullDynaBean type");
+ try {
+ clazz = PropertyUtils.getPropertyType(bean, "nestedDynaBean.nullDynaBean.foo");
+ fail("Expected NestedNullException for nestedDynaBean.nullDynaBean.foo");
+ } catch (final NestedNullException e) {
+ // expected
}
-
}
/**
@@ -1614,7 +1475,6 @@ public class PropertyUtilsTestCase {
*/
@Test
public void testGetReadMethodBasic() {
-
testGetReadMethod(bean, properties, TEST_BEAN_CLASS);
}
@@ -1624,7 +1484,6 @@ public class PropertyUtilsTestCase {
*/
@Test
public void testGetReadMethodPackageSubclass() {
-
testGetReadMethod(beanPackageSubclass, properties, TEST_BEAN_CLASS);
}
@@ -1675,9 +1534,7 @@ public class PropertyUtilsTestCase {
*/
@Test
public void testGetReadMethodPublicSubclass() {
-
testGetReadMethod(beanPublicSubclass, properties, TEST_BEAN_CLASS);
-
}
/** Text case for setting properties on inner classes */
@@ -1720,272 +1577,141 @@ public class PropertyUtilsTestCase {
* Test getSimpleProperty on a boolean property.
*/
@Test
- public void testGetSimpleBoolean() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "booleanProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Boolean.class, value, "Got correct type");
- assertEquals(((Boolean) value).booleanValue(), bean.getBooleanProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleBoolean() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "booleanProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Boolean.class, value, "Got correct type");
+ assertEquals(((Boolean) value).booleanValue(), bean.getBooleanProperty(), "Got correct value");
}
/**
* Test getSimpleProperty on a double property.
*/
@Test
- public void testGetSimpleDouble() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "doubleProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Double.class, value, "Got correct type");
- assertEquals(((Double) value).doubleValue(), bean.getDoubleProperty(), 0.005,
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleDouble() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "doubleProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Double.class, value, "Got correct type");
+ assertEquals(((Double) value).doubleValue(), bean.getDoubleProperty(), 0.005, "Got correct value");
}
/**
* Test getSimpleProperty on a float property.
*/
@Test
- public void testGetSimpleFloat() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "floatProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Float.class, value, "Got correct type");
- assertEquals(((Float) value).floatValue(), bean.getFloatProperty(), (float) 0.005,
- "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleFloat() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "floatProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Float.class, value, "Got correct type");
+ assertEquals(((Float) value).floatValue(), bean.getFloatProperty(), (float) 0.005, "Got correct value");
}
/**
* Negative test getSimpleProperty on an indexed property.
*/
@Test
- public void testGetSimpleIndexed() {
-
+ public void testGetSimpleIndexed() throws Exception {
try {
PropertyUtils.getSimpleProperty(bean, "intIndexed[0]");
fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
} catch (final IllegalArgumentException e) {
// Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
}
-
}
/**
* Test getSimpleProperty on an int property.
*/
@Test
- public void testGetSimpleInt() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "intProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Integer.class, value, "Got correct type");
- assertEquals(((Integer) value).intValue(), bean.getIntProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleInt() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "intProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Integer.class, value, "Got correct type");
+ assertEquals(((Integer) value).intValue(), bean.getIntProperty(), "Got correct value");
}
/**
* Test getSimpleProperty on a long property.
*/
@Test
- public void testGetSimpleLong() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "longProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Long.class, value, "Got correct type");
- assertEquals(((Long) value).longValue(), bean.getLongProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleLong() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "longProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Long.class, value, "Got correct type");
+ assertEquals(((Long) value).longValue(), bean.getLongProperty(), "Got correct value");
}
/**
* Negative test getSimpleProperty on a nested property.
*/
@Test
- public void testGetSimpleNested() {
-
+ public void testGetSimpleNested() throws Exception {
try {
PropertyUtils.getSimpleProperty(bean, "nested.stringProperty");
fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
} catch (final IllegalArgumentException e) {
// Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
}
-
}
/**
* Test getSimpleProperty on a read-only String property.
*/
@Test
- public void testGetSimpleReadOnly() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "readOnlyProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(String.class, value, "Got correct type");
- assertEquals((String) value, bean.getReadOnlyProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleReadOnly() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "readOnlyProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(String.class, value, "Got correct type");
+ assertEquals((String) value, bean.getReadOnlyProperty(), "Got correct value");
}
/**
* Test getSimpleProperty on a short property.
*/
@Test
- public void testGetSimpleShort() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "shortProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(Short.class, value, "Got correct type");
- assertEquals(((Short) value).shortValue(), bean.getShortProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleShort() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "shortProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(Short.class, value, "Got correct type");
+ assertEquals(((Short) value).shortValue(), bean.getShortProperty(), "Got correct value");
}
/**
* Test getSimpleProperty on a String property.
*/
@Test
- public void testGetSimpleString() {
-
- try {
- final Object value = PropertyUtils.getSimpleProperty(bean, "stringProperty");
- assertNotNull(value, "Got a value");
- assertInstanceOf(String.class, value, "Got correct type");
- assertEquals((String) value, bean.getStringProperty(), "Got correct value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testGetSimpleString() throws Exception {
+ final Object value = PropertyUtils.getSimpleProperty(bean, "stringProperty");
+ assertNotNull(value, "Got a value");
+ assertInstanceOf(String.class, value, "Got correct type");
+ assertEquals((String) value, bean.getStringProperty(), "Got correct value");
}
/**
* Negative test getSimpleProperty on an unknown property.
*/
@Test
- public void testGetSimpleUnknown() {
-
+ public void testGetSimpleUnknown() throws Exception {
try {
PropertyUtils.getSimpleProperty(bean, "unknown");
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
assertEquals("Unknown property 'unknown' on class '" + bean.getClass() + "'", e.getMessage());
}
-
}
/**
* Test getSimpleProperty on a write-only String property.
*/
@Test
- public void testGetSimpleWriteOnly() {
-
+ public void testGetSimpleWriteOnly() throws Exception {
try {
PropertyUtils.getSimpleProperty(bean, "writeOnlyProperty");
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
- assertEquals(
- "Property 'writeOnlyProperty' has no getter method in class '" + bean.getClass() + "'",
- e.getMessage());
+ assertEquals("Property 'writeOnlyProperty' has no getter method in class '" + bean.getClass() + "'", e.getMessage());
}
}
@@ -2043,9 +1769,7 @@ public class PropertyUtilsTestCase {
*/
@Test
public void testGetWriteMethodBasic() {
-
testGetWriteMethod(bean, properties, TEST_BEAN_CLASS);
-
}
/**
@@ -2053,9 +1777,7 @@ public class PropertyUtilsTestCase {
*/
@Test
public void testGetWriteMethodPackageSubclass() {
-
testGetWriteMethod(beanPackageSubclass, properties, TEST_BEAN_CLASS);
-
}
/**
@@ -2063,9 +1785,7 @@ public class PropertyUtilsTestCase {
*/
@Test
public void testGetWriteMethodPublicSubclass() {
-
testGetWriteMethod(beanPublicSubclass, properties, TEST_BEAN_CLASS);
-
}
/**
@@ -2076,78 +1796,68 @@ public class PropertyUtilsTestCase {
String property = null;
try {
property = "stringProperty";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "stringIndexed";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "mappedProperty";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "nestedDynaBean";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "nestedDynaBean.stringProperty";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nestedBean";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nestedBean.nestedDynaBean";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nestedBean.nestedDynaBean.stringProperty";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nullDynaBean";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isReadable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nullDynaBean.foo";
- assertTrue(PropertyUtils.isReadable(bean, property),
- "Property " + property + " isReadable expected TRUE");
+ assertTrue(PropertyUtils.isReadable(bean, property), "Property " + property + " isReadable expected TRUE");
fail("Property " + property + " isReadable expected NestedNullException");
} catch (final NestedNullException e) {
// expected result
@@ -2164,38 +1874,33 @@ public class PropertyUtilsTestCase {
String property = null;
try {
property = "stringProperty";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "stringIndexed";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "mappedProperty";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "nestedDynaBean";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "nestedDynaBean.stringProperty";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
t.printStackTrace();
fail("Property " + property + " isWriteable Threw exception: " + t);
@@ -2203,40 +1908,35 @@ public class PropertyUtilsTestCase {
try {
property = "nestedDynaBean.nestedBean";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nestedBean.nestedDynaBean";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nestedBean.nestedDynaBean.stringProperty";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nullDynaBean";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
} catch (final Throwable t) {
fail("Property " + property + " isWriteable Threw exception: " + t);
}
try {
property = "nestedDynaBean.nullDynaBean.foo";
- assertTrue(PropertyUtils.isWriteable(bean, property),
- "Property " + property + " isWriteable expected TRUE");
+ assertTrue(PropertyUtils.isWriteable(bean, property), "Property " + property + " isWriteable expected TRUE");
fail("Property " + property + " isWriteable expected NestedNullException");
} catch (final NestedNullException e) {
// expected result
@@ -2266,14 +1966,12 @@ public class PropertyUtilsTestCase {
// getNestedProperty with getter should obtain the simple property
utilsBean.setProperty(bean, "unusuallyNamedProperty", "next value");
assertEquals("next value", bean.getUnusuallyNamedProperty(), "Set property on map failed (2)");
- assertEquals("next value", utilsBean.getNestedProperty(bean, "unusuallyNamedProperty"),
- "setNestedProperty on non-simple property failed");
+ assertEquals("next value", utilsBean.getNestedProperty(bean, "unusuallyNamedProperty"), "setNestedProperty on non-simple property failed");
// setting property without setter should update the map
// getting property without setter should fetch from the map
utilsBean.setProperty(bean, "mapProperty", "value1");
- assertEquals("value1", utilsBean.getNestedProperty(bean, "mapProperty"),
- "setNestedProperty on non-simple property failed");
+ assertEquals("value1", utilsBean.getNestedProperty(bean, "mapProperty"), "setNestedProperty on non-simple property failed");
final HashMap<String, Object> myMap = new HashMap<>();
myMap.put("thebean", bean);
@@ -2294,23 +1992,20 @@ public class PropertyUtilsTestCase {
// setting property direct should work, and not affect map
bean.setUnusuallyNamedProperty("bean value");
assertEquals("bean value", bean.getUnusuallyNamedProperty(), "Set property direct failed");
- assertNull(PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"),
- "Get on unset map property failed");
+ assertNull(PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"), "Get on unset map property failed");
// setting simple property should call the setter method only, and not
// affect the map.
PropertyUtils.setSimpleProperty(bean, "unusuallyNamedProperty", "new value");
assertEquals("new value", bean.getUnusuallyNamedProperty(), "Set property on map failed (1)");
- assertNull(PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"),
- "Get on unset map property failed");
+ assertNull(PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"), "Get on unset map property failed");
// setting via setNestedProperty should affect the map only, and not
// call the setter method.
PropertyUtils.setProperty(bean, "unusuallyNamedProperty", "next value");
assertEquals("next value", PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"),
- "setNestedProperty on map not visible to getNestedProperty");
- assertEquals("new value", bean.getUnusuallyNamedProperty(),
- "Set nested property on map unexpected affected simple property");
+ "setNestedProperty on map not visible to getNestedProperty");
+ assertEquals("new value", bean.getUnusuallyNamedProperty(), "Set nested property on map unexpected affected simple property");
}
/**
@@ -3034,230 +2729,118 @@ public class PropertyUtilsTestCase {
* Test setNextedProperty on a boolean property.
*/
@Test
- public void testSetNestedBoolean() {
-
- try {
- final boolean oldValue = bean.getNested().getBooleanProperty();
- final boolean newValue = !oldValue;
- PropertyUtils.setNestedProperty(bean, "nested.booleanProperty", Boolean.valueOf(newValue));
- assertEquals(newValue, bean.getNested().getBooleanProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedBoolean() throws Exception {
+ final boolean oldValue = bean.getNested().getBooleanProperty();
+ final boolean newValue = !oldValue;
+ PropertyUtils.setNestedProperty(bean, "nested.booleanProperty", Boolean.valueOf(newValue));
+ assertEquals(newValue, bean.getNested().getBooleanProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a double property.
*/
@Test
- public void testSetNestedDouble() {
-
- try {
- final double oldValue = bean.getNested().getDoubleProperty();
- final double newValue = oldValue + 1.0;
- PropertyUtils.setNestedProperty(bean, "nested.doubleProperty", Double.valueOf(newValue));
- assertEquals(newValue, bean.getNested().getDoubleProperty(), 0.005, "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedDouble() throws Exception {
+ final double oldValue = bean.getNested().getDoubleProperty();
+ final double newValue = oldValue + 1.0;
+ PropertyUtils.setNestedProperty(bean, "nested.doubleProperty", Double.valueOf(newValue));
+ assertEquals(newValue, bean.getNested().getDoubleProperty(), 0.005, "Matched new value");
}
/**
* Test setNestedProperty on a float property.
*/
@Test
- public void testSetNestedFloat() {
-
- try {
- final float oldValue = bean.getNested().getFloatProperty();
- final float newValue = oldValue + (float) 1.0;
- PropertyUtils.setNestedProperty(bean, "nested.floatProperty", Float.valueOf(newValue));
- assertEquals(newValue, bean.getNested().getFloatProperty(), (float) 0.005, "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedFloat() throws Exception {
+ final float oldValue = bean.getNested().getFloatProperty();
+ final float newValue = oldValue + (float) 1.0;
+ PropertyUtils.setNestedProperty(bean, "nested.floatProperty", Float.valueOf(newValue));
+ assertEquals(newValue, bean.getNested().getFloatProperty(), (float) 0.005, "Matched new value");
}
/**
* Test setNestedProperty on a int property.
*/
@Test
- public void testSetNestedInt() {
-
- try {
- final int oldValue = bean.getNested().getIntProperty();
- final int newValue = oldValue + 1;
- PropertyUtils.setNestedProperty(bean, "nested.intProperty", Integer.valueOf(newValue));
- assertEquals(newValue, bean.getNested().getIntProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedInt() throws Exception {
+ final int oldValue = bean.getNested().getIntProperty();
+ final int newValue = oldValue + 1;
+ PropertyUtils.setNestedProperty(bean, "nested.intProperty", Integer.valueOf(newValue));
+ assertEquals(newValue, bean.getNested().getIntProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a long property.
*/
@Test
- public void testSetNestedLong() {
-
- try {
- final long oldValue = bean.getNested().getLongProperty();
- final long newValue = oldValue + 1;
- PropertyUtils.setNestedProperty(bean, "nested.longProperty", Long.valueOf(newValue));
- assertEquals(newValue, bean.getNested().getLongProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedLong() throws Exception {
+ final long oldValue = bean.getNested().getLongProperty();
+ final long newValue = oldValue + 1;
+ PropertyUtils.setNestedProperty(bean, "nested.longProperty", Long.valueOf(newValue));
+ assertEquals(newValue, bean.getNested().getLongProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a read-only String property.
*/
@Test
- public void testSetNestedReadOnly() {
-
+ public void testSetNestedReadOnly() throws Exception {
try {
final String oldValue = bean.getNested().getWriteOnlyPropertyValue();
final String newValue = oldValue + " Extra Value";
PropertyUtils.setNestedProperty(bean, "nested.readOnlyProperty", newValue);
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
}
-
}
/**
* Test setNestedProperty on a short property.
*/
@Test
- public void testSetNestedShort() {
-
- try {
- final short oldValue = bean.getNested().getShortProperty();
- short newValue = oldValue;
- newValue++;
- PropertyUtils.setNestedProperty(bean, "nested.shortProperty", Short.valueOf(newValue));
- assertEquals(newValue, bean.getNested().getShortProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedShort() throws Exception {
+ final short oldValue = bean.getNested().getShortProperty();
+ short newValue = oldValue;
+ newValue++;
+ PropertyUtils.setNestedProperty(bean, "nested.shortProperty", Short.valueOf(newValue));
+ assertEquals(newValue, bean.getNested().getShortProperty(), "Matched new value");
}
/**
* Test setNestedProperty on a String property.
*/
@Test
- public void testSetNestedString() {
-
- try {
- final String oldValue = bean.getNested().getStringProperty();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setNestedProperty(bean, "nested.stringProperty", newValue);
- assertEquals(newValue, bean.getNested().getStringProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedString() throws Exception {
+ final String oldValue = bean.getNested().getStringProperty();
+ final String newValue = oldValue + " Extra Value";
+ PropertyUtils.setNestedProperty(bean, "nested.stringProperty", newValue);
+ assertEquals(newValue, bean.getNested().getStringProperty(), "Matched new value");
}
/**
* Test setNestedProperty on an unknown property name.
*/
@Test
- public void testSetNestedUnknown() {
-
+ public void testSetNestedUnknown() throws Exception {
try {
final String newValue = "New String Value";
PropertyUtils.setNestedProperty(bean, "nested.unknown", newValue);
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
}
-
}
/**
* Test setNestedProperty on a write-only String property.
*/
@Test
- public void testSetNestedWriteOnly() {
-
- try {
- final String oldValue = bean.getNested().getWriteOnlyPropertyValue();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setNestedProperty(bean, "nested.writeOnlyProperty", newValue);
- assertEquals(newValue, bean.getNested().getWriteOnlyPropertyValue(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetNestedWriteOnly() throws Exception {
+ final String oldValue = bean.getNested().getWriteOnlyPropertyValue();
+ final String newValue = oldValue + " Extra Value";
+ PropertyUtils.setNestedProperty(bean, "nested.writeOnlyProperty", newValue);
+ assertEquals(newValue, bean.getNested().getWriteOnlyPropertyValue(), "Matched new value");
}
@Test
@@ -3321,248 +2904,133 @@ public class PropertyUtilsTestCase {
* Test setSimpleProperty on a boolean property.
*/
@Test
- public void testSetSimpleBoolean() {
-
- try {
- final boolean oldValue = bean.getBooleanProperty();
- final boolean newValue = !oldValue;
- PropertyUtils.setSimpleProperty(bean, "booleanProperty", Boolean.valueOf(newValue));
- assertEquals(newValue, bean.getBooleanProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleBoolean() throws Exception {
+ final boolean oldValue = bean.getBooleanProperty();
+ final boolean newValue = !oldValue;
+ PropertyUtils.setSimpleProperty(bean, "booleanProperty", Boolean.valueOf(newValue));
+ assertEquals(newValue, bean.getBooleanProperty(), "Matched new value");
}
/**
* Test setSimpleProperty on a double property.
*/
@Test
- public void testSetSimpleDouble() {
-
- try {
- final double oldValue = bean.getDoubleProperty();
- final double newValue = oldValue + 1.0;
- PropertyUtils.setSimpleProperty(bean, "doubleProperty", Double.valueOf(newValue));
- assertEquals(newValue, bean.getDoubleProperty(), 0.005, "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleDouble() throws Exception {
+ final double oldValue = bean.getDoubleProperty();
+ final double newValue = oldValue + 1.0;
+ PropertyUtils.setSimpleProperty(bean, "doubleProperty", Double.valueOf(newValue));
+ assertEquals(newValue, bean.getDoubleProperty(), 0.005, "Matched new value");
}
/**
* Test setSimpleProperty on a float property.
*/
@Test
- public void testSetSimpleFloat() {
-
- try {
- final float oldValue = bean.getFloatProperty();
- final float newValue = oldValue + (float) 1.0;
- PropertyUtils.setSimpleProperty(bean, "floatProperty", Float.valueOf(newValue));
- assertEquals(newValue, bean.getFloatProperty(), (float) 0.005, "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleFloat() throws Exception {
+ final float oldValue = bean.getFloatProperty();
+ final float newValue = oldValue + (float) 1.0;
+ PropertyUtils.setSimpleProperty(bean, "floatProperty", Float.valueOf(newValue));
+ assertEquals(newValue, bean.getFloatProperty(), (float) 0.005, "Matched new value");
}
/**
* Negative test setSimpleProperty on an indexed property.
*/
@Test
- public void testSetSimpleIndexed() {
-
+ public void testSetSimpleIndexed() throws Exception {
try {
PropertyUtils.setSimpleProperty(bean, "stringIndexed[0]", "New String Value");
fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
} catch (final IllegalArgumentException e) {
// Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
}
-
}
/**
* Test setSimpleProperty on a int property.
*/
@Test
- public void testSetSimpleInt() {
-
- try {
- final int oldValue = bean.getIntProperty();
- final int newValue = oldValue + 1;
- PropertyUtils.setSimpleProperty(bean, "intProperty", Integer.valueOf(newValue));
- assertEquals(newValue, bean.getIntProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleInt() throws Exception {
+ final int oldValue = bean.getIntProperty();
+ final int newValue = oldValue + 1;
+ PropertyUtils.setSimpleProperty(bean, "intProperty", Integer.valueOf(newValue));
+ assertEquals(newValue, bean.getIntProperty(), "Matched new value");
}
/**
* Test setSimpleProperty on a long property.
*/
@Test
- public void testSetSimpleLong() {
-
- try {
- final long oldValue = bean.getLongProperty();
- final long newValue = oldValue + 1;
- PropertyUtils.setSimpleProperty(bean, "longProperty", Long.valueOf(newValue));
- assertEquals(newValue, bean.getLongProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleLong() throws Exception {
+ final long oldValue = bean.getLongProperty();
+ final long newValue = oldValue + 1;
+ PropertyUtils.setSimpleProperty(bean, "longProperty", Long.valueOf(newValue));
+ assertEquals(newValue, bean.getLongProperty(), "Matched new value");
}
/**
* Negative test setSimpleProperty on a nested property.
*/
@Test
- public void testSetSimpleNested() {
-
+ public void testSetSimpleNested() throws Exception {
try {
PropertyUtils.setSimpleProperty(bean, "nested.stringProperty", "New String Value");
fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
} catch (final IllegalArgumentException e) {
// Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
}
-
}
/**
* Test setSimpleProperty on a read-only String property.
*/
@Test
- public void testSetSimpleReadOnly() {
-
+ public void testSetSimpleReadOnly() throws Exception {
try {
final String oldValue = bean.getWriteOnlyPropertyValue();
final String newValue = oldValue + " Extra Value";
PropertyUtils.setSimpleProperty(bean, "readOnlyProperty", newValue);
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
assertEquals(
"Property 'readOnlyProperty' has no setter method in class '" + bean.getClass() + "'",
e.getMessage());
}
-
}
/**
* Test setSimpleProperty on a short property.
*/
@Test
- public void testSetSimpleShort() {
-
- try {
- final short oldValue = bean.getShortProperty();
- short newValue = oldValue;
- newValue++;
- PropertyUtils.setSimpleProperty(bean, "shortProperty", Short.valueOf(newValue));
- assertEquals(newValue, bean.getShortProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleShort() throws Exception {
+ final short oldValue = bean.getShortProperty();
+ short newValue = oldValue;
+ newValue++;
+ PropertyUtils.setSimpleProperty(bean, "shortProperty", Short.valueOf(newValue));
+ assertEquals(newValue, bean.getShortProperty(), "Matched new value");
}
/**
* Test setSimpleProperty on a String property.
*/
@Test
- public void testSetSimpleString() {
-
- try {
- final String oldValue = bean.getStringProperty();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setSimpleProperty(bean, "stringProperty", newValue);
- assertEquals(newValue, bean.getStringProperty(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleString() throws Exception {
+ final String oldValue = bean.getStringProperty();
+ final String newValue = oldValue + " Extra Value";
+ PropertyUtils.setSimpleProperty(bean, "stringProperty", newValue);
+ assertEquals(newValue, bean.getStringProperty(), "Matched new value");
}
/**
* Test setSimpleProperty on an unknown property name.
*/
@Test
- public void testSetSimpleUnknown() {
-
+ public void testSetSimpleUnknown() throws Exception {
try {
final String newValue = "New String Value";
PropertyUtils.setSimpleProperty(bean, "unknown", newValue);
fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
} catch (final NoSuchMethodException e) {
// Correct result for this test
assertEquals("Unknown property 'unknown' on class '" + bean.getClass() + "'", e.getMessage());
@@ -3574,23 +3042,11 @@ public class PropertyUtilsTestCase {
* Test setSimpleProperty on a write-only String property.
*/
@Test
- public void testSetSimpleWriteOnly() {
-
- try {
- final String oldValue = bean.getWriteOnlyPropertyValue();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setSimpleProperty(bean, "writeOnlyProperty", newValue);
- assertEquals(newValue, bean.getWriteOnlyPropertyValue(), "Matched new value");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
+ public void testSetSimpleWriteOnly() throws Exception {
+ final String oldValue = bean.getWriteOnlyPropertyValue();
+ final String newValue = oldValue + " Extra Value";
+ PropertyUtils.setSimpleProperty(bean, "writeOnlyProperty", newValue);
+ assertEquals(newValue, bean.getWriteOnlyPropertyValue(), "Matched new value");
}
/**