diff --git a/commons-testing/pom.xml b/commons-testing/pom.xml index 33b2745..d3da9eb 100755 --- a/commons-testing/pom.xml +++ b/commons-testing/pom.xml @@ -58,11 +58,16 @@ archunit-junit5-engine ${archunit.version} + + org.junit.jupiter + junit-jupiter-engine + test + org.junit.jupiter - junit-jupiter-engine + junit-jupiter-params test diff --git a/commons-testing/src/main/java/be/sddevelopment/commons/testing/naming/ReplaceUnderscoredCamelCasing.java b/commons-testing/src/main/java/be/sddevelopment/commons/testing/naming/ReplaceUnderscoredCamelCasing.java index 0e6a165..ca743b6 100755 --- a/commons-testing/src/main/java/be/sddevelopment/commons/testing/naming/ReplaceUnderscoredCamelCasing.java +++ b/commons-testing/src/main/java/be/sddevelopment/commons/testing/naming/ReplaceUnderscoredCamelCasing.java @@ -66,14 +66,10 @@ public String generateDisplayNameForMethod(Class testClass, Method testMethod return this.replaceCapitals(super.generateDisplayNameForMethod(testClass, testMethod)); } - private String replaceCapitals(String name) { - name = name.replaceAll("([A-Z])", " $1").toLowerCase(); + String replaceCapitals(String name) { + name = name.replaceAll("([A-Z])", " $1"); name = name.replaceAll("(\\d+)", " $1"); - name = name.replace("given", "GIVEN"); - name = name.replace("when", "WHEN"); - name = name.replace("then", "THEN"); - name = name.replace("and", "AND"); - return name; + return name.toLowerCase(); } } diff --git a/commons-testing/src/test/java/be/sddevelopment/commons/testing/naming/ReplaceUnderscoredCamelCasingTest.java b/commons-testing/src/test/java/be/sddevelopment/commons/testing/naming/ReplaceUnderscoredCamelCasingTest.java new file mode 100644 index 0000000..2946b22 --- /dev/null +++ b/commons-testing/src/test/java/be/sddevelopment/commons/testing/naming/ReplaceUnderscoredCamelCasingTest.java @@ -0,0 +1,58 @@ +/*- + * #%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.naming; + +import static org.junit.jupiter.params.provider.Arguments.of; + +import java.util.stream.Stream; +import org.assertj.core.api.WithAssertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +@DisplayName("Replace Underscored Camel Casing TestCase naming") +class ReplaceUnderscoredCamelCasingTest implements WithAssertions { + + private final ReplaceUnderscoredCamelCasing toTest = new ReplaceUnderscoredCamelCasing(); + + @ParameterizedTest + @MethodSource("methodNamesForValidation") + void replacesUnderscoresWithSpaces(String input, String expected) { + assertThat(input).isNotBlank(); + + var result = toTest.replaceCapitals(input); + + assertThat(result).isEqualTo(expected); + } + + public static Stream methodNamesForValidation() { + return Stream.of( + of("canHandleEmptyDataSets", "can handle empty data sets"), + of("parsingRequiresAtLeastAHeaderLine", "parsing requires at least a header line"), + of("whenAnExceptionIsSuppressedUsingDefaultSuppressionThenChainInterpretsItAsEmptyResult", "when an exception is suppressed using default suppression then chain interprets it as empty result"), + of("insultsYouGivenFileWithDataAndYourMum", "insults you given file with data and your mum") + ); + } +} diff --git a/commons/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java b/commons/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java index b1293c4..cbf28b0 100755 --- a/commons/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java +++ b/commons/src/test/java/be/sddevelopment/commons/exceptions/ExceptionSuppressorTest.java @@ -82,7 +82,7 @@ static String throwExceptionIfNotBLank(String url) throws MalformedURLException } @Test - void whenAnExceptionIsSuppressed_usingDefaultSupress_thenChainInterpretsItAsEmptyResult() { + void whenAnExceptionIsSuppressed_usingDefaultSuppression_thenChainInterpretsItAsEmptyResult() { Optional result = Optional .of(Strings.NON_EMPTY_STRING) .map(ignore(TestMethods::throwExceptionIfNotBLank)); diff --git a/pom.xml b/pom.xml index 4324dd5..2d26e3c 100755 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,11 @@ archunit-junit5-engine ${archunit.version} + + org.junit.jupiter + junit-jupiter-params + ${junit.jupiter.version} +