diff --git a/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java b/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java index d62a34e80d..ad13fb57db 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java @@ -87,7 +87,7 @@ public String getRelativeName() { @PublicAPI(usage = ACCESS) public HasAnnotations getPackageInfo() { return tryGetPackageInfo().getOrThrow( - new IllegalArgumentException(String.format("Package %s does not contain a package-info.java", getName()))); + new IllegalArgumentException(String.format("%s does not contain a package-info.java", getDescription()))); } @PublicAPI(usage = ACCESS) @@ -114,7 +114,7 @@ public A getAnnotationOfType(Class type) { @PublicAPI(usage = ACCESS) public JavaAnnotation getAnnotationOfType(String typeName) { return tryGetAnnotationOfType(typeName).getOrThrow(new IllegalArgumentException( - String.format("Package %s is not annotated with @%s", getName(), typeName))); + String.format("%s is not annotated with @%s", getDescription(), typeName))); } @Override diff --git a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaPackageTest.java b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaPackageTest.java index 7b4c21845f..25028e314f 100644 --- a/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaPackageTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/core/domain/JavaPackageTest.java @@ -328,43 +328,45 @@ public void has_package_dependencies_from_other_packages() { @Test public void test_getPackageInfo() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - final JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + final JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); assertThat(annotatedPackage.getPackageInfo()).isNotNull(); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() { - notAnnotatedPackage.getPackageInfo(); + nonAnnotatedPackage.getPackageInfo(); } - }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(".packageexamples does not contain a package-info.java"); + }) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(nonAnnotatedPackage.getDescription() + " does not contain a package-info.java"); } @Test public void test_tryGetPackageInfo() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); assertThat(annotatedPackage.tryGetPackageInfo()).isPresent(); - assertThat(notAnnotatedPackage.tryGetPackageInfo()).isAbsent(); + assertThat(nonAnnotatedPackage.tryGetPackageInfo()).isAbsent(); } @Test public void test_getAnnotations() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); JavaAnnotation annotation = getOnlyElement(annotatedPackage.getAnnotations()); assertThat(annotation.getRawType()).matches(PackageLevelAnnotation.class); assertThat(annotation.getOwner()).isEqualTo(annotatedPackage); - assertThat(notAnnotatedPackage.getAnnotations()).isEmpty(); + assertThat(nonAnnotatedPackage.getAnnotations()).isEmpty(); } @Test public void test_getAnnotationOfType_type() { final JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - final JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + final JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); assertThat(annotatedPackage.getAnnotationOfType(PackageLevelAnnotation.class)).isInstanceOf(PackageLevelAnnotation.class); @@ -373,94 +375,95 @@ public void test_getAnnotationOfType_type() { public void call() { annotatedPackage.getAnnotationOfType(Deprecated.class); } - }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(".packageexamples.annotated is not annotated with @"); + }).isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(annotatedPackage.getDescription() + " is not annotated with @" + Deprecated.class.getName()); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() { - notAnnotatedPackage.getAnnotationOfType(Deprecated.class); + nonAnnotatedPackage.getAnnotationOfType(Deprecated.class); } - }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(".packageexamples is not annotated with @"); + }).isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(nonAnnotatedPackage.getDescription() + " is not annotated with @" + Deprecated.class.getName()); } @Test public void test_getAnnotationOfType_typeName() { final JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - final JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + final JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); - assertThat(annotatedPackage.getAnnotationOfType("com.tngtech.archunit.core.domain.packageexamples.annotated.PackageLevelAnnotation") + assertThat(annotatedPackage.getAnnotationOfType(PackageLevelAnnotation.class.getName()) .getRawType()).matches(PackageLevelAnnotation.class); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() { - annotatedPackage.getAnnotationOfType("java.lang.Deprecated"); + annotatedPackage.getAnnotationOfType("not.There"); } - }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(".packageexamples.annotated is not annotated with @"); + }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(annotatedPackage.getDescription() + " is not annotated with @not.There"); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() { - notAnnotatedPackage.getAnnotationOfType("java.lang.Deprecated"); + nonAnnotatedPackage.getAnnotationOfType("not.There"); } - }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(".packageexamples is not annotated with @"); + }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(nonAnnotatedPackage.getDescription() + " is not annotated with @not.There"); } @Test public void test_tryGetAnnotationOfType_type() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); assertThat(annotatedPackage.tryGetAnnotationOfType(PackageLevelAnnotation.class)).isPresent(); assertThat(annotatedPackage.tryGetAnnotationOfType(Deprecated.class)).isAbsent(); - assertThat(notAnnotatedPackage.tryGetAnnotationOfType(Deprecated.class)).isAbsent(); + assertThat(nonAnnotatedPackage.tryGetAnnotationOfType(Deprecated.class)).isAbsent(); } @Test public void test_tryGetAnnotationOfType_typeName() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); - assertThat(annotatedPackage.tryGetAnnotationOfType( - "com.tngtech.archunit.core.domain.packageexamples.annotated.PackageLevelAnnotation")).isPresent(); - assertThat(annotatedPackage.tryGetAnnotationOfType("java.lang.Deprecated")).isAbsent(); + assertThat(annotatedPackage.tryGetAnnotationOfType(PackageLevelAnnotation.class.getName())).isPresent(); + assertThat(annotatedPackage.tryGetAnnotationOfType(Deprecated.class.getName())).isAbsent(); - assertThat(notAnnotatedPackage.tryGetAnnotationOfType("java.lang.Deprecated")).isAbsent(); + assertThat(nonAnnotatedPackage.tryGetAnnotationOfType(Deprecated.class.getName())).isAbsent(); } @Test public void test_isAnnotatedWith_type() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); assertThat(annotatedPackage.isAnnotatedWith(PackageLevelAnnotation.class)).isTrue(); assertThat(annotatedPackage.isAnnotatedWith(Deprecated.class)).isFalse(); - assertThat(notAnnotatedPackage.isAnnotatedWith(Deprecated.class)).isFalse(); + assertThat(nonAnnotatedPackage.isAnnotatedWith(Deprecated.class)).isFalse(); } @Test public void test_isAnnotatedWith_typeName() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); - assertThat(annotatedPackage.isAnnotatedWith("com.tngtech.archunit.core.domain.packageexamples.annotated.PackageLevelAnnotation")).isTrue(); - assertThat(annotatedPackage.isAnnotatedWith("java.lang.Deprecated")).isFalse(); + assertThat(annotatedPackage.isAnnotatedWith(PackageLevelAnnotation.class.getName())).isTrue(); + assertThat(annotatedPackage.isAnnotatedWith(Deprecated.class.getName())).isFalse(); - assertThat(notAnnotatedPackage.isAnnotatedWith("java.lang.Deprecated")).isFalse(); + assertThat(nonAnnotatedPackage.isAnnotatedWith(Deprecated.class.getName())).isFalse(); } @Test public void test_isAnnotatedWith_predicate() { JavaPackage annotatedPackage = importPackage("packageexamples.annotated"); - JavaPackage notAnnotatedPackage = importPackage("packageexamples"); + JavaPackage nonAnnotatedPackage = importPackage("packageexamples"); assertThat(annotatedPackage.isAnnotatedWith(DescribedPredicate.>alwaysTrue())).isTrue(); assertThat(annotatedPackage.isAnnotatedWith(DescribedPredicate.>alwaysFalse())).isFalse(); - assertThat(notAnnotatedPackage.isAnnotatedWith(DescribedPredicate.>alwaysTrue())).isFalse(); - assertThat(notAnnotatedPackage.isAnnotatedWith(DescribedPredicate.>alwaysFalse())).isFalse(); + assertThat(nonAnnotatedPackage.isAnnotatedWith(DescribedPredicate.>alwaysTrue())).isFalse(); + assertThat(nonAnnotatedPackage.isAnnotatedWith(DescribedPredicate.>alwaysFalse())).isFalse(); } @Test