vmassol 02/05/05 13:08:50
Modified: framework/src/java/share/org/apache/cactus
AbstractTestCase.java AbstractWebTestCase.java
Log:
continuing refactoring
Revision Changes Path
1.6 +63 -1
jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractTestCase.java 5 May 2002 14:28:50 -0000 1.5
+++ AbstractTestCase.java 5 May 2002 20:08:50 -0000 1.6
@@ -75,7 +75,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: AbstractTestCase.java,v 1.5 2002/05/05 14:28:50 vmassol Exp $
+ * @version $Id: AbstractTestCase.java,v 1.6 2002/05/05 20:08:50 vmassol Exp $
*/
public abstract class AbstractTestCase extends TestCase
{
@@ -244,6 +244,68 @@
runServerTest();
} finally {
tearDown();
+ }
+ }
+
+ /**
+ * Call the test case begin method.
+ *
+ * @param theRequest the request object to pass to the begin method.
+ * @exception Throwable any error that occurred when calling the begin
+ * method for the current test case.
+ */
+ protected void callBeginMethod(Request theRequest) throws Throwable
+ {
+ // First, verify if a begin method exist. If one is found, verify if
+ // it has the correct signature. If not, send a warning.
+ Method[] methods = getClass().getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].getName().equals(getBeginMethodName())) {
+
+ // Check return type
+ if (!methods[i].getReturnType().getName().equals("void")) {
+ fail("The begin method [" + methods[i].getName() +
+ "] should return void and not [" +
+ methods[i].getReturnType().getName() + "]");
+ }
+
+ // Check if method is public
+ if (!Modifier.isPublic(methods[i].getModifiers())) {
+ fail("Method [" + methods[i].getName() +
+ "] should be declared public");
+ }
+
+ // Check parameters
+ Class[] parameters = methods[i].getParameterTypes();
+ if (parameters.length != 1) {
+
+ fail("The begin method [" + methods[i].getName() +
+ "] must accept a single parameter derived from " +
+ "class [" + WebRequest.class.getName() + "], " +
+ "but " + parameters.length + " parameters were found");
+
+ } else if (!theRequest.getClass().isAssignableFrom(
+ parameters[0])) {
+
+ fail("The begin method [" + methods[i].getName() +
+ "] must accept a single parameter derived from " +
+ "class [" + theRequest.getClass().getName() + "], " +
+ "but found a [" + parameters[0].getName() + "] " +
+ "parameter instead");
+ }
+
+ try {
+ methods[i].invoke(this, new Object[]{theRequest});
+ break;
+ } catch (InvocationTargetException e) {
+ e.fillInStackTrace();
+ throw e.getTargetException();
+ } catch (IllegalAccessException e) {
+ e.fillInStackTrace();
+ throw e;
+ }
+
+ }
}
}
1.2 +1 -66
jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebTestCase.java
Index: AbstractWebTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractWebTestCase.java 28 Apr 2002 20:19:17 -0000 1.1
+++ AbstractWebTestCase.java 5 May 2002 20:08:50 -0000 1.2
@@ -73,7 +73,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: AbstractWebTestCase.java,v 1.1 2002/04/28 20:19:17 vmassol Exp $
+ * @version $Id: AbstractWebTestCase.java,v 1.2 2002/05/05 20:08:50 vmassol Exp $
*/
public abstract class AbstractWebTestCase extends AbstractTestCase
{
@@ -85,71 +85,6 @@
public AbstractWebTestCase(String theName)
{
super(theName);
- }
-
- /**
- * Call the test case begin method
- *
- * @param theRequest the <code>WebRequest</code> object to
- * pass to the begin method.
- * @exception Throwable any error that occurred when calling the begin
- * method for the current test case.
- */
- protected void callBeginMethod(WebRequest theRequest)
- throws Throwable
- {
- // First, verify if a begin method exist. If one is found, verify if
- // it has the correct signature. If not, send a warning.
- Method[] methods = getClass().getMethods();
- for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(getBeginMethodName())) {
-
- // Check return type
- if (!methods[i].getReturnType().getName().equals("void")) {
- fail("The begin method [" + methods[i].getName() +
- "] should return void and not [" +
- methods[i].getReturnType().getName() + "]");
- }
-
- // Check if method is public
- if (!Modifier.isPublic(methods[i].getModifiers())) {
- fail("Method [" + methods[i].getName() +
- "] should be declared public");
- }
-
- // Check parameters
- Class[] parameters = methods[i].getParameterTypes();
- if (parameters.length != 1) {
-
- fail("The begin method [" + methods[i].getName() +
- "] must accept a single parameter derived from " +
- "class [" + WebRequest.class.getName() + "], " +
- "but " + parameters.length + " parameters were found");
-
- } else if (
- !WebRequest.class.isAssignableFrom(parameters[0])) {
-
- fail("The begin method [" + methods[i].getName() +
- "] must accept a single parameter derived from " +
- "class [" + WebRequest.class.getName() + "], " +
- "but found a [" + parameters[0].getName() + "] " +
- "parameter instead");
- }
-
- try {
-
- methods[i].invoke(this, new Object[]{theRequest});
-
- } catch (InvocationTargetException e) {
- e.fillInStackTrace();
- throw e.getTargetException();
- } catch (IllegalAccessException e) {
- e.fillInStackTrace();
- throw e;
- }
-
- }
- }
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>