commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1241155 - in /commons/sandbox/beanutils2/trunk/src: main/java/org/apache/commons/beanutils2/ test/java/org/apache/commons/beanutils2/
Date Mon, 06 Feb 2012 20:25:28 GMT
Author: simonetripodi
Date: Mon Feb  6 20:25:27 2012
New Revision: 1241155

URL: http://svn.apache.org/viewvc?rev=1241155&view=rev
Log:
started handling TypeLiteral instead of pure class 

Modified:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/StaticMethodsTestCase.java

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java?rev=1241155&r1=1241154&r2=1241155&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
Mon Feb  6 20:25:27 2012
@@ -21,6 +21,8 @@ package org.apache.commons.beanutils2;
 
 import static org.apache.commons.beanutils2.internal.Assertions.checkNotNull;
 
+import org.apache.commons.beanutils2.type.TypeLiteral;
+
 public final class BeanUtils
 {
 
@@ -35,7 +37,7 @@ public final class BeanUtils
 
     // introspection stuff
 
-    public static <B> ClassAccessor<B> on( Class<B> beanType )
+    public static <B> ClassAccessor<B> on( TypeLiteral<B> beanType )
     {
         beanType = checkNotNull( beanType, "No bean class specified" );
 

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java?rev=1241155&r1=1241154&r2=1241155&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java
Mon Feb  6 20:25:27 2012
@@ -26,6 +26,8 @@ import static org.apache.commons.beanuti
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 
+import org.apache.commons.beanutils2.type.TypeLiteral;
+
 final class DefaultClassAccessor<B>
     implements ClassAccessor<B>
 {
@@ -33,9 +35,9 @@ final class DefaultClassAccessor<B>
     private final AccessibleObjectsRegistry<Constructor<?>> constructorRegistry
=
                     AccessibleObjectsRegistry.getConstructorsRegistry();
 
-    private final Class<B> beanClass;
+    private final TypeLiteral<B> beanClass;
 
-    public DefaultClassAccessor( Class<B> beanClass )
+    public DefaultClassAccessor( TypeLiteral<B> beanClass )
     {
         this.beanClass = beanClass;
     }
@@ -48,7 +50,7 @@ final class DefaultClassAccessor<B>
     public BeanAccessor<B> newInstance()
         throws InstantiationException, IllegalAccessException
     {
-        B bean = beanClass.newInstance();
+        B bean = (B) beanClass.getRawType().newInstance();
         return new DefaultBeanAccessor<B>( bean );
     }
 
@@ -63,7 +65,7 @@ final class DefaultClassAccessor<B>
     {
         arguments = checkNotNull( arguments,
                                   "Null arguments not admitted - don't pass any argument
to use %s empty constructor",
-                                  beanClass.getName() );
+                                  beanClass );
         arguments = checkNoneIsNull( arguments );
         return invokeConstructor( false, arguments );
     }
@@ -77,7 +79,7 @@ final class DefaultClassAccessor<B>
     {
         arguments = checkNotNull( arguments,
                                   "Null arguments not admitted - don't pass any argument
to use %s empty constructor",
-                                  beanClass.getName() );
+                                  beanClass );
         arguments = checkNoneIsNull( arguments );
         return invokeConstructor( true, arguments );
     }
@@ -98,11 +100,13 @@ final class DefaultClassAccessor<B>
         NoSuchMethodException
     {
         @SuppressWarnings( "unchecked" ) // type driven by beanClass
-        Constructor<B> constructor = (Constructor<B>) constructorRegistry.get(
exact, beanClass, getParameterTypes( arguments ) );
+        Constructor<B> constructor = (Constructor<B>) constructorRegistry.get(
exact,
+                                                                               beanClass.getRawType(),
+                                                                               getParameterTypes(
arguments ) );
 
         if ( null == constructor )
         {
-            throw new NoSuchMethodException( "No such accessible constructor on class: "
+ beanClass.getName() );
+            throw new NoSuchMethodException( "No such accessible constructor on class: "
+ beanClass );
         }
 
         int argumentsLength = arguments.length;
@@ -123,8 +127,8 @@ final class DefaultClassAccessor<B>
      */
     public ArgumentsAccessor invokeStatic( String methodName )
     {
-        methodName = checkNotNull( methodName, "Impossible to execute null static method
in %s", beanClass.getName() );
-        return new DefaultArgumentsAccessor( beanClass, false, methodName, null );
+        methodName = checkNotNull( methodName, "Impossible to execute null static method
in %s", beanClass );
+        return new DefaultArgumentsAccessor( beanClass.getRawType(), false, methodName, null
);
     }
 
     /**
@@ -132,8 +136,8 @@ final class DefaultClassAccessor<B>
      */
     public ArgumentsAccessor invokeExactStatic( String methodName )
     {
-        methodName = checkNotNull( methodName, "Impossible to execute null static method
in %s", beanClass.getName() );
-        return new DefaultArgumentsAccessor( beanClass, true, methodName, null );
+        methodName = checkNotNull( methodName, "Impossible to execute null static method
in %s", beanClass );
+        return new DefaultArgumentsAccessor( beanClass.getRawType(), true, methodName, null
);
     }
 
 }

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java?rev=1241155&r1=1241154&r2=1241155&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassLoaderBuilder.java
Mon Feb  6 20:25:27 2012
@@ -21,6 +21,8 @@ package org.apache.commons.beanutils2;
 
 import static java.lang.Thread.currentThread;
 
+import org.apache.commons.beanutils2.type.TypeLiteral;
+
 import static org.apache.commons.beanutils2.internal.Assertions.checkNotNull;
 
 final class DefaultClassLoaderBuilder
@@ -63,7 +65,7 @@ final class DefaultClassLoaderBuilder
         Class<?> beanType = classLoader.loadClass( beanTypeName );
 
         @SuppressWarnings( { "rawtypes", "unchecked" } ) // ClassAccessor raw type is unknown
-        DefaultClassAccessor<?> accessor = new DefaultClassAccessor( beanType );
+        DefaultClassAccessor<?> accessor = new DefaultClassAccessor( TypeLiteral.get(beanType
) );
         return accessor;
     }
 

Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java?rev=1241155&r1=1241154&r2=1241155&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java
Mon Feb  6 20:25:27 2012
@@ -24,6 +24,7 @@ import static org.apache.commons.beanuti
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import org.apache.commons.beanutils2.type.TypeLiteral;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -45,12 +46,12 @@ public class ConstructorsTestCase
         throws Exception
     {
         {
-            TestBean obj = on( TestBean.class ).invokeConstructor( argument( "TEST" ) ).get();
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeConstructor( argument(
"TEST" ) ).get();
             assertNotNull( obj );
             assertEquals( "TEST", obj.getStringProperty() );
         }
         {
-            TestBean obj = on( TestBean.class ).invokeConstructor( argument( new Float( 17.3f
) ) ).get();
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeConstructor( argument(
new Float( 17.3f ) ) ).get();
             assertNotNull( obj );
             assertEquals( 17.3f, obj.getFloatProperty(), 0.0f );
         }
@@ -60,24 +61,26 @@ public class ConstructorsTestCase
     public void invokeConstructorWithInvalidArgument()
         throws Exception
     {
+        TypeLiteral<TestBean> testBeanLiteral = new TypeLiteral<TestBean>(){};
+
         thrown.expect( NoSuchMethodException.class );
         thrown.expectMessage( "No such accessible constructor on class:" );
-        thrown.expectMessage( TestBean.class.getName() );
-        on( TestBean.class ).invokeConstructor( argument( (byte) 6 ) ).get();
+        thrown.expectMessage( String.valueOf( testBeanLiteral ) );
+        on( testBeanLiteral ).invokeConstructor( argument( (byte) 6 ) ).get();
     }
 
     @Test( expected = NullPointerException.class )
     public void invokeConstructorWithNull()
         throws Exception
     {
-        on( TestBean.class ).invokeConstructor( (Argument<?>) null );
+        on( new TypeLiteral<TestBean>(){} ).invokeConstructor( (Argument<?>)
null );
     }
 
     @Test
     public void invokeConstructorWithArgArray()
         throws Exception
     {
-        TestBean obj = on( TestBean.class ).invokeConstructor( argument( new Float( 17.3f
) ), argument( "TEST" ) ).get();
+        TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeConstructor( argument(
new Float( 17.3f ) ), argument( "TEST" ) ).get();
         assertNotNull( obj );
         assertEquals( 17.3f, obj.getFloatProperty(), 0.0f );
         assertEquals( "TEST", obj.getStringProperty() );
@@ -87,17 +90,19 @@ public class ConstructorsTestCase
     public void invokeConstrucotrWithInvalidArgArray()
         throws Exception
     {
+        TypeLiteral<TestBean> testBeanLiteral = new TypeLiteral<TestBean>(){};
+
         thrown.expect( NoSuchMethodException.class );
         thrown.expectMessage( "No such accessible constructor on class:" );
-        thrown.expectMessage( TestBean.class.getName() );
-        on( TestBean.class ).invokeConstructor( argument( (byte) 17 ), argument( "TEST" )
).get();
+        thrown.expectMessage( String.valueOf( testBeanLiteral ) );
+        on( testBeanLiteral ).invokeConstructor( argument( (byte) 17 ), argument( "TEST"
) ).get();
     }
 
     @Test( expected = NullPointerException.class )
     public void invokeConstructorWithNullArray()
         throws Exception
     {
-        on( TestBean.class ).invokeConstructor( null, null, null );
+        on( new TypeLiteral<TestBean>(){} ).invokeConstructor( null, null, null );
     }
 
     @Test
@@ -105,14 +110,14 @@ public class ConstructorsTestCase
         throws Exception
     {
         {
-            TestBean obj = on( TestBean.class ).invokeConstructor( argument( Boolean.TYPE,
Boolean.TRUE ),
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeConstructor( argument(
Boolean.TYPE, Boolean.TRUE ),
                                                                    argument( String.class,
"TEST" ) ).get();
             assertNotNull( obj );
             assertEquals( true, obj.getBooleanProperty() );
             assertEquals( "TEST", obj.getStringProperty() );
         }
         {
-            TestBean obj = on( TestBean.class ).invokeConstructor( argument( Boolean.class,
Boolean.TRUE ),
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeConstructor( argument(
Boolean.class, Boolean.TRUE ),
                                                                    argument( String.class,
"TEST" ) ).get();
             assertNotNull( obj );
             assertEquals( true, obj.isBooleanSecond() );
@@ -123,11 +128,13 @@ public class ConstructorsTestCase
     @Test
     public void invokeConstructorWithInvalidTypeArray() throws Exception
     {
+        TypeLiteral<TestBean> testBeanLiteral = new TypeLiteral<TestBean>(){};
+
         thrown.expect( NoSuchMethodException.class );
         thrown.expectMessage( "No such accessible constructor on class:" );
-        thrown.expectMessage( TestBean.class.getName() );
-        on( TestBean.class ).invokeConstructor( argument( String.class, "TEST" ),
-                                                argument( Boolean.TYPE, Boolean.TRUE )).get();
+        thrown.expectMessage( String.valueOf( testBeanLiteral ) );
+        on( testBeanLiteral ).invokeConstructor( argument( String.class, "TEST" ),
+                                                 argument( Boolean.TYPE, Boolean.TRUE )).get();
     }
 
     @Test
@@ -135,12 +142,12 @@ public class ConstructorsTestCase
         throws Exception
     {
         {
-            TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( "TEST"
) ).get();
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor(
argument( "TEST" ) ).get();
             assertNotNull( obj );
             assertEquals( "TEST", obj.getStringProperty() );
         }
         {
-            TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Boolean.TRUE
) ).get();
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor(
argument( Boolean.TRUE ) ).get();
             assertNotNull( obj );
 
             assertEquals( true, obj.isBooleanSecond() );
@@ -151,25 +158,27 @@ public class ConstructorsTestCase
     public void invokeExactConstructorWithInvalidArgument()
         throws Exception
     {
+        TypeLiteral<TestBean> testBeanLiteral = new TypeLiteral<TestBean>(){};
+
         thrown.expect( NoSuchMethodException.class );
         thrown.expectMessage( "No such accessible constructor on class:" );
-        thrown.expectMessage( TestBean.class.getName() );
-        on( TestBean.class ).invokeExactConstructor( argument( new Float( 17.3f ) ) ).get();
+        thrown.expectMessage( String.valueOf( testBeanLiteral ) );
+        on( testBeanLiteral ).invokeExactConstructor( argument( new Float( 17.3f ) ) ).get();
     }
 
     @Test( expected = NullPointerException.class )
     public void invokeExactConstructorWithNull()
         throws Exception
     {
-        on( TestBean.class ).invokeExactConstructor( (Argument<?>) null );
+        on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor( (Argument<?>)
null );
     }
 
     @Test
     public void invokeExactConstructorWithArgArray()
         throws Exception
     {
-        TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Boolean.TRUE
),
-                                                                    argument( "TEST" ) ).get();
+        TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor(
argument( Boolean.TRUE ),
+                                                                                   argument(
"TEST" ) ).get();
         assertNotNull( obj );
         assertEquals( true, obj.isBooleanSecond() );
         assertEquals( "TEST", obj.getStringProperty() );
@@ -178,17 +187,19 @@ public class ConstructorsTestCase
     @Test
     public void invokeExactConstructorWithInvalidArgArray() throws Exception
     {
+        TypeLiteral<TestBean> testBeanLiteral = new TypeLiteral<TestBean>(){};
+
         thrown.expect( NoSuchMethodException.class );
         thrown.expectMessage( "No such accessible constructor on class:" );
-        thrown.expectMessage( TestBean.class.getName() );
-        on( TestBean.class ).invokeExactConstructor( argument( new Float( 17.3f ) ),argument(
"TEST" ) ).get();
+        thrown.expectMessage( String.valueOf( testBeanLiteral ) );
+        on( testBeanLiteral ).invokeExactConstructor( argument( new Float( 17.3f ) ),argument(
"TEST" ) ).get();
     }
 
     @Test( expected = NullPointerException.class )
     public void invokeExactConstructorWithNullArray()
         throws Exception
     {
-        on( TestBean.class ).invokeExactConstructor( null, null, null );
+        on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor( null, null, null
);
     }
 
     @Test
@@ -196,21 +207,21 @@ public class ConstructorsTestCase
         throws Exception
     {
         {
-            TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Boolean.TYPE,
Boolean.TRUE ),
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor(
argument( Boolean.TYPE, Boolean.TRUE ),
                                                                         argument( String.class,
"TEST" ) ).get();
             assertNotNull( obj );
             assertEquals( true, obj.getBooleanProperty() );
             assertEquals( "TEST", obj.getStringProperty() );
         }
         {
-            TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Boolean.class,
Boolean.TRUE ),
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor(
argument( Boolean.class, Boolean.TRUE ),
                                                                         argument( String.class,
"TEST" ) ).get();
             assertNotNull( obj );
             assertEquals( true, obj.isBooleanSecond() );
             assertEquals( "TEST", obj.getStringProperty() );
         }
         {
-            TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Float.TYPE,
new Float( 17.3f ) ),
+            TestBean obj = on( new TypeLiteral<TestBean>(){} ).invokeExactConstructor(
argument( Float.TYPE, new Float( 17.3f ) ),
                                                                         argument( String.class,
"TEST" ) ).get();
             assertNotNull( obj );
 
@@ -222,11 +233,13 @@ public class ConstructorsTestCase
     @Test
     public void invokeExactConstructorWithInvalidTypeArray() throws Exception
     {
+        TypeLiteral<TestBean> testBeanLiteral = new TypeLiteral<TestBean>(){};
+
         thrown.expect( NoSuchMethodException.class );
         thrown.expectMessage( "No such accessible constructor on class:" );
-        thrown.expectMessage( TestBean.class.getName() );
-        on( TestBean.class ).invokeExactConstructor( argument( Float.class, new Float( 17.3f
) ),
-                                                     argument( String.class, "TEST" ) ).get();
+        thrown.expectMessage( String.valueOf( testBeanLiteral ) );
+        on( testBeanLiteral ).invokeExactConstructor( argument( Float.class, new Float( 17.3f
) ),
+                                                      argument( String.class, "TEST" ) ).get();
     }
 
 }

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=1241155&r1=1241154&r2=1241155&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
Mon Feb  6 20:25:27 2012
@@ -23,6 +23,7 @@ import static org.apache.commons.beanuti
 import static org.apache.commons.beanutils2.BeanUtils.on;
 import static org.junit.Assert.assertEquals;
 
+import org.apache.commons.beanutils2.type.TypeLiteral;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -52,7 +53,7 @@ public final class StaticMethodsTestCase
     public void invokeStaticMethodCurrentCounter()
         throws Exception
     {
-        Object value = on( TestBean.class ).invokeStatic( "currentCounter" ).withArguments().get();
+        Object value = on( new TypeLiteral<TestBean>(){} ).invokeStatic( "currentCounter"
).withArguments().get();
         assertEquals( "currentCounter value", oldValue, ( (Integer) value ).intValue() );
     }
 
@@ -60,7 +61,7 @@ public final class StaticMethodsTestCase
     public void invokeStaticMethodIncrementCounter()
         throws Exception
     {
-        on( TestBean.class ).invokeStatic( "incrementCounter" ).withArguments();
+        on( new TypeLiteral<TestBean>(){} ).invokeStatic( "incrementCounter" ).withArguments();
         assertEquals( oldValue + 1, TestBean.currentCounter() );
     }
 
@@ -68,7 +69,7 @@ public final class StaticMethodsTestCase
     public void invokeStaticMethodIncrementCounterIntegerPrimitive()
         throws Exception
     {
-        on( TestBean.class ).invokeStatic( "incrementCounter" ).withArguments( argument(
8  ) ).get();
+        on( new TypeLiteral<TestBean>(){} ).invokeStatic( "incrementCounter" ).withArguments(
argument( 8  ) ).get();
         assertEquals( oldValue + 8, TestBean.currentCounter() );
     }
 
@@ -76,7 +77,7 @@ public final class StaticMethodsTestCase
     public void invokeStaticMethodIncrementCounterIntegerWrapper()
         throws Exception
     {
-        on( TestBean.class ).invokeStatic( "incrementCounter" ).withArguments( argument(
new Integer( 8 ) ) ).get();
+        on( new TypeLiteral<TestBean>(){} ).invokeStatic( "incrementCounter" ).withArguments(
argument( new Integer( 8 ) ) ).get();
         assertEquals( oldValue + 8, TestBean.currentCounter() );
     }
 
@@ -84,7 +85,7 @@ public final class StaticMethodsTestCase
     public void invokeStaticMethodIncrementCounterIntegerWrapperAsPrimitive()
         throws Exception
     {
-        on( TestBean.class ).invokeStatic( "incrementCounter" ).withArguments( argument(
int.class,
+        on( new TypeLiteral<TestBean>(){} ).invokeStatic( "incrementCounter" ).withArguments(
argument( int.class,
                                                                                         
      new Integer( 8 ) ) ).get();
         assertEquals( oldValue + 8, TestBean.currentCounter() );
     }
@@ -93,7 +94,7 @@ public final class StaticMethodsTestCase
     public void invokeStaticMethodIncrementCounterNumberInteger()
         throws Exception
     {
-        on( TestBean.class ).invokeStatic( "incrementCounter" ).withArguments( argument(
Number.class,
+        on( new TypeLiteral<TestBean>(){} ).invokeStatic( "incrementCounter" ).withArguments(
argument( Number.class,
                                                                                         
      new Integer( 8 ) ) ).get();
         // incrementCounter(Number) will multiply its input with 2
         assertEquals( oldValue + 8 * 2, TestBean.currentCounter() );
@@ -103,18 +104,20 @@ public final class StaticMethodsTestCase
     public void invokeStaticMethodWithInvalidArgument()
         throws Exception
     {
+        TypeLiteral<TestBean> testBeanLiteral = new TypeLiteral<TestBean>(){};
+
         String methodName = "incrementCounter";
         thrown.expect( NoSuchMethodException.class );
         thrown.expectMessage( "No such accessible method:" );
         thrown.expectMessage( methodName );
-        thrown.expectMessage( TestBean.class.getName() );
-        on( TestBean.class ).invokeStatic( methodName ).withArguments( argument( 'x' ) );
+        thrown.expectMessage( String.valueOf( testBeanLiteral ) );
+        on( testBeanLiteral ).invokeStatic( methodName ).withArguments( argument( 'x' ) );
     }
 
     @Test
     public void invokeExactStaticMethodIncrementCounter() throws Exception
     {
-        on( TestBean.class ).invokeExactStatic( "incrementCounter" ).withArguments();
+        on( new TypeLiteral<TestBean>(){} ).invokeExactStatic( "incrementCounter" ).withArguments();
         assertEquals( oldValue + 1, TestBean.currentCounter() );
     }
 
@@ -122,7 +125,7 @@ public final class StaticMethodsTestCase
     public void invokeExactStaticMethodIncrementIntegerPrimitive()
         throws Exception
     {
-        on( TestBean.class ).invokeExactStatic( "incrementCounter" ).withArguments( argument(
int.class, 8 ) ).get();
+        on( new TypeLiteral<TestBean>(){} ).invokeExactStatic( "incrementCounter" ).withArguments(
argument( int.class, 8 ) ).get();
         assertEquals( oldValue + 8, TestBean.currentCounter() );
     }
 
@@ -130,15 +133,15 @@ public final class StaticMethodsTestCase
     public void invokeExactStaticMethodIncrementIntegerWrapper()
         throws Exception
     {
-        on( TestBean.class ).invokeExactStatic( "incrementCounter" ).withArguments( argument(
new Integer( 8 ) ) ).get();
+        on( new TypeLiteral<TestBean>(){} ).invokeExactStatic( "incrementCounter" ).withArguments(
argument( new Integer( 8 ) ) ).get();
     }
 
     @Test
     public void invokeExactStaticMethodIncrementNumberInteger()
         throws Exception
     {
-        on( TestBean.class ).invokeExactStatic( "incrementCounter" ).withArguments( argument(
Number.class,
-                                                                                        
           new Integer( 8 ) ) ).get();
+        on( new TypeLiteral<TestBean>(){} ).invokeExactStatic( "incrementCounter" ).withArguments(
argument( Number.class,
+                                                                                        
                    new Integer( 8 ) ) ).get();
         // incrementCounter(Number) will multiply its input with 2
         assertEquals( oldValue + 2 * 8, TestBean.currentCounter() );
     }



Mime
View raw message