Merge pull request #4706 from Debamoy:issue/1831-detached-test-case-reports-package-private-methods
[java] DetachedTestCase should not report on abstract methods #4706
This commit is contained in:
@ -24,7 +24,7 @@ public class DetachedTestCaseRule extends AbstractJavaRulechainRule {
|
||||
// looks like a test case
|
||||
methods.filter(m -> m.getArity() == 0
|
||||
&& m.isVoid()
|
||||
&& !m.getModifiers().hasAny(JModifier.STATIC, JModifier.PRIVATE, JModifier.PROTECTED))
|
||||
&& !m.getModifiers().hasAny(JModifier.STATIC, JModifier.PRIVATE, JModifier.PROTECTED, JModifier.ABSTRACT))
|
||||
// the method itself has no annotation
|
||||
.filter(it -> it.getDeclaredAnnotations().isEmpty())
|
||||
.forEach(m -> addViolation(data, m));
|
||||
|
@ -36,6 +36,22 @@ public class MyTest {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Abstract methods should not be reported as detached test case (#1831)</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class MyTest {
|
||||
@Test
|
||||
public void someTest() {}
|
||||
|
||||
public abstract void someOtherTest() {}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
|
||||
<test-code>
|
||||
<description>missing annotation on public test case in JUnit 4 test class (regular annotation)</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
|
Reference in New Issue
Block a user