[jboss-cvs] JBossAS SVN: r82621 - in projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang: unit and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 6 03:24:41 EST 2009
Author: jaikiran
Date: 2009-01-06 03:24:40 -0500 (Tue, 06 Jan 2009)
New Revision: 82621
Modified:
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/MyClass.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/unit/SerializableMethodTestCase.java
Log:
EJBTHREE-1400 Added tests for vararg methods
Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/MyClass.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/MyClass.java 2009-01-06 03:19:19 UTC (rev 82620)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/MyClass.java 2009-01-06 08:24:40 UTC (rev 82621)
@@ -159,4 +159,32 @@
return m;
}
+ /**
+ *
+ * @param ints
+ */
+ public void methodWithPrimitiveVarArgsAndReturningVoid(int... ints)
+ {
+ // do nothing
+ }
+
+ /**
+ *
+ * @param integers
+ */
+ public void methodWithVarArgsAndReturningVoid(Integer... integers)
+ {
+ // do nothing
+ }
+
+ /**
+ *
+ * @param someString
+ * @param objects
+ */
+ public void methodWithVarArgsAndNormalArg(String someString, Object... objects)
+ {
+ // do nothing
+ }
+
}
Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/unit/SerializableMethodTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/unit/SerializableMethodTestCase.java 2009-01-06 03:19:19 UTC (rev 82620)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/lang/unit/SerializableMethodTestCase.java 2009-01-06 08:24:40 UTC (rev 82621)
@@ -585,7 +585,7 @@
copyOfMethod.hashCode());
// test toString
- assertEquals("Roundtrip of inherited method toString failed",copyOfMethodToString, methodToString);
+ assertEquals("Roundtrip of inherited method toString failed", copyOfMethodToString, methodToString);
logger.info("Completed testing the toMethod(Classloader)");
@@ -626,7 +626,7 @@
logger.info("Completed testing toMethod() with serialization");
}
-
+
/**
* Test to ensure that when no actual class is specified,
* this field is automatically populated to the value of the declaring
@@ -638,19 +638,91 @@
public void testDeclaringClassDefaultsWhenNoActualClassSpecified() throws Throwable
{
// Obtain a method
- Method method = Object.class.getMethod("toString", new Class<?>[]{});
-
+ Method method = Object.class.getMethod("toString", new Class<?>[]
+ {});
+
// Create a Serializable View, without noting an actual class
SerializableMethod sm = new SerializableMethod(method);
-
+
// Get the actual and declaring class names
String declaringClassName = sm.getDeclaringClassName();
String actualClassName = sm.getActualClassName();
-
+
// Ensure they're equal
assertEquals("When no actual class is specified, should default to the declaring class", declaringClassName,
actualClassName);
+
+ }
+
+ /**
+ * Test to ensure that the {@link SerializableMethod#toMethod()} works as expected
+ * when varargs are involved.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testToMethodForVarArgs() throws Throwable
+ {
+
+ logger.info("Testing the toMethod(), for methods accepting primitive varargs");
+
+ // Get the primitive vararg method
+ Method primitiveVarArgMethod = myClass.getClass().getMethod("methodWithPrimitiveVarArgsAndReturningVoid",
+ new Class<?>[]
+ {int[].class});
+
+ // Create SerializableMethod
+ SerializableMethod serializableMethodForPrimitiveVarArgMethod = new SerializableMethod(primitiveVarArgMethod);
+
+ // Call toMethod
+ Method returnedMethod = serializableMethodForPrimitiveVarArgMethod.toMethod();
+ //test equals
+ assertTrue("Failure - The method returned by toMethod() of SerializableMethod is not equal to the original method", returnedMethod.equals(primitiveVarArgMethod));
+
+ // test hashCode
+ assertEquals("Failure - The method returned by toMethod() has a different hashCode than the original method", returnedMethod.hashCode(), primitiveVarArgMethod.hashCode());
+
+ logger.info("Completed testing the toMethod(), for methods accepting primitive varargs");
+
+ logger.info("Testing the toMethod(), for methods accepting non-primitive varargs");
+ // Get method for non-primitive vararg
+ Method nonPrimitiveVarArgMethod = myClass.getClass().getMethod("methodWithVarArgsAndReturningVoid", new Class<?>[]{Integer[].class});
+
+ // Create a serializablemethod out of it
+ SerializableMethod serializableMethodForNonPrimitiveVarArg = new SerializableMethod(nonPrimitiveVarArgMethod);
+
+ // Call toMethod
+ Method returnedMethodForNonPrimitiveVarArg = serializableMethodForNonPrimitiveVarArg.toMethod();
+
+ // test equals
+ assertTrue("Failure - The method returned by toMethod() of SerializableMethod is not equal to the original method", returnedMethodForNonPrimitiveVarArg.equals(nonPrimitiveVarArgMethod));
+
+ // test hashCode
+ assertEquals("Failure - The method returned by toMethod() has a different hashCode than the original method", returnedMethodForNonPrimitiveVarArg.hashCode(), nonPrimitiveVarArgMethod.hashCode());
+
+ logger.info("Completed testing the toMethod(), for methods accepting non-primitive varargs");
+
+
+ logger.info("Testing the toMethod(), for methods accepting a normal arg and a vararg");
+ // Get the method
+ Method mixedVarArgMethod = myClass.getClass().getMethod("methodWithVarArgsAndNormalArg", new Class<?>[]{String.class,Object[].class});
+
+ // Create a serializablemethod out of it
+ SerializableMethod serializableMethodForMixedVarArgMethod = new SerializableMethod(mixedVarArgMethod);
+
+ // Call toMethod
+ Method returnedMethodForMixedVarArgMethod = serializableMethodForMixedVarArgMethod.toMethod();
+
+ // test equals
+ assertTrue("Failure - The method returned by toMethod() of SerializableMethod is not equal to the original method", returnedMethodForMixedVarArgMethod.equals(mixedVarArgMethod));
+
+ // test hashCode
+ assertEquals("Failure - The method returned by toMethod() has a different hashCode than the original method", returnedMethodForMixedVarArgMethod.hashCode(), mixedVarArgMethod.hashCode());
+
+ logger.info("Completed testing the toMethod(), for methods accepting a normal arg and a vararg");
+
+
}
-
+
}
More information about the jboss-cvs-commits
mailing list