Skip to content

Apache Lucene open-source search software

fix bug where @Test A::test(), B extends A, B::test() without @Test would be run twice

Robert Muir790a492be3a6
diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
index 913d5ca90fd..ff2d062c6c9 100644
--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
@@ -986,7 +986,7 @@ public abstract class LuceneTestCase extends Assert {
if (testMethods != null)
return testMethods;
testClassesRun.add(getTestClass().getJavaClass().getSimpleName());
- testMethods = getTestClass().getAnnotatedMethods(Test.class);
+ testMethods = new ArrayList<FrameworkMethod>();
for (Method m : getTestClass().getJavaClass().getMethods()) {
// check if the current test's class has methods annotated with @Ignore
final Ignore ignored = m.getAnnotation(Ignore.class);
@@ -995,11 +995,11 @@ public abstract class LuceneTestCase extends Assert {
}
// add methods starting with "test"
final int mod = m.getModifiers();
- if (m.getName().startsWith("test") &&
- m.getAnnotation(Test.class) == null &&
+ if (m.getAnnotation(Test.class) != null ||
+ (m.getName().startsWith("test") &&
!Modifier.isAbstract(mod) &&
m.getParameterTypes().length == 0 &&
- m.getReturnType() == Void.TYPE)
+ m.getReturnType() == Void.TYPE))
{
if (Modifier.isStatic(mod))
throw new RuntimeException("Test methods must not be static.");