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-ffa450edef68master
@@ -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) {} | ||||
@@ -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";} | |||||
} | |||||
} | } |