forked from angelozerr/jdt-codemining
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix angelozerr#106: Check for JUnit3 base class.
- Loading branch information
Showing
1 changed file
with
17 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 17 additions & 1 deletion
18
...demining/src/org/eclipse/jdt/experimental/junit/codemining/tester/JUnit3MethodTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
package org.eclipse.jdt.experimental.junit.codemining.tester; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.jdt.core.IMethod; | ||
import org.eclipse.jdt.core.IType; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.experimental.JavaCodeMiningPlugin; | ||
|
||
public class JUnit3MethodTester implements IJUnitMethodTester { | ||
|
||
public static final IJUnitMethodTester INSTANCE = new JUnit3MethodTester(); | ||
|
||
@Override | ||
public boolean isTestMethod(IMethod method) { | ||
return IJUnitMethodTester.isMethod(method, true) && method.getElementName().startsWith("test"); | ||
return IJUnitMethodTester.isMethod(method, true) && isTestClass(method.getDeclaringType()) | ||
&& method.getElementName().startsWith("test"); | ||
} | ||
|
||
private boolean isTestClass(IType type) { | ||
try { | ||
return Stream.of(type.newSupertypeHierarchy(new NullProgressMonitor()).getAllSupertypes(type)) | ||
.filter(t -> "junit.framework.TestCase".equals(t.getFullyQualifiedName())).findFirst().isPresent(); | ||
} catch (JavaModelException e) { | ||
JavaCodeMiningPlugin.getDefault().getLog().error("isTestClass check for JUnit3 failed.", e); | ||
return false; | ||
} | ||
} | ||
} |