vmassol 01/10/28 03:27:37
Modified: src/framework/share/org/apache/cactus AbstractTestCase.java
src/sample/share/org/apache/cactus/sample/unit
TestServletTestCase1_InterceptorServletTestCase.java
src/test/share/org/apache/cactus
TestAbstractTestCase_InterceptorTestCase.java
Added: src/framework/share/org/apache/cactus/util
JUnitVersionHelper.java
Log:
added support for JUnit 3.8 without breaking support for ealier versions of JUnit
(Note: JUnit 3.8 removed the name() method - replaced by getName())
Revision Changes Path
1.15 +6 -6
jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- AbstractTestCase.java 2001/10/22 14:09:51 1.14
+++ AbstractTestCase.java 2001/10/28 11:27:36 1.15
@@ -72,7 +72,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: AbstractTestCase.java,v 1.14 2001/10/22 14:09:51 vmassol Exp $
+ * @version $Id: AbstractTestCase.java,v 1.15 2001/10/28 11:27:36 vmassol Exp $
*/
public abstract class AbstractTestCase extends TestCase
{
@@ -118,7 +118,7 @@
public AbstractTestCase(String theName)
{
super(theName);
- this.currentTestMethod = getName();
+ this.currentTestMethod = JUnitVersionHelper.getTestCaseName(this);
}
/**
@@ -128,12 +128,12 @@
private String getBaseMethodName()
{
// Sanity check
- if (!getName().startsWith(TEST_METHOD_PREFIX)) {
- throw new RuntimeException("bad name [" + getName() +
+ if (!this.currentTestMethod.startsWith(TEST_METHOD_PREFIX)) {
+ throw new RuntimeException("bad name [" + this.currentTestMethod +
"]. It should start with [" + TEST_METHOD_PREFIX + "].");
}
- return getName().substring(TEST_METHOD_PREFIX.length());
+ return this.currentTestMethod.substring(TEST_METHOD_PREFIX.length());
}
/**
@@ -421,7 +421,7 @@
// a file, ...
request.addParameter(ServiceDefinition.CLASS_NAME_PARAM,
this.getClass().getName(), WebRequest.GET_METHOD);
- request.addParameter(ServiceDefinition.METHOD_NAME_PARAM, getName(),
+ request.addParameter(ServiceDefinition.METHOD_NAME_PARAM,
this.currentTestMethod,
WebRequest.GET_METHOD);
request.addParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM,
new Boolean(request.getAutomaticSession()).toString(),
1.7 +4 -4
jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase1_InterceptorServletTestCase.java
Index: TestServletTestCase1_InterceptorServletTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase1_InterceptorServletTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestServletTestCase1_InterceptorServletTestCase.java 2001/10/27 15:36:46
1.6
+++ TestServletTestCase1_InterceptorServletTestCase.java 2001/10/28 11:27:36
1.7
@@ -66,7 +66,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: TestServletTestCase1_InterceptorServletTestCase.java,v 1.6
2001/10/27 15:36:46 vmassol Exp $
+ * @version $Id: TestServletTestCase1_InterceptorServletTestCase.java,v 1.7
2001/10/28 11:27:36 vmassol Exp $
* @see TestServletTestCase1
*/
public class TestServletTestCase1_InterceptorServletTestCase
@@ -94,7 +94,7 @@
// If the test case is "testAssertionFailedError" and the exception
// is of type AssertionFailedError and contains the text
// "test assertion failed error", then the test is ok.
- if (getName().equals("testAssertionFailedError")) {
+ if (this.currentTestMethod.equals("testAssertionFailedError")) {
if (e.instanceOf(AssertionFailedError.class)) {
assertEquals("test assertion failed error", e.getMessage());
return;
@@ -108,7 +108,7 @@
// TestServletTestCaseHelper1_ExceptionNotSerializable
// and contains the text "test non serializable exception", then
// the test is ok.
- if (getName().equals("testExceptionNotSerializable")) {
+ if (this.currentTestMethod.equals("testExceptionNotSerializable")) {
if (e.instanceOf(
TestServletTestCase1_ExceptionNotSerializable.class)) {
@@ -122,7 +122,7 @@
// is of type TestServletTestCaseHelper1_ExceptionSerializable
// and contains the text "test serializable exception", then
// the test is ok.
- if (getName().equals("testExceptionSerializable")) {
+ if (this.currentTestMethod.equals("testExceptionSerializable")) {
assert(e.instanceOf(
TestServletTestCase1_ExceptionSerializable.class));
1.9 +13 -13
jakarta-cactus/src/test/share/org/apache/cactus/TestAbstractTestCase_InterceptorTestCase.java
Index: TestAbstractTestCase_InterceptorTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/test/share/org/apache/cactus/TestAbstractTestCase_InterceptorTestCase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TestAbstractTestCase_InterceptorTestCase.java 2001/10/22 14:10:12 1.8
+++ TestAbstractTestCase_InterceptorTestCase.java 2001/10/28 11:27:36 1.9
@@ -68,7 +68,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: TestAbstractTestCase_InterceptorTestCase.java,v 1.8 2001/10/22
14:10:12 vmassol Exp $
+ * @version $Id: TestAbstractTestCase_InterceptorTestCase.java,v 1.9 2001/10/28
11:27:36 vmassol Exp $
*/
public class TestAbstractTestCase_InterceptorTestCase
extends AbstractTestCase
@@ -124,7 +124,7 @@
// Test that when a begin method for a given test does not have the
// correct return type (i.e. void), a
// <code>AssertionFailedError</code> exception is returned.
- if (getName().equals("testBeginMethodBadReturnType")) {
+ if (this.currentTestMethod.equals("testBeginMethodBadReturnType")) {
assertEquals("The begin method " +
"[beginBeginMethodBadReturnType] should return void and " +
"not [java.lang.String]", e.getMessage());
@@ -133,7 +133,7 @@
// Test that when a begin method for a given test is not declared
// public a <code>AssertionFailedError</code> exception is returned.
- if (getName().equals("testBeginMethodNotPublic")) {
+ if (this.currentTestMethod.equals("testBeginMethodNotPublic")) {
assertEquals("Method [beginBeginMethodNotPublic] should be " +
"declared public", e.getMessage());
return;
@@ -142,7 +142,7 @@
// Test that when a begin method for a given test has the wrong
// type of parameters, a <code>AssertionFailedError</code> exception
// is returned.
- if (getName().equals("testBeginMethodBadParamType")) {
+ if (this.currentTestMethod.equals("testBeginMethodBadParamType")) {
assertEquals("The begin method " +
"[beginBeginMethodBadParamType] must accept a single " +
"parameter derived from class " +
@@ -155,7 +155,7 @@
// Test that when a begin method for a given test has the wrong
// number of parameters, a <code>AssertionFailedError</code>
// exception is returned.
- if (getName().equals("testBeginMethodBadParamNumber")) {
+ if (this.currentTestMethod.equals("testBeginMethodBadParamNumber")) {
assertEquals("The begin method " +
"[beginBeginMethodBadParamNumber] must accept a single " +
"parameter derived from class " +
@@ -167,7 +167,7 @@
// Verify that the begin method with a
// <code>WebRequest</code> parameter is called correctly.
- if (getName().equals("testBeginMethodOK")) {
+ if (this.currentTestMethod.equals("testBeginMethodOK")) {
assertEquals("beginBeginMethodOK", e.getMessage());
return;
}
@@ -177,7 +177,7 @@
// Test that when an end method for a given test does not have the
// correct return type (i.e. void), a
// <code>AssertionFailedError</code> exception is returned.
- if (getName().equals("testEndMethodBadReturnType")) {
+ if (this.currentTestMethod.equals("testEndMethodBadReturnType")) {
assertEquals("The end method " +
"[endEndMethodBadReturnType] should return void and " +
"not [java.lang.String]", e.getMessage());
@@ -186,7 +186,7 @@
// Test that when an end method for a given test is not declared
// public a <code>AssertionFailedError</code> exception is returned.
- if (getName().equals("testEndMethodNotPublic")) {
+ if (this.currentTestMethod.equals("testEndMethodNotPublic")) {
assertEquals("Method [endEndMethodNotPublic] should be " +
"declared public", e.getMessage());
return;
@@ -195,7 +195,7 @@
// Test that when an end method for a given test has the wrong
// type of parameters, a <code>AssertionFailedError</code> exception
// is returned.
- if (getName().equals("testEndMethodBadParamType")) {
+ if (this.currentTestMethod.equals("testEndMethodBadParamType")) {
assertEquals("The end method [endEndMethodBadParamType] " +
"has a bad parameter of type [java.lang.String]",
e.getMessage());
@@ -205,7 +205,7 @@
// Test that when an end method for a given test has the wrong
// number of parameters, a <code>AssertionFailedError</code>
// exception is returned.
- if (getName().equals("testEndMethodBadParamNumber")) {
+ if (this.currentTestMethod.equals("testEndMethodBadParamNumber")) {
assertEquals("The end method [endEndMethodBadParamNumber] " +
"must only have a single parameter", e.getMessage());
return;
@@ -214,7 +214,7 @@
// Test that the end method is called correctly when it's signature
// contains a <code>org.apache.cactus.WebResponse</code>
// parameter.
- if (getName().equals("testEndMethodOK1")) {
+ if (this.currentTestMethod.equals("testEndMethodOK1")) {
assertEquals("endEndMethodOK1", e.getMessage());
return;
}
@@ -222,7 +222,7 @@
// Test that the end method is called correctly when it's signature
// contains a <code>com.meterware.httpunit.WebResponse</code>
// parameter.
- if (getName().equals("testEndMethodOK2")) {
+ if (this.currentTestMethod.equals("testEndMethodOK2")) {
assertEquals("endEndMethodOK2", e.getMessage());
return;
}
@@ -230,7 +230,7 @@
// Test that the deprecated end method with the
// <code>HttpURLConnection</code> parameter can still be called
// correctly.
- if (getName().equals("testEndMethodOK3")) {
+ if (this.currentTestMethod.equals("testEndMethodOK3")) {
assertEquals("endEndMethodOK3", e.getMessage());
return;
}
1.1
jakarta-cactus/src/framework/share/org/apache/cactus/util/JUnitVersionHelper.java
Index: JUnitVersionHelper.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Cactus", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.cactus.util;
import java.lang.reflect.*;
import junit.framework.*;
/**
* Work around for some changes to the public JUnit API between
* different JUnit releases.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
* @version $Id: JUnitVersionHelper.java,v 1.1 2001/10/28 11:27:36 vmassol Exp $
*/
public class JUnitVersionHelper
{
private static Method testCaseName = null;
static {
try {
testCaseName = TestCase.class.getMethod("getName", new Class[0]);
} catch (NoSuchMethodException e) {
// pre JUnit 3.7
try {
testCaseName = TestCase.class.getMethod("name", new Class[0]);
} catch (NoSuchMethodException e2) {
throw new ChainedRuntimeException("Cannot find method 'name()'");
}
}
}
/**
* JUnit 3.7 introduces TestCase.getName() and subsequent versions
* of JUnit remove the old name() method. This method provides
* access to the name of a TestCase via reflection that is
* supposed to work with version before and after JUnit 3.7.
*/
public static String getTestCaseName(TestCase t)
{
if (testCaseName != null) {
try {
return (String) testCaseName.invoke(t, new Object[0]);
} catch (Throwable e) {}
}
return "unknown";
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]