diff --git a/commons-testing/pom.xml b/commons-testing/pom.xml new file mode 100755 index 0000000..7ef2009 --- /dev/null +++ b/commons-testing/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + + be.sddevelopment + code-utils + 1.0.0-SNAPSHOT + + + commons-testing + + + + + org.projectlombok + lombok + compile + + + org.assertj + assertj-core + compile + + + org.junit.jupiter + junit-jupiter-api + compile + + + org.apache.commons + commons-lang3 + + + + + org.junit.jupiter + junit-jupiter-engine + test + + + com.tngtech.archunit + archunit-junit5-api + test + + + + \ No newline at end of file diff --git a/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java similarity index 90% rename from src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java rename to commons-testing/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java index 53934b1..94c307b 100755 --- a/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java +++ b/commons-testing/src/main/java/be/sddevelopment/commons/testing/ReflectionAssertionUtils.java @@ -24,10 +24,8 @@ package be.sddevelopment.commons.testing; import static java.lang.String.format; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import be.sddevelopment.commons.access.AccessProtectionUtils; -import be.sddevelopment.commons.access.Utility; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -50,11 +48,11 @@ * @created 25.03.21, Thursday * @since 1.0.0 */ -@Utility public final class ReflectionAssertionUtils { private ReflectionAssertionUtils() { - AccessProtectionUtils.utilityClassConstructor(); + throw new UnsupportedOperationException( + "Utility classes should not have a public or default constructor"); } public static void assertPrivateMemberReflectionProtection( diff --git a/src/main/java/be/sddevelopment/commons/testing/ReplaceUnderscoredCamelCasing.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/ReplaceUnderscoredCamelCasing.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/testing/ReplaceUnderscoredCamelCasing.java rename to commons-testing/src/main/java/be/sddevelopment/commons/testing/ReplaceUnderscoredCamelCasing.java diff --git a/src/main/java/be/sddevelopment/commons/testing/TextualAssertions.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/TextualAssertions.java similarity index 94% rename from src/main/java/be/sddevelopment/commons/testing/TextualAssertions.java rename to commons-testing/src/main/java/be/sddevelopment/commons/testing/TextualAssertions.java index b93c68f..2d1281d 100755 --- a/src/main/java/be/sddevelopment/commons/testing/TextualAssertions.java +++ b/commons-testing/src/main/java/be/sddevelopment/commons/testing/TextualAssertions.java @@ -26,8 +26,6 @@ import static org.apache.commons.lang3.StringUtils.isAlpha; import static org.assertj.core.api.Assertions.assertThat; -import be.sddevelopment.commons.access.AccessProtectionUtils; -import be.sddevelopment.commons.access.Utility; import java.util.Optional; import java.util.function.Supplier; import org.apache.commons.lang3.StringUtils; @@ -41,13 +39,13 @@ * @version $Id: $Id * @created 18.10.20, Sunday */ -@Utility public final class TextualAssertions { private static final String FIELD_NOT_EMPTY = "Field expected to not be empty"; private TextualAssertions() { - AccessProtectionUtils.utilityClassConstructor(); + throw new UnsupportedOperationException( + "Utility classes should not have a public or default constructor"); } @SuppressWarnings("OptionalGetWithoutIsPresent") diff --git a/src/main/java/be/sddevelopment/commons/testing/package-info.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/package-info.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/testing/package-info.java rename to commons-testing/src/main/java/be/sddevelopment/commons/testing/package-info.java diff --git a/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java b/commons-testing/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java similarity index 73% rename from src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java rename to commons-testing/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java index 956659f..b1cbf21 100755 --- a/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java +++ b/commons-testing/src/test/java/be/sddevelopment/commons/testing/TextualAssertionsTest.java @@ -27,7 +27,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import be.sddevelopment.commons.constants.Strings; import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; @@ -50,26 +49,34 @@ class EmptyInputTests { @Test void whenAssertingANumericalOptional_andTheStringIsEmpty_thenTheAssertFails() { - assertThatThrownBy(() -> TextualAssertions.assertThatNumber(this::emptyInputSupplier)).isInstanceOf(AssertionError.class).hasMessageContaining("to be numeric"); + assertThatThrownBy(() -> TextualAssertions.assertThatNumber(this::emptyInputSupplier)) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("to be numeric"); } @Test void whenAssertingAnAlphaNumericalOptional_andTheStringIsEmpty_thenTheAssertFails() { - assertThatThrownBy(() -> TextualAssertions.assertThatAlphanumeric(this::emptyInputSupplier)).isInstanceOf(AssertionError.class).hasMessageContaining("to be alphanumeric"); + assertThatThrownBy(() -> TextualAssertions.assertThatAlphanumeric(this::emptyInputSupplier)) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("to be alphanumeric"); } @Test void whenAssertingAnAlphaOptional_andTheStringIsEmpty_thenTheAssertFails() { - assertThatThrownBy(() -> TextualAssertions.assertThatAlpha(this::emptyInputSupplier)).isInstanceOf(AssertionError.class).hasMessageContaining("to be alphabetical"); + assertThatThrownBy(() -> TextualAssertions.assertThatAlpha(this::emptyInputSupplier)) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("to be alphabetical"); } @Test void whenAssertingAnEmptyInput_andTheStringIsEmpty_thenTheAssertFails() { - assertThatThrownBy(() -> TextualAssertions.assertEmpty(this::emptyInputSupplier)).isInstanceOf(AssertionError.class).hasMessageContaining("Expecting empty Optional"); + assertThatThrownBy(() -> TextualAssertions.assertEmpty(this::emptyInputSupplier)) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("Expecting empty Optional"); } private Optional emptyInputSupplier() { - return of(Strings.EMPTY_STRING); + return of(""); } } @@ -79,17 +86,23 @@ class NullInputTests { @Test void whenAssertingANumericalOptional_andTheInputIsNull_thenTheAssertFails() { - assertThatThrownBy(() -> TextualAssertions.assertThatAlphanumeric(Optional::empty)).isInstanceOf(AssertionError.class).hasMessageContaining("Field expected to not be empty"); + assertThatThrownBy(() -> TextualAssertions.assertThatAlphanumeric(Optional::empty)) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("Field expected to not be empty"); } @Test void whenAssertingAnAlphaNumericalOptional_andTheInputIsNull_thenTheAssertFails() { - assertThatThrownBy(() -> TextualAssertions.assertThatAlphanumeric(Optional::empty)).isInstanceOf(AssertionError.class).hasMessageContaining("Field expected to not be empty"); + assertThatThrownBy(() -> TextualAssertions.assertThatAlphanumeric(Optional::empty)) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("Field expected to not be empty"); } @Test void whenAssertingAnAlphaOptional_andTheInputIsNull_thenTheAssertFails() { - assertThatThrownBy(() -> TextualAssertions.assertThatAlpha(Optional::empty)).isInstanceOf(AssertionError.class).hasMessageContaining("Field expected to not be empty"); + assertThatThrownBy(() -> TextualAssertions.assertThatAlpha(Optional::empty)) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("Field expected to not be empty"); } } @@ -99,17 +112,20 @@ class CorrectInputTests { @Test void whenAssertingANumericalOptional_andTheInputContainsOnlyDigits_thenTheAssertFails() { - assertThatCode(() -> TextualAssertions.assertThatNumber(() -> of("1000290"))).doesNotThrowAnyException(); + assertThatCode( + () -> TextualAssertions.assertThatNumber(() -> of("1000290"))).doesNotThrowAnyException(); } @Test void whenAssertingAnAlphaNumericalOptional_andTheInputContainsLettersAndDigits_thenTheAssertFails() { - assertThatCode(() -> TextualAssertions.assertThatAlphanumeric(() -> of("abcd123jajaja"))).doesNotThrowAnyException(); + assertThatCode(() -> TextualAssertions.assertThatAlphanumeric( + () -> of("abcd123jajaja"))).doesNotThrowAnyException(); } @Test void whenAssertingAnAlphaOptional_andTheInputIsNull_thenTheAssertFails() { - assertThatCode(() -> TextualAssertions.assertThatAlpha(() -> of("aaaaahjhjahzjahzjahzjahzj"))).doesNotThrowAnyException(); + assertThatCode(() -> TextualAssertions.assertThatAlpha( + () -> of("aaaaahjhjahzjahzjahzjahzj"))).doesNotThrowAnyException(); } } diff --git a/commons/pom.xml b/commons/pom.xml new file mode 100755 index 0000000..c6deaf6 --- /dev/null +++ b/commons/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + + be.sddevelopment + code-utils + 1.0.0-SNAPSHOT + + + commons + + + + + org.projectlombok + lombok + ${lombok.version} + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + + + com.tngtech.archunit + archunit-junit5-api + ${archunit.version} + test + + + be.sddevelopment + commons-testing + ${parent.version} + + + + + \ No newline at end of file diff --git a/src/main/java/be/sddevelopment/commons/access/AccessProtectionUtils.java b/commons/src/main/java/be/sddevelopment/commons/access/AccessProtectionUtils.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/access/AccessProtectionUtils.java rename to commons/src/main/java/be/sddevelopment/commons/access/AccessProtectionUtils.java diff --git a/src/main/java/be/sddevelopment/commons/access/Utility.java b/commons/src/main/java/be/sddevelopment/commons/access/Utility.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/access/Utility.java rename to commons/src/main/java/be/sddevelopment/commons/access/Utility.java diff --git a/src/main/java/be/sddevelopment/commons/constants/Strings.java b/commons/src/main/java/be/sddevelopment/commons/constants/Strings.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/constants/Strings.java rename to commons/src/main/java/be/sddevelopment/commons/constants/Strings.java diff --git a/src/main/java/be/sddevelopment/commons/exceptions/ExceptionSuppressor.java b/commons/src/main/java/be/sddevelopment/commons/exceptions/ExceptionSuppressor.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/exceptions/ExceptionSuppressor.java rename to commons/src/main/java/be/sddevelopment/commons/exceptions/ExceptionSuppressor.java diff --git a/src/main/java/be/sddevelopment/commons/exceptions/FallibleFunction.java b/commons/src/main/java/be/sddevelopment/commons/exceptions/FallibleFunction.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/exceptions/FallibleFunction.java rename to commons/src/main/java/be/sddevelopment/commons/exceptions/FallibleFunction.java diff --git a/src/main/java/be/sddevelopment/commons/exceptions/WrappedException.java b/commons/src/main/java/be/sddevelopment/commons/exceptions/WrappedException.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/exceptions/WrappedException.java rename to commons/src/main/java/be/sddevelopment/commons/exceptions/WrappedException.java diff --git a/src/main/java/be/sddevelopment/commons/exceptions/package-info.java b/commons/src/main/java/be/sddevelopment/commons/exceptions/package-info.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/exceptions/package-info.java rename to commons/src/main/java/be/sddevelopment/commons/exceptions/package-info.java diff --git a/src/main/java/be/sddevelopment/commons/validation/ErrorTemplate.java b/commons/src/main/java/be/sddevelopment/commons/validation/ErrorTemplate.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/ErrorTemplate.java rename to commons/src/main/java/be/sddevelopment/commons/validation/ErrorTemplate.java diff --git a/src/main/java/be/sddevelopment/commons/validation/Failure.java b/commons/src/main/java/be/sddevelopment/commons/validation/Failure.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/Failure.java rename to commons/src/main/java/be/sddevelopment/commons/validation/Failure.java diff --git a/src/main/java/be/sddevelopment/commons/validation/FailureBuilderClause.java b/commons/src/main/java/be/sddevelopment/commons/validation/FailureBuilderClause.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/FailureBuilderClause.java rename to commons/src/main/java/be/sddevelopment/commons/validation/FailureBuilderClause.java diff --git a/src/main/java/be/sddevelopment/commons/validation/Fallible.java b/commons/src/main/java/be/sddevelopment/commons/validation/Fallible.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/Fallible.java rename to commons/src/main/java/be/sddevelopment/commons/validation/Fallible.java diff --git a/src/main/java/be/sddevelopment/commons/validation/FieldValidationRule.java b/commons/src/main/java/be/sddevelopment/commons/validation/FieldValidationRule.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/FieldValidationRule.java rename to commons/src/main/java/be/sddevelopment/commons/validation/FieldValidationRule.java diff --git a/src/main/java/be/sddevelopment/commons/validation/Rule.java b/commons/src/main/java/be/sddevelopment/commons/validation/Rule.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/Rule.java rename to commons/src/main/java/be/sddevelopment/commons/validation/Rule.java diff --git a/src/main/java/be/sddevelopment/commons/validation/Severity.java b/commons/src/main/java/be/sddevelopment/commons/validation/Severity.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/Severity.java rename to commons/src/main/java/be/sddevelopment/commons/validation/Severity.java diff --git a/src/main/java/be/sddevelopment/commons/validation/ValidationRule.java b/commons/src/main/java/be/sddevelopment/commons/validation/ValidationRule.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/ValidationRule.java rename to commons/src/main/java/be/sddevelopment/commons/validation/ValidationRule.java diff --git a/src/main/java/be/sddevelopment/commons/validation/package-info.java b/commons/src/main/java/be/sddevelopment/commons/validation/package-info.java similarity index 100% rename from src/main/java/be/sddevelopment/commons/validation/package-info.java rename to commons/src/main/java/be/sddevelopment/commons/validation/package-info.java diff --git a/src/main/javadoc/stylesheet.css b/commons/src/main/javadoc/stylesheet.css similarity index 100% rename from src/main/javadoc/stylesheet.css rename to commons/src/main/javadoc/stylesheet.css diff --git a/src/test/java/be/sddevelopment/commons/access/AccessProtectionUtilsTest.java b/commons/src/test/java/be/sddevelopment/commons/access/AccessProtectionUtilsTest.java similarity index 95% rename from src/test/java/be/sddevelopment/commons/access/AccessProtectionUtilsTest.java rename to commons/src/test/java/be/sddevelopment/commons/access/AccessProtectionUtilsTest.java index f0b30de..0727ad9 100755 --- a/src/test/java/be/sddevelopment/commons/access/AccessProtectionUtilsTest.java +++ b/commons/src/test/java/be/sddevelopment/commons/access/AccessProtectionUtilsTest.java @@ -56,12 +56,14 @@ void setUp() throws ClassNotFoundException { */ @Test void givenAUtilityClassWithAPrivateDefaultConstructor_whenInstantiatingAndOverwritingAccessModifier_anExceptionIsThrown() { - ReflectionAssertionUtils.assertPrivateMemberReflectionProtection(classToTest.getDeclaredConstructors()[0]); + ReflectionAssertionUtils.assertPrivateMemberReflectionProtection( + classToTest.getDeclaredConstructors()[0]); } @Test void givenAUtilityClassWithAPrivateConstructor_whenInstantiating_anIllegalExceptionIsThrown() { - assertThatThrownBy(() -> classToTest.getDeclaredConstructor().newInstance()).isInstanceOf(IllegalAccessException.class); + assertThatThrownBy(() -> classToTest.getDeclaredConstructor().newInstance()).isInstanceOf( + IllegalAccessException.class); } private Class utilityClass() throws ClassNotFoundException { diff --git a/src/test/java/be/sddevelopment/commons/access/UtilityClass.java b/commons/src/test/java/be/sddevelopment/commons/access/UtilityClass.java similarity index 100% rename from src/test/java/be/sddevelopment/commons/access/UtilityClass.java rename to commons/src/test/java/be/sddevelopment/commons/access/UtilityClass.java diff --git a/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java b/commons/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java similarity index 70% rename from src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java rename to commons/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java index 712c27a..0142177 100755 --- a/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java +++ b/commons/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java @@ -61,9 +61,10 @@ @DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class) class ExceptionSuppressorTest { - public final Condition messageOfOriginalException = new Condition<>(c -> org.apache.commons.lang3.StringUtils.equalsIgnoreCase(c.getMessage(), TestMethods.EXCEPTION_MESSAGE), - "Precondition: Throwable contains the original exception message" - ); + public final Condition messageOfOriginalException = new Condition<>( + c -> org.apache.commons.lang3.StringUtils.equalsIgnoreCase(c.getMessage(), + TestMethods.EXCEPTION_MESSAGE + ), "Precondition: Throwable contains the original exception message"); private static final class TestMethods { @@ -82,14 +83,18 @@ static String throwExceptionIfNotBLank(String url) throws MalformedURLException @Test void whenAnExceptionIsSuppressed_usingDefaultSupress_thenChainInterpretsItAsEmptyResult() { - Optional result = Optional.of(Strings.NON_EMPTY_STRING).map(ignore(TestMethods::throwExceptionIfNotBLank)); + Optional result = Optional + .of(Strings.NON_EMPTY_STRING) + .map(ignore(TestMethods::throwExceptionIfNotBLank)); assertThat(result).isNotPresent(); } @Test void whenAnExceptionIsNotSuppressed_usingDefaultSupress_thenChainUsesMethodReturnObject() { - Optional result = Optional.of(EMPTY_STRING).map(ignore(TestMethods::throwExceptionIfNotBLank)); + Optional result = Optional + .of(EMPTY_STRING) + .map(ignore(TestMethods::throwExceptionIfNotBLank)); assertThat(result).contains(TestMethods.NO_THROW); } @@ -97,16 +102,26 @@ void whenAnExceptionIsNotSuppressed_usingDefaultSupress_thenChainUsesMethodRetur @Test void whenAnExceptionIsSupressed_ByConvertingToRuntime_thenItIsThrown() { Optional nonEmptyString = Optional.of(Strings.NON_EMPTY_STRING); - assertThatThrownBy(() -> nonEmptyString.map(ExceptionSuppressor.uncheck(TestMethods::throwExceptionIfNotBLank))).isInstanceOf(WrappedException.class).hasCauseInstanceOf(MalformedURLException.class); + assertThatThrownBy(() -> nonEmptyString.map( + ExceptionSuppressor.uncheck(TestMethods::throwExceptionIfNotBLank))) + .isInstanceOf(WrappedException.class) + .hasCauseInstanceOf(MalformedURLException.class); } @Test void whenAnExceptionIsSupressed_ByConvertingToRuntime_thenTheThrownExceptionContainsTheOriginalOne() { - assertThatThrownBy(() -> Optional.of(Strings.NON_EMPTY_STRING).map(ExceptionSuppressor.uncheck(TestMethods::throwExceptionIfNotBLank))).satisfies(messageOfOriginalException); + assertThatThrownBy(() -> Optional + .of(Strings.NON_EMPTY_STRING) + .map(ExceptionSuppressor.uncheck( + TestMethods::throwExceptionIfNotBLank))).satisfies( + messageOfOriginalException); } @Test void whenAnExceptionIsSupressed_usingIgnoreAsOptional_givenAMethodThatThrowsAnException_TheResultIsAnEmptyOptional() { - assertThat(Optional.of(Strings.NON_EMPTY_STRING).flatMap(ExceptionSuppressor.ignoreAsOptional(TestMethods::throwExceptionIfNotBLank))).isEmpty(); + assertThat(Optional + .of(Strings.NON_EMPTY_STRING) + .flatMap(ExceptionSuppressor.ignoreAsOptional( + TestMethods::throwExceptionIfNotBLank))).isEmpty(); } } diff --git a/src/test/java/be/sddevelopment/commons/validation/FallibleTest.java b/commons/src/test/java/be/sddevelopment/commons/validation/FallibleTest.java similarity index 100% rename from src/test/java/be/sddevelopment/commons/validation/FallibleTest.java rename to commons/src/test/java/be/sddevelopment/commons/validation/FallibleTest.java diff --git a/src/test/java/be/sddevelopment/commons/validation/ValidationToolsUsageTest.java b/commons/src/test/java/be/sddevelopment/commons/validation/ValidationToolsUsageTest.java similarity index 50% rename from src/test/java/be/sddevelopment/commons/validation/ValidationToolsUsageTest.java rename to commons/src/test/java/be/sddevelopment/commons/validation/ValidationToolsUsageTest.java index 3b6fb07..eba0961 100755 --- a/src/test/java/be/sddevelopment/commons/validation/ValidationToolsUsageTest.java +++ b/commons/src/test/java/be/sddevelopment/commons/validation/ValidationToolsUsageTest.java @@ -60,25 +60,58 @@ private static class EmailContact { @Test void asADeveloper_givenADataClass_IWantToValidateItsContentsAndDisplayErrors() { - EmailContact toValidate = EmailContact.builder().email("Invalid Format").name("Bob").lastName("The Buider").userIdentifier(UUID.randomUUID()).build(); + EmailContact toValidate = EmailContact + .builder() + .email("Invalid Format") + .name("Bob") + .lastName("The Buider") + .userIdentifier(UUID.randomUUID()) + .build(); Fallible toBeValid = Fallible .of(toValidate) - .ensure(emailContact -> Optional.of(emailContact).map(EmailContact::getEmail).map(mail -> StringUtils.containsIgnoreCase("invalid", mail)).orElse(false), - emailContact -> failureBuilder -> failureBuilder.errorCode("ERROR").reason("email should not contain invalid atoms").severity(Severity.ERROR) + .ensure(emailContact -> Optional + .of(emailContact) + .map(EmailContact::getEmail) + .map( + mail -> StringUtils.containsIgnoreCase( + "invalid", mail)) + .orElse(false), + emailContact -> failureBuilder -> failureBuilder + .errorCode( + "ERROR") + .reason( + "email should not contain invalid atoms") + .severity( + Severity.ERROR) ); Fallible redesigned = Fallible .of(toValidate) .ensure(field(EmailContact::getEmail) .compliesTo(Objects::nonNull) - .andTo(mail -> StringUtils.containsIgnoreCase("invalid", mail)) - .elseFail(FailureBuilderClause.withCode("ERROR").andReason("email should not contain invalid atoms").andSeverity(Severity.ERROR))); + .andTo( + mail -> StringUtils.containsIgnoreCase( + "invalid", mail)) + .elseFail(FailureBuilderClause + .withCode("ERROR") + .andReason( + "email should not contain invalid atoms") + .andSeverity( + Severity.ERROR))); Assertions.assertThat(toBeValid.isValid()).isFalse(); - Assertions.assertThat(toBeValid.failures()).extracting(Failure::getErrorCode, Failure::getReason, Failure::getSeverity).containsExactlyInAnyOrder(Tuple.tuple("ERROR", "email should not contain invalid atoms", Severity.ERROR)); + Assertions + .assertThat(toBeValid.failures()) + .extracting(Failure::getErrorCode, Failure::getReason, Failure::getSeverity) + .containsExactlyInAnyOrder( + Tuple.tuple("ERROR", "email should not contain invalid atoms", Severity.ERROR)); Assertions.assertThat(redesigned.isValid()).isFalse(); - Assertions.assertThat(redesigned.failures()).extracting(Failure::getErrorCode, Failure::getReason, Failure::getSeverity).containsExactlyInAnyOrder(Tuple.tuple("ERROR", "email should not contain invalid atoms", Severity.ERROR)); + Assertions + .assertThat(redesigned.failures()) + .extracting(Failure::getErrorCode, Failure::getReason, Failure::getSeverity) + .containsExactlyInAnyOrder( + Tuple.tuple("ERROR", "email should not contain invalid atoms", Severity.ERROR)); } } diff --git a/pom.xml b/pom.xml index 1cbed63..66ab875 100755 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ be.sddevelopment code-utils 1.0.0-SNAPSHOT + pom A set of tools and utility classes, aimed at making it easier for developers to write their code @@ -23,6 +24,10 @@ + + commons + commons-testing + sddevelopment-be @@ -56,47 +61,48 @@ - - - - org.projectlombok - lombok - ${lombok.version} - compile - - - org.apache.commons - commons-lang3 - 3.12.0 - - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.junit.jupiter - junit-jupiter-api - ${junit.jupiter.version} - - - com.tngtech.archunit - archunit-junit5-api - ${archunit.version} - test - - + + + + + org.projectlombok + lombok + ${lombok.version} + compile + + + org.apache.commons + commons-lang3 + 3.15.0 + - + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + + + com.tngtech.archunit + archunit-junit5-api + ${archunit.version} + test + + + + @@ -125,7 +131,7 @@ 3.5.0 maven - src/main/javadoc + commons/src/main/javadoc /styles/stylesheet.css @@ -138,7 +144,7 @@ 1.18.20.0 UTF-8 - ${project.basedir}/src/main/java + commons/src/main/java