Skip to content

Commit

Permalink
Do not use javax package in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 12, 2024
1 parent 2756da3 commit 8826fcc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/util/Generated.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.CLASS;
import static java.lang.annotation.RetentionPolicy.*;

/**
* This annotation is used to mark source code that has been generated or is somehow not relevant for style checking or
* code coverage analysis. It is quite similar to the {@code javax.annotation.Generated} annotation. The
* code coverage analysis. It is quite similar to the JSR305 annotation. The
* main difference is that it has class retention, so it is available for tools that work on bytecode (like JaCoCo,
* PIT, or SpotBugs).
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/edu/hm/hafner/util/ArchitectureRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public final class ArchitectureRules {
.dependOnClassesThat()
.haveNameMatching(
"edu.umd.cs.findbugs.annotations.Nullable") // only CheckForNull and NonNull is allowed
.because("JSR 305 annotations are now part of edu.umd.cs.findbugs.annotations package");
.because("JSR 305 annotations are forbidden, as well as the Nullable annotation from FindBugs");

/** Prevents that classes use visible but forbidden API. */
public static final ArchRule NO_FORBIDDEN_CLASSES_CALLED =
Expand Down
13 changes: 5 additions & 8 deletions src/test/java/edu/hm/hafner/util/ArchitectureRulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ void shouldNotUseJsr305Annotations() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(
() -> ArchitectureRules.NO_FORBIDDEN_ANNOTATION_USED.check(
importClasses(ArchitectureRulesViolatedTest.class)))
.withMessageContainingAll("was violated (4 times)", "edu.umd.cs.findbugs.annotations",
"Field <edu.hm.hafner.util.ArchitectureRulesTest$ArchitectureRulesViolatedTest.empty> is annotated with <javax.annotation.Nonnull>",
.withMessageContainingAll("was violated (3 times)", "edu.umd.cs.findbugs.annotations",
"Field <edu.hm.hafner.util.ArchitectureRulesTest$ArchitectureRulesViolatedTest.noNullable> is annotated with <edu.umd.cs.findbugs.annotations.Nullable>",
"Method <edu.hm.hafner.util.ArchitectureRulesTest$ArchitectureRulesViolatedTest.method(java.lang.String)> is annotated with <javax.annotation.CheckForNull>",
"Parameter <java.lang.String> of method <edu.hm.hafner.util.ArchitectureRulesTest$ArchitectureRulesViolatedTest.method(java.lang.String)> is annotated with <javax.annotation.Nonnull>");
"Method <edu.hm.hafner.util.ArchitectureRulesTest$ArchitectureRulesViolatedTest.method(java.lang.String)> is annotated with <edu.umd.cs.findbugs.annotations.Nullable>",
"Parameter <java.lang.String> of method <edu.hm.hafner.util.ArchitectureRulesTest$ArchitectureRulesViolatedTest.method(java.lang.String)> is annotated with <edu.umd.cs.findbugs.annotations.Nullable>");

assertThatNoException().isThrownBy(
() -> ArchitectureRules.NO_FORBIDDEN_ANNOTATION_USED.check(importPassingClass()));
Expand Down Expand Up @@ -113,8 +112,6 @@ private JavaClasses importClasses(final Class<?>... classes) {

@SuppressWarnings("all") @Generated // This class is just there to be used in architecture tests
public static class ArchitectureRulesViolatedTest {
@javax.annotation.Nonnull
private final String empty = "";
@edu.umd.cs.findbugs.annotations.Nullable
private final String noNullable = null;

Expand All @@ -125,8 +122,8 @@ public void shouldFail() {
throw new IllegalArgumentException();
}

@javax.annotation.CheckForNull
protected String method(@javax.annotation.Nonnull String param) {
@edu.umd.cs.findbugs.annotations.Nullable
protected String method(@edu.umd.cs.findbugs.annotations.Nullable String param) {
return null;
}

Expand Down

0 comments on commit 8826fcc

Please sign in to comment.