Author: julien(a)jboss.com
Date: 2007-06-02 19:51:26 -0400 (Sat, 02 Jun 2007)
New Revision: 7372
Modified:
trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
Log:
- make isInvokable not have side effect (state mutation)
- revert to getMethod() rather than getDeclaredMethod() as getDeclaredMethod() would not
pick up the method from a parent class
Modified: trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-06-01
21:54:37 UTC (rev 7371)
+++ trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-06-02
23:51:26 UTC (rev 7372)
@@ -148,15 +148,8 @@
// Invoke setUp() if it exists
try
{
- Method setUpMethod = testClass.getDeclaredMethod("setUp", new
Class[0]);
- if (isInvokable(setUpMethod, true))
- {
- setUpMethod.invoke(test, new Object[0]);
- }
- else
- {
- // Maybe print a warn !!! ???
- }
+ Method setUp = testClass.getMethod("setUp", new Class[0]);
+ invokeNoArg(test, setUp, true);
}
catch (NoSuchMethodException ignore)
{
@@ -194,11 +187,8 @@
// Invoke tearDown() if it exists
try
{
- Method tearDown = testClass.getDeclaredMethod("tearDown", new
Class[0]);
- if (isInvokable(tearDown, true))
- {
- tearDown.invoke(test, new Object[0]);
- }
+ Method tearDown = testClass.getMethod("tearDown", new Class[0]);
+ invokeNoArg(test, tearDown, true);
}
catch (NoSuchMethodException ignore)
{
@@ -223,7 +213,8 @@
Method method = methods[j];
//
- if (isInvokable(method))
+ int modifiers = method.getModifiers();
+ if (Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers)
&& !Modifier.isStatic(modifiers))
{
String methodName = method.getName();
if (methodName.startsWith("test") &&
@@ -266,27 +257,36 @@
this.containerInfo = containerInfo;
}
- /** Return true if the method is invokable. */
- private boolean isInvokable(Method m)
+ /**
+ * Invoke a method that takes no argument.
+ *
+ * @param m the method to invoke
+ * @param allowProtected enable the invocation of non accessible methods
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ private static void invokeNoArg(Object test, Method m, boolean allowProtected) throws
IllegalAccessException, InvocationTargetException
{
- return isInvokable(m, false);
- }
-
- private boolean isInvokable(Method m, boolean allowProtected)
- {
int modifiers = m.getModifiers();
- boolean accessible = Modifier.isPublic(modifiers);
- if (allowProtected)
+ //
+ if (Modifier.isStatic(modifiers) || Modifier.isAbstract(modifiers))
{
- accessible |= Modifier.isProtected(modifiers);
- if (accessible)
+ return;
+ }
+
+ //
+ if (!Modifier.isPublic(modifiers))
+ {
+ if (!allowProtected)
{
- m.setAccessible(true);
+ return;
}
+ m.setAccessible(true);
}
- return accessible && !Modifier.isAbstract(modifiers) &&
!Modifier.isStatic(modifiers);
+ //
+ m.invoke(test, new Object[0]);
}
public static TestSuite createTestSuite(Class testClass, Map parameterMap) throws
Exception
Show replies by date