Browse Source

bug ID#42231, a static method is package scoped instead of public

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@532325 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 18 years ago
parent
commit
36b05881a3
1 changed files with 23 additions and 9 deletions
  1. +23
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java

+ 23
- 9
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java View File

@@ -25,10 +25,20 @@ import junit.framework.TestCase;
/** /**
* Work around for some changes to the public JUnit API between * Work around for some changes to the public JUnit API between
* different JUnit releases. * different JUnit releases.
* @since Ant 1.7
*/ */
public class JUnitVersionHelper { public class JUnitVersionHelper {


private static Method testCaseName = null; private static Method testCaseName = null;

/**
* Name of the JUnit4 class we look for.
* {@value}
* @since Ant 1.7.1
*/
public static final String JUNIT_FRAMEWORK_JUNIT4_TEST_CASE_FACADE = "junit.framework.JUnit4TestCaseFacade";
private static final String UNKNOWN_TEST_CASE_NAME = "unknown";

static { static {
try { try {
testCaseName = TestCase.class.getMethod("getName", new Class[0]); testCaseName = TestCase.class.getMethod("getName", new Class[0]);
@@ -36,7 +46,7 @@ public class JUnitVersionHelper {
// pre JUnit 3.7 // pre JUnit 3.7
try { try {
testCaseName = TestCase.class.getMethod("name", new Class[0]); testCaseName = TestCase.class.getMethod("name", new Class[0]);
} catch (NoSuchMethodException e2) {
} catch (NoSuchMethodException ignored) {
// ignore // ignore
} }
} }
@@ -60,9 +70,9 @@ public class JUnitVersionHelper {
public static String getTestCaseName(Test t) { public static String getTestCaseName(Test t) {
if (t == null) if (t == null)
{ {
return "unknown";
return UNKNOWN_TEST_CASE_NAME;
} }
if (t.getClass().getName().equals("junit.framework.JUnit4TestCaseFacade")) {
if (t.getClass().getName().equals(JUNIT_FRAMEWORK_JUNIT4_TEST_CASE_FACADE)) {
// Self-describing as of JUnit 4 (#38811). But trim "(ClassName)". // Self-describing as of JUnit 4 (#38811). But trim "(ClassName)".
String name = t.toString(); String name = t.toString();
if (name.endsWith(")")) { if (name.endsWith(")")) {
@@ -75,7 +85,7 @@ public class JUnitVersionHelper {
if (t instanceof TestCase && testCaseName != null) { if (t instanceof TestCase && testCaseName != null) {
try { try {
return (String) testCaseName.invoke(t, new Object[0]); return (String) testCaseName.invoke(t, new Object[0]);
} catch (Throwable e) {
} catch (Throwable ignored) {
// ignore // ignore
} }
} else { } else {
@@ -92,23 +102,27 @@ public class JUnitVersionHelper {
&& getNameMethod.getReturnType() == String.class) { && getNameMethod.getReturnType() == String.class) {
return (String) getNameMethod.invoke(t, new Object[0]); return (String) getNameMethod.invoke(t, new Object[0]);
} }
} catch (Throwable e) {
} catch (Throwable ignored) {
// ignore // ignore
} }
} }
return "unknown";
return UNKNOWN_TEST_CASE_NAME;
} }


/** /**
* Tries to find the name of the class which a test represents * Tries to find the name of the class which a test represents
* across JUnit 3 and 4.
* across JUnit 3 and 4. For Junit4 it parses the toString() value of the
* test, and extracts it from there.
* @since Ant 1.7.1 (it was private until then)
* @param test test case to look at
* @return the extracted class name.
*/ */
static String getTestCaseClassName(Test test) {
public static String getTestCaseClassName(Test test) {
String className = test.getClass().getName(); String className = test.getClass().getName();
if (test instanceof JUnitTaskMirrorImpl.VmExitErrorTest) { if (test instanceof JUnitTaskMirrorImpl.VmExitErrorTest) {
className = ((JUnitTaskMirrorImpl.VmExitErrorTest) test).getClassName(); className = ((JUnitTaskMirrorImpl.VmExitErrorTest) test).getClassName();
} else } else
if (className.equals("junit.framework.JUnit4TestCaseFacade")) {
if (className.equals(JUNIT_FRAMEWORK_JUNIT4_TEST_CASE_FACADE)) {
// JUnit 4 wraps solo tests this way. We can extract // JUnit 4 wraps solo tests this way. We can extract
// the original test name with a little hack. // the original test name with a little hack.
String name = test.toString(); String name = test.toString();


Loading…
Cancel
Save