Author: niallp Date: Mon May 21 17:23:27 2007 New Revision: 540380 URL: http://svn.apache.org/viewvc?view=rev&rev=540380 Log: BEANUTILS-266 - add a test case to check that PropertyUtilsBean's invoke method is correctly initializing the cause on JDK 1.4+
Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java?view=diff&rev=540380&r1=540379&r2=540380 ============================================================================== --- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java (original) +++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java Mon May 21 17:23:27 2007 @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.StringTokenizer; import org.apache.commons.beanutils.priv.PrivateBeanFactory; import org.apache.commons.beanutils.priv.PrivateDirect; @@ -3825,5 +3826,43 @@ myMap.put("thebean", bean); utilsBean.getNestedProperty(myMap, "thebean.mapitem"); utilsBean.getNestedProperty(myMap, "thebean(mapitem)"); + } + + /** + * Test [EMAIL PROTECTED] PropertyUtilsBean}'s invoke method throwing an IllegalArgumentException + * and check that the "cause" has been properly initialized for JDK 1.4+ + * See BEANUTILS-266 for changes and reason for test + */ + public void testExceptionFromInvoke() throws Exception { + if (isPre14JVM()) { + return; + } + try { + PropertyUtils.setSimpleProperty(bean, "intProperty","XXX"); + } catch(IllegalArgumentException t) { + Throwable cause = (Throwable)PropertyUtils.getProperty(t, "cause"); + assertNotNull("Cause not found", cause); + assertTrue("Expected cause to be IllegalArgumentException, but was: " + cause.getClass(), + cause instanceof IllegalArgumentException); + assertEquals("Check error message", "argument type mismatch", cause.getMessage()); + } catch(Throwable t) { + fail("Expected IllegalArgumentException, but threw " + t); + } + } + + /** + * Test for JDK 1.4 + */ + private boolean isPre14JVM() { + String version = System.getProperty("java.specification.version"); + StringTokenizer tokenizer = new StringTokenizer(version,"."); + if (tokenizer.nextToken().equals("1")) { + String minorVersion = tokenizer.nextToken(); + if (minorVersion.equals("0")) return true; + if (minorVersion.equals("1")) return true; + if (minorVersion.equals("2")) return true; + if (minorVersion.equals("3")) return true; + } + return false; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]