Description of file/class
* * @author Stijn Dejongh - * @version $Id: $Id - * @created 18.10.20, Sunday */ public final class TextualAssertions { diff --git a/commons-testing/src/main/java/be/sddevelopment/commons/testing/annotations/WIP.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/annotations/WIP.java new file mode 100644 index 0000000..3f3b3e9 --- /dev/null +++ b/commons-testing/src/main/java/be/sddevelopment/commons/testing/annotations/WIP.java @@ -0,0 +1,37 @@ +/*- + * #%L + * commons-testing + * %% + * Copyright (C) 2020 - 2024 SD Development + * %% + * Licensed under the EUPL, Version 1.1 or – as soon they will be + * approved by the European Commission - subsequent versions of the + * EUPL (the "Licence"); + * + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * + * http://ec.europa.eu/idabc/eupl5 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * #L% + */ + +package be.sddevelopment.commons.testing.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.junit.jupiter.api.Disabled; + +@Disabled("Disabled: Work In Progress") +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface WIP { + +} diff --git a/commons-testing/src/main/java/be/sddevelopment/commons/testing/package-info.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/package-info.java index bc1b2c4..aafd4a2 100755 --- a/commons-testing/src/main/java/be/sddevelopment/commons/testing/package-info.java +++ b/commons-testing/src/main/java/be/sddevelopment/commons/testing/package-info.java @@ -22,9 +22,11 @@ */ /** - *Description of file/class
+ *+ * This module contains testing utilities included in the sddevelopment.be commons projects. + * It is intended to simplify the testing of other modules in java projects. + *
* * @author Stijn Dejongh - * @created 22.10.20, Thursday **/ package be.sddevelopment.commons.testing; 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 4934eae..dd45ba3 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 @@ -7,12 +7,12 @@ * Licensed under the EUPL, Version 1.1 or – as soon they will be * approved by the European Commission - subsequent versions of the * EUPL (the "Licence"); - * + * * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * http://ec.europa.eu/idabc/eupl5 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,18 +26,14 @@ import static be.sddevelopment.commons.testing.ReflectionAssertionUtils.assertPrivateMember; import static be.sddevelopment.commons.testing.ReflectionAssertionUtils.assertPrivateMemberReflectionProtection; -import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.assertj.core.api.WithAssertions; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class) -class ReflectionAssertionUtilsTest implements WithAssertions { +class ReflectionAssertionUtilsTest implements BaseTest { @Test void constructorIsPrivate() throws NoSuchMethodException { @@ -46,16 +42,21 @@ void constructorIsPrivate() throws NoSuchMethodException { @Test void constructorIsReflectionSafe() throws NoSuchMethodException { - assertPrivateMemberReflectionProtection(ReflectionAssertionUtils.class.getDeclaredConstructor()); + assertPrivateMemberReflectionProtection( + ReflectionAssertionUtils.class.getDeclaredConstructor()); } @Nested @DisplayName("Method: assertPrivateMember") class AssertPrivateMember { + @Test void passesWhenConstructorIsPrivate() throws NoSuchMethodException { var constructorToTest = ClassWithPrivateConstructor.class.getDeclaredConstructor(); - assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPrivate); + assertThat(constructorToTest) + .isNotNull() + .extracting(Constructor::getModifiers) + .matches(Modifier::isPrivate); ThrowingCallable assertion = () -> assertPrivateMember(constructorToTest); @@ -65,43 +66,61 @@ void passesWhenConstructorIsPrivate() throws NoSuchMethodException { @Test void failsWhenConstructorIsPublic() throws NoSuchMethodException { var constructorToTest = ClassWithPublicConstructor.class.getDeclaredConstructor(); - assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPublic); + assertThat(constructorToTest) + .isNotNull() + .extracting(Constructor::getModifiers) + .matches(Modifier::isPublic); ThrowingCallable assertion = () -> assertPrivateMember(constructorToTest); - assertThatCode(assertion).isInstanceOf(AssertionError.class).hasMessageContaining("is expected to be protected from illegal access"); + assertThatCode(assertion) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("is expected to be protected from illegal access"); } } @Nested @DisplayName("Method: assertPrivateMemberReflectionProtection") class AssertPrivateMemberReflectionProtection { + @Test void failsWhenConstructorIsPublic() throws NoSuchMethodException { var constructorToTest = ClassWithPublicConstructor.class.getDeclaredConstructor(); - assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPublic); + assertThat(constructorToTest) + .isNotNull() + .extracting(Constructor::getModifiers) + .matches(Modifier::isPublic); ThrowingCallable assertion = () -> assertPrivateMemberReflectionProtection(constructorToTest); - assertThatCode(assertion).isInstanceOf(AssertionError.class) - .hasMessageContaining("is expected to be protected from illegal access"); + assertThatCode(assertion) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("is expected to be protected from illegal access"); } @Test void failsWhenConstructorIsPrivateButNotReflectionSafe() throws NoSuchMethodException { var constructorToTest = ClassWithPrivateConstructor.class.getDeclaredConstructor(); - assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPrivate); + assertThat(constructorToTest) + .isNotNull() + .extracting(Constructor::getModifiers) + .matches(Modifier::isPrivate); ThrowingCallable assertion = () -> assertPrivateMemberReflectionProtection(constructorToTest); - assertThatCode(assertion).isNotNull().isInstanceOf(AssertionError.class) - .hasMessageContaining("is expected to be protected from illegal access"); + assertThatCode(assertion) + .isNotNull() + .isInstanceOf(AssertionError.class) + .hasMessageContaining("is expected to be protected from illegal access"); } @Test void passesWhenConstructorIsPrivateAndReflectionSafe() throws NoSuchMethodException { var constructorToTest = ClassWithReflectionSafeConstructor.class.getDeclaredConstructor(); - assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPrivate); + assertThat(constructorToTest) + .isNotNull() + .extracting(Constructor::getModifiers) + .matches(Modifier::isPrivate); ThrowingCallable assertion = () -> assertPrivateMemberReflectionProtection(constructorToTest); @@ -110,17 +129,21 @@ void passesWhenConstructorIsPrivateAndReflectionSafe() throws NoSuchMethodExcept } static final class ClassWithReflectionSafeConstructor { + private ClassWithReflectionSafeConstructor() { - throw new UnsupportedOperationException("Utility classes should not have a public or default constructor"); + throw new UnsupportedOperationException( + "Utility classes should not have a public or default constructor"); } } static final class ClassWithPrivateConstructor { + private ClassWithPrivateConstructor() { } } static final class ClassWithPublicConstructor { + public ClassWithPublicConstructor() { // Intentionally left empty to test the assertion } diff --git a/commons-testing/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java b/commons-testing/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java index 97ddaa1..67a30f7 100755 --- a/commons-testing/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java +++ b/commons-testing/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java @@ -41,8 +41,7 @@ * @version $Id: $Id */ @DisplayName("Test for AssertionUtils") -@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class) -class TextualAssertionsTest { +class TextualAssertionsTest implements BaseTest{ @Nested @DisplayName("Test with empty input") diff --git a/commons/pom.xml b/commons/pom.xml index 61a6d79..54d5fbc 100755 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -10,6 +10,12 @@