You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/02/01 08:07:51 UTC
svn commit: r1238953 - in /commons/sandbox/beanutils2/trunk/src:
changes/changes.xml
test/java/org/apache/commons/beanutils2/StaticMethodsTestCase.java
Author: simonetripodi
Date: Wed Feb 1 07:07:50 2012
New Revision: 1238953
URL: http://svn.apache.org/viewvc?rev=1238953&view=rev
Log:
[SANDBOX-378] Extend StaticMethodsTestCase - patch provided by Benedikt Ritter
Modified:
commons/sandbox/beanutils2/trunk/src/changes/changes.xml
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/StaticMethodsTestCase.java
Modified: commons/sandbox/beanutils2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/changes/changes.xml?rev=1238953&r1=1238952&r2=1238953&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/beanutils2/trunk/src/changes/changes.xml Wed Feb 1 07:07:50 2012
@@ -23,6 +23,9 @@
</properties>
<body>
<release version="0.1" date="201?-??-??" description="First release.">
+ <action dev="simonetripodi" type="update" issue="SANDBOX-378" due-to="Benedikt Ritter">
+ Extend StaticMethodsTestCase
+ </action>
<action dev="simonetripodi" type="update" issue="SANDBOX-377" due-to="Benedikt Ritter">
Implement invoke(Exact)Method(...) on DefaultBeanAccessor
</action>
Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/StaticMethodsTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/StaticMethodsTestCase.java?rev=1238953&r1=1238952&r2=1238953&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/StaticMethodsTestCase.java (original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/StaticMethodsTestCase.java Wed Feb 1 07:07:50 2012
@@ -23,39 +23,124 @@ import static org.apache.commons.beanuti
import static org.apache.commons.beanutils2.BeanUtils.on;
import static org.junit.Assert.assertEquals;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public final class StaticMethodsTestCase
{
+ private int oldValue;
- @Test
- public void invokeStaticMethod()
- throws Exception
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Before
+ public void setUp()
{
+ oldValue = TestBean.currentCounter();
+ }
- Object value = null;
- int current = TestBean.currentCounter();
+ @After
+ public void tearDown()
+ {
+ oldValue = 0;
+ }
- value = on( TestBean.class ).invokeStaticMethod( "currentCounter" ).withArguments().get();
- assertEquals( "currentCounter value", current, ( (Integer) value ).intValue() );
+ @Test
+ public void invokeStaticMethodCurrentCounter()
+ throws Exception
+ {
+ Object value = on( TestBean.class ).invokeStaticMethod( "currentCounter" ).withArguments().get();
+ assertEquals( "currentCounter value", oldValue, ( (Integer) value ).intValue() );
+ }
+ @Test
+ public void invokeStaticMethodIncrementCounter()
+ throws Exception
+ {
on( TestBean.class ).invokeStaticMethod( "incrementCounter" ).withArguments();
- current++;
+ assertEquals( oldValue + 1, TestBean.currentCounter() );
+ }
- value = on( TestBean.class ).invokeStaticMethod( "currentCounter" ).withArguments().get();
- assertEquals( "currentCounter value", current, ( (Integer) value ).intValue() );
+ @Test
+ public void invokeStaticMethodIncrementCounterIntegerPrimitive()
+ throws Exception
+ {
+ on( TestBean.class ).invokeStaticMethod( "incrementCounter" ).withArguments( argument( 8 ) ).get();
+ assertEquals( oldValue + 8, TestBean.currentCounter() );
+ }
+ @Test
+ public void invokeStaticMethodIncrementCounterIntegerWrapper()
+ throws Exception
+ {
on( TestBean.class ).invokeStaticMethod( "incrementCounter" ).withArguments( argument( new Integer( 8 ) ) ).get();
- current += 8;
+ assertEquals( oldValue + 8, TestBean.currentCounter() );
+ }
- value = on( TestBean.class ).invokeStaticMethod( "currentCounter" ).withArguments().get();
- assertEquals( "currentCounter value", current, ( (Integer) value ).intValue() );
+ @Test
+ public void invokeStaticMethodIncrementCounterIntegerWrapperAsPrimitive()
+ throws Exception
+ {
+ on( TestBean.class ).invokeStaticMethod( "incrementCounter" ).withArguments( argument( int.class,
+ new Integer( 8 ) ) ).get();
+ assertEquals( oldValue + 8, TestBean.currentCounter() );
+ }
- on( TestBean.class ).invokeStaticMethod( "incrementCounter" ).withArguments( argument( Number.class, new Integer( 8 ) ) ).get();
- current += 16;
+ @Test
+ public void invokeStaticMethodIncrementCounterNumberInteger()
+ throws Exception
+ {
+ on( TestBean.class ).invokeStaticMethod( "incrementCounter" ).withArguments( argument( Number.class,
+ new Integer( 8 ) ) ).get();
+ // incrementCounter(Number) will multiply its input with 2
+ assertEquals( oldValue + 8 * 2, TestBean.currentCounter() );
+ }
+
+ @Test
+ public void invokeStaticMethodWithInvalidArgument()
+ throws Exception
+ {
+ String methodName = "incrementCounter";
+ thrown.expect( NoSuchMethodException.class );
+ thrown.expectMessage( "No such accessible method:" );
+ thrown.expectMessage( methodName );
+ thrown.expectMessage( TestBean.class.getName() );
+ on( TestBean.class ).invokeStaticMethod( methodName ).withArguments( argument( 'x' ) );
+ }
+
+ @Test
+ public void invokeExactStaticMethodIncrementCounter() throws Exception
+ {
+ on( TestBean.class ).invokeExactStaticMethod( "incrementCounter" ).withArguments();
+ assertEquals( oldValue + 1, TestBean.currentCounter() );
+ }
- value = on( TestBean.class ).invokeStaticMethod( "currentCounter" ).withArguments().get();
- assertEquals( "currentCounter value", current, ( (Integer) value ).intValue() );
+ @Test
+ public void invokeExactStaticMethodIncrementIntegerPrimitive()
+ throws Exception
+ {
+ on( TestBean.class ).invokeExactStaticMethod( "incrementCounter" ).withArguments( argument( int.class, 8 ) ).get();
+ assertEquals( oldValue + 8, TestBean.currentCounter() );
+ }
+
+ @Test( expected = NoSuchMethodException.class )
+ public void invokeExactStaticMethodIncrementIntegerWrapper()
+ throws Exception
+ {
+ on( TestBean.class ).invokeExactStaticMethod( "incrementCounter" ).withArguments( argument( new Integer( 8 ) ) ).get();
+ }
+
+ @Test
+ public void invokeExactStaticMethodIncrementNumberInteger()
+ throws Exception
+ {
+ on( TestBean.class ).invokeExactStaticMethod( "incrementCounter" ).withArguments( argument( Number.class,
+ new Integer( 8 ) ) ).get();
+ // incrementCounter(Number) will multiply its input with 2
+ assertEquals( oldValue + 2 * 8, TestBean.currentCounter() );
}
}