From 9df532db164587f3320658c7d71f2fe21eae3a4d Mon Sep 17 00:00:00 2001 From: Stijn Dejongh Date: Sun, 22 Sep 2024 15:06:09 +0200 Subject: [PATCH] Sonar indicated issues --- .../commons/testing/ReflectionAssertionUtils.java | 9 ++++----- .../commons/testing/ReflectionAssertionUtilsTest.java | 1 + .../sddevelopment/commons/validation/FallibleTest.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commons-testing/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java index 4054d00..675b708 100755 --- a/commons-testing/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java +++ b/commons-testing/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java @@ -54,11 +54,10 @@ public final class ReflectionAssertionUtils { "Utility classes should not have a public or default constructor"; private ReflectionAssertionUtils() { - throw new UnsupportedOperationException("Utility classes should not have a public or default constructor"); + throw new UnsupportedOperationException(PROHIBITED_CONSTRUCTOR_ACCESS); } - public static void assertPrivateMemberReflectionProtection( - @SuppressWarnings("rawtypes") final Constructor constructor) { + public static void assertPrivateMemberReflectionProtection(final Constructor constructor) { constructor.setAccessible(true); assertThatThrownBy(constructor::newInstance, unprotectedConstructorError(constructor)) @@ -68,12 +67,12 @@ public static void assertPrivateMemberReflectionProtection( } public static void assertPrivateMember( - @SuppressWarnings("rawtypes") final Constructor constructor) { + @SuppressWarnings("rawtypes") final Constructor constructor) { assertThatThrownBy(constructor::newInstance, unprotectedConstructorError(constructor)) .isInstanceOfAny(InvocationTargetException.class, IllegalAccessException.class); } - private static String unprotectedConstructorError(final Constructor constructor) { + private static String unprotectedConstructorError(final Constructor constructor) { return format("Constructor %s is expected to be protected from illegal access", constructor); } } diff --git a/commons-testing/src/test/java/be/sddevelopment/commons/testing/ReflectionAssertionUtilsTest.java b/commons-testing/src/test/java/be/sddevelopment/commons/testing/ReflectionAssertionUtilsTest.java index 3f9a32c..dc8bd2e 100755 --- a/commons-testing/src/test/java/be/sddevelopment/commons/testing/ReflectionAssertionUtilsTest.java +++ b/commons-testing/src/test/java/be/sddevelopment/commons/testing/ReflectionAssertionUtilsTest.java @@ -119,6 +119,7 @@ private ClassWithPrivateConstructor() { static final class ClassWithPublicConstructor { public ClassWithPublicConstructor() { + // Intentionally left empty to test the assertion } } diff --git a/commons/src/test/java/be/sddevelopment/commons/validation/FallibleTest.java b/commons/src/test/java/be/sddevelopment/commons/validation/FallibleTest.java index f06bef4..ad97758 100755 --- a/commons/src/test/java/be/sddevelopment/commons/validation/FallibleTest.java +++ b/commons/src/test/java/be/sddevelopment/commons/validation/FallibleTest.java @@ -44,7 +44,7 @@ @DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class) class FallibleTest { - public final List NAUGHTY_WORDS = singletonList("string"); + public static final List NAUGHTY_WORDS = singletonList("string"); public static final String NAUGHTY_ERROR = "Your word seems to contain a naughty bit [%s]"; static class ConsumerServiceStub {