Browse Source

Support name() accessors as well.

Submitted by:	Andrew Everitt <Andrew.Everitt at gbr.xerox.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273328 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
e1ef86cb25
2 changed files with 20 additions and 3 deletions
  1. +10
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java
  2. +10
    -0
      src/testcases/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java

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

@@ -96,9 +96,16 @@ public class JUnitVersionHelper {
} catch (Throwable e) {} } catch (Throwable e) {}
} else { } else {
try { try {
Method getNameMethod =
t.getClass().getMethod("getName", new Class [0]);
if (getNameMethod.getReturnType() == String.class) {
Method getNameMethod = null;
try {
getNameMethod =
t.getClass().getMethod("getName", new Class [0]);
} catch (NoSuchMethodException e) {
getNameMethod = t.getClass().getMethod("name",
new Class [0]);
}
if (getNameMethod != null &&
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 e) {}


+ 10
- 0
src/testcases/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java View File

@@ -87,6 +87,11 @@ public class JUnitVersionHelperTest extends TestCase {
JUnitVersionHelper.getTestCaseName(new Foo3())); JUnitVersionHelper.getTestCaseName(new Foo3()));
} }


public void testNameNotGetName() {
assertEquals("I'm a foo, too",
JUnitVersionHelper.getTestCaseName(new Foo4()));
}

public void testNull() { public void testNull() {
assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null)); assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null));
} }
@@ -106,4 +111,9 @@ public class JUnitVersionHelperTest extends TestCase {


public static class Foo3 extends Foo { public static class Foo3 extends Foo {
} }

public static class Foo4 extends Foo {
public String name() {return "I'm a foo, too";}
}

} }

Loading…
Cancel
Save