[java] CommentDefaultAccessModifier: add test case for ignoredAnnotations

This commit is contained in:
Andreas Dangel
2018-10-27 22:36:52 +02:00
parent 2dd0033520
commit ada6d83a83
2 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,9 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.rule.codestyle.commentdefaultaccessmodifier;
public @interface OnlyForTesting {
}

View File

@ -161,7 +161,19 @@ public class CommentDefaultAccessModifier {
}
]]></code>
</test-code>
<test-code>
<description>#1430 CommentDefaultAccessModifier triggers on field annotated with @VisibleForTesting 2</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import com.google.common.annotations.VisibleForTesting;
public class CommentDefaultAccessModifier {
@VisibleForTesting void method() {}
}
]]></code>
</test-code>
<test-code>
<description>#536 Constructor with default access modifier should trigger</description>
<expected-problems>1</expected-problems>
@ -218,6 +230,27 @@ public interface A {
interface B {
default void b() {}
}
}
]]></code>
</test-code>
<test-code>
<description>Use property ignoredAnnotations (see #1343)</description>
<rule-property name="ignoredAnnotations">net.sourceforge.pmd.lang.java.rule.codestyle.commentdefaultaccessmodifier.OnlyForTesting</rule-property>
<expected-problems>1</expected-problems>
<expected-linenumbers>6</expected-linenumbers>
<expected-messages>
<message>To avoid mistakes add a comment at the beginning of the method method if you want a default access modifier</message>
</expected-messages>
<code><![CDATA[
package net.sourceforge.pmd.lang.java.rule.codestyle.commentdefaultaccessmodifier;
import android.support.annotation.VisibleForTesting;
public class CommentDefaultAccessModifier {
@VisibleForTesting void method() {}
@OnlyForTesting void method2() {}
}
]]></code>
</test-code>