Skip to content

Commit

Permalink
Issue #34: Add tests for suppress annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed Mar 29, 2015
1 parent 6981f7e commit 5128cc5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
Binary file modified src/test/antunit/Java5DeprecatedAnnotation.class
Binary file not shown.
1 change: 1 addition & 0 deletions src/test/antunit/Java5DeprecatedAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Java5DeprecatedAnnotation {

/** @deprecated **/
public Java5DeprecatedAnnotation() {
new StringBuilder();
}

}
Binary file modified src/test/antunit/Java8Annotations.class
Binary file not shown.
2 changes: 1 addition & 1 deletion src/test/antunit/Java8Annotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public InnerClassWithCtorParam(@FooBar X param) {
public int testField2;

@ClassFileOnly
public int testField3;
public StringBuilder testField3;

@Retention(value=RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD, ElementType.TYPE})
Expand Down
37 changes: 36 additions & 1 deletion src/test/antunit/TestAnnotations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,47 @@
<target name="testMissingDeprecatedAnnotation">
<au:expectfailure expectedMessage="Check for forbidden API calls failed, see log">
<forbiddenapis failOnMissingClasses="true" classpath="${basedir}">
<fileset file="Java5DeprecatedAnnotation.class"/>
<file file="Java5DeprecatedAnnotation.class"/>
java.lang.Deprecated @ Deprecated annotation
</forbiddenapis>
</au:expectfailure>
<au:assertLogContains level="error" text="java.lang.Deprecated [Deprecated annotation]"/>
<au:assertLogContains level="error" text=" 1 error(s)"/>
</target>

<target name="testSuppressAnnotationsDeprecated1">
<forbiddenapis failOnMissingClasses="true" classpath="${basedir}" suppressAnnotation="java.lang.Deprecated">
<file file="Java5DeprecatedAnnotation.class"/>
java.lang.StringBuilder
</forbiddenapis>
</target>

<target name="testSuppressAnnotationsDeprecated2">
<forbiddenapis failOnMissingClasses="true" classpath="${basedir}">
<suppressAnnotation classname="java.lang.Deprecated"/>
<file file="Java5DeprecatedAnnotation.class"/>
java.lang.StringBuilder
</forbiddenapis>
</target>

<target name="testSuppressAnnotationsJava8">
<forbiddenapis failOnMissingClasses="true" classpath="${basedir}">
<!-- this should disable whole class scanning: -->
<suppressAnnotation classname="Java8Annotations$FooBar"/>
<!-- normally, this should produce similar errors like 'testAnnotations': -->
<file file="Java8Annotations.class"/>
Java8Annotations$ClassFileOnly @ Forbidden class-only annotation
Java8Annotations$FooBar @ Forbidden annotation
java.lang.Deprecated @ Deprecated annotation
</forbiddenapis>
</target>

<target name="testSuppressAnnotationsJava8ClassFileOnly">
<forbiddenapis failOnMissingClasses="true" classpath="${basedir}">
<suppressAnnotation classname="Java8Annotations$ClassFileOnly"/>
<file file="Java8Annotations.class"/>
java.lang.StringBuilder
</forbiddenapis>
</target>

</project>

0 comments on commit 5128cc5

Please sign in to comment.