From 8826fcc351959f67906fe42bfb9e75f089d77a0f Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Thu, 12 Sep 2024 14:21:31 +0200 Subject: [PATCH] Do not use javax package in tests. --- src/main/java/edu/hm/hafner/util/Generated.java | 4 ++-- .../java/edu/hm/hafner/util/ArchitectureRules.java | 2 +- .../edu/hm/hafner/util/ArchitectureRulesTest.java | 13 +++++-------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/hm/hafner/util/Generated.java b/src/main/java/edu/hm/hafner/util/Generated.java index 83a27f24..9073ba0b 100644 --- a/src/main/java/edu/hm/hafner/util/Generated.java +++ b/src/main/java/edu/hm/hafner/util/Generated.java @@ -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). */ diff --git a/src/test/java/edu/hm/hafner/util/ArchitectureRules.java b/src/test/java/edu/hm/hafner/util/ArchitectureRules.java index 090e3043..67b12e55 100644 --- a/src/test/java/edu/hm/hafner/util/ArchitectureRules.java +++ b/src/test/java/edu/hm/hafner/util/ArchitectureRules.java @@ -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 = diff --git a/src/test/java/edu/hm/hafner/util/ArchitectureRulesTest.java b/src/test/java/edu/hm/hafner/util/ArchitectureRulesTest.java index dc0da9d1..5015d16d 100644 --- a/src/test/java/edu/hm/hafner/util/ArchitectureRulesTest.java +++ b/src/test/java/edu/hm/hafner/util/ArchitectureRulesTest.java @@ -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 is annotated with ", + .withMessageContainingAll("was violated (3 times)", "edu.umd.cs.findbugs.annotations", "Field is annotated with ", - "Method is annotated with ", - "Parameter of method is annotated with "); + "Method is annotated with ", + "Parameter of method is annotated with "); assertThatNoException().isThrownBy( () -> ArchitectureRules.NO_FORBIDDEN_ANNOTATION_USED.check(importPassingClass())); @@ -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; @@ -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; }