diff options
| author | Paul-Christian Volkmer | 2026-09-03 14:35:10 +0200 |
|---|---|---|
| committer | GitHub | 2026-09-03 14:35:10 +0200 |
| commit | fb91356b7777dfa5b6088bcc3a48b43924c1c0fd (patch) | |
| tree | a3d384390e388395953865a286f15292aaa04a86 /src/test/java/dev/dnpm/oshelper/analyzer/AnalyzerUtilsTest.java | |
| parent | 59daf77a63bd17bb14248cf9881046dd6b331e2a (diff) | |
build: apply Spotless plugin (#293)
Diffstat (limited to 'src/test/java/dev/dnpm/oshelper/analyzer/AnalyzerUtilsTest.java')
| -rw-r--r-- | src/test/java/dev/dnpm/oshelper/analyzer/AnalyzerUtilsTest.java | 231 |
1 files changed, 117 insertions, 114 deletions
diff --git a/src/test/java/dev/dnpm/oshelper/analyzer/AnalyzerUtilsTest.java b/src/test/java/dev/dnpm/oshelper/analyzer/AnalyzerUtilsTest.java index 009ce34..18100a6 100644 --- a/src/test/java/dev/dnpm/oshelper/analyzer/AnalyzerUtilsTest.java +++ b/src/test/java/dev/dnpm/oshelper/analyzer/AnalyzerUtilsTest.java @@ -19,138 +19,141 @@ package dev.dnpm.oshelper.analyzer; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Map; import java.util.Optional; import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; class AnalyzerUtilsTest { - private final Map<String, Object> input = Map.of("value1", 1, "valueA", "A", "valueTrue", true); - - private static Set<TestTypeData> testTypeData() { - return Set.of( - new TestTypeData("value1", Integer.class).withExpectedResult(true), - new TestTypeData("valueA", String.class).withExpectedResult(true), - new TestTypeData("valueTrue", Boolean.class).withExpectedResult(true), - - new TestTypeData("value1", String.class).withExpectedResult(false), - new TestTypeData("valueA", Boolean.class).withExpectedResult(false), - new TestTypeData("valueTrue", Integer.class).withExpectedResult(false), - - new TestTypeData("value1", Boolean.class).withExpectedResult(false), - new TestTypeData("valueA", Integer.class).withExpectedResult(false), - new TestTypeData("valueTrue", String.class).withExpectedResult(false) - ); + private final Map<String, Object> input = Map.of("value1", 1, "valueA", "A", "valueTrue", true); + + private static Set<TestTypeData> testTypeData() { + return Set.of( + new TestTypeData("value1", Integer.class).withExpectedResult(true), + new TestTypeData("valueA", String.class).withExpectedResult(true), + new TestTypeData("valueTrue", Boolean.class).withExpectedResult(true), + new TestTypeData("value1", String.class).withExpectedResult(false), + new TestTypeData("valueA", Boolean.class).withExpectedResult(false), + new TestTypeData("valueTrue", Integer.class).withExpectedResult(false), + new TestTypeData("value1", Boolean.class).withExpectedResult(false), + new TestTypeData("valueA", Integer.class).withExpectedResult(false), + new TestTypeData("valueTrue", String.class).withExpectedResult(false)); + } + + @ParameterizedTest + @MethodSource("testTypeData") + void testShouldReturnExpectedResultForTypedCheck(TestTypeData testData) { + var actual = AnalyzerUtils.requiredValuePresent(input, testData.key, testData.type); + assertThat(actual).isEqualTo(testData.result); + } + + private static Set<TestMatchData> testMatchData() { + return Set.of( + new TestMatchData("value1", "[\\d]").withExpectedResult(true), + new TestMatchData("valueA", "[A-Z]").withExpectedResult(true), + new TestMatchData("value1", "[A-Z]").withExpectedResult(false), + new TestMatchData("valueA", "[a-z]").withExpectedResult(false), + new TestMatchData("valueA", "[\\d]").withExpectedResult(false)); + } + + @ParameterizedTest + @MethodSource("testMatchData") + void testShouldReturnExpectedResultForMatchCheck(TestMatchData testData) { + var actual = AnalyzerUtils.requiredValueMatches(input, testData.key, testData.regexp); + assertThat(actual).isEqualTo(testData.result); + } + + @Test + void testShouldCheckIfInputValueIsIdNumber() { + assertThat(AnalyzerUtils.requiredValueIsId(Map.of("value", 0), "value")).isFalse(); + assertThat(AnalyzerUtils.requiredValueIsId(Map.of("value", "ABC"), "value")).isFalse(); + assertThat(AnalyzerUtils.requiredValueIsId(Map.of("value", 1234), "value")).isTrue(); + } + + @Test + void testShouldReturnInputValueAsOptional() { + assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", 1234), "value", Integer.class)) + .isEqualTo(Optional.of(1234)); + assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", "ABC"), "value", String.class)) + .isEqualTo(Optional.of("ABC")); + + assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", 1234), "value1", Integer.class)) + .isEmpty(); + assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", "ABC"), "value1", String.class)) + .isEmpty(); + assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", 1234), "value", String.class)) + .isEmpty(); + assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", "ABC"), "value", Boolean.class)) + .isEmpty(); + } + + @Test + void testShouldReturnInputIdAsOptional() { + assertThat(AnalyzerUtils.getRequiredId(Map.of("value", 1234), "value")) + .isEqualTo(Optional.of(1234)); + + assertThat(AnalyzerUtils.getRequiredId(Map.of("value", 1234), "value1")).isEmpty(); + assertThat(AnalyzerUtils.getRequiredId(Map.of("value", "ABC"), "value")).isEmpty(); + assertThat(AnalyzerUtils.getRequiredId(Map.of("value", 0), "value")).isEmpty(); + } + + @Test + void testShouldReturnInputValueMatchingAsOptional() { + assertThat(AnalyzerUtils.getRequiredValueMatching(Map.of("value", 1234), "value", "[\\d]+")) + .isEqualTo(Optional.of("1234")); + assertThat(AnalyzerUtils.getRequiredValueMatching(Map.of("value", "ABC"), "value", "[A-Z]+")) + .isEqualTo(Optional.of("ABC")); + + assertThat(AnalyzerUtils.getRequiredValueMatching(Map.of("value", "ABC"), "value1", "[A-Z]+")) + .isEmpty(); + } + + private static class TestTypeData { + public final String key; + public final Class<?> type; + + public boolean result; + + public TestTypeData(String key, Class<?> type) { + this.key = key; + this.type = type; } - @ParameterizedTest - @MethodSource("testTypeData") - void testShouldReturnExpectedResultForTypedCheck(TestTypeData testData) { - var actual = AnalyzerUtils.requiredValuePresent(input, testData.key, testData.type); - assertThat(actual).isEqualTo(testData.result); + public TestTypeData withExpectedResult(boolean result) { + this.result = result; + return this; } - private static Set<TestMatchData> testMatchData() { - return Set.of( - new TestMatchData("value1", "[\\d]").withExpectedResult(true), - new TestMatchData("valueA", "[A-Z]").withExpectedResult(true), - - new TestMatchData("value1", "[A-Z]").withExpectedResult(false), - new TestMatchData("valueA", "[a-z]").withExpectedResult(false), - new TestMatchData("valueA", "[\\d]").withExpectedResult(false) - ); - } - - @ParameterizedTest - @MethodSource("testMatchData") - void testShouldReturnExpectedResultForMatchCheck(TestMatchData testData) { - var actual = AnalyzerUtils.requiredValueMatches(input, testData.key, testData.regexp); - assertThat(actual).isEqualTo(testData.result); + @Override + public String toString() { + return String.format("key: '%s', type: %s, result: %s", key, type.getSimpleName(), result); } + } - @Test - void testShouldCheckIfInputValueIsIdNumber() { - assertThat(AnalyzerUtils.requiredValueIsId(Map.of("value", 0), "value")).isFalse(); - assertThat(AnalyzerUtils.requiredValueIsId(Map.of("value", "ABC"), "value")).isFalse(); - assertThat(AnalyzerUtils.requiredValueIsId(Map.of("value", 1234), "value")).isTrue(); - } + private static class TestMatchData { + public final String key; + public final String regexp; - @Test - void testShouldReturnInputValueAsOptional() { - assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", 1234), "value", Integer.class)).isEqualTo(Optional.of(1234)); - assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", "ABC"), "value", String.class)).isEqualTo(Optional.of("ABC")); + public boolean result; - assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", 1234), "value1", Integer.class)).isEmpty(); - assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", "ABC"), "value1", String.class)).isEmpty(); - assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", 1234), "value", String.class)).isEmpty(); - assertThat(AnalyzerUtils.getRequiredValue(Map.of("value", "ABC"), "value", Boolean.class)).isEmpty(); + public TestMatchData(String key, String regexp) { + this.key = key; + this.regexp = regexp; } - @Test - void testShouldReturnInputIdAsOptional() { - assertThat(AnalyzerUtils.getRequiredId(Map.of("value", 1234), "value")).isEqualTo(Optional.of(1234)); - - assertThat(AnalyzerUtils.getRequiredId(Map.of("value", 1234), "value1")).isEmpty(); - assertThat(AnalyzerUtils.getRequiredId(Map.of("value", "ABC"), "value")).isEmpty(); - assertThat(AnalyzerUtils.getRequiredId(Map.of("value", 0), "value")).isEmpty(); - } - - @Test - void testShouldReturnInputValueMatchingAsOptional() { - assertThat(AnalyzerUtils.getRequiredValueMatching(Map.of("value", 1234), "value", "[\\d]+")).isEqualTo(Optional.of("1234")); - assertThat(AnalyzerUtils.getRequiredValueMatching(Map.of("value", "ABC"), "value", "[A-Z]+")).isEqualTo(Optional.of("ABC")); - - assertThat(AnalyzerUtils.getRequiredValueMatching(Map.of("value", "ABC"), "value1", "[A-Z]+")).isEmpty(); + public TestMatchData withExpectedResult(boolean result) { + this.result = result; + return this; } - private static class TestTypeData { - public final String key; - public final Class<?> type; - - public boolean result; - - public TestTypeData(String key, Class<?> type) { - this.key = key; - this.type = type; - } - - public TestTypeData withExpectedResult(boolean result) { - this.result = result; - return this; - } - - @Override - public String toString() { - return String.format("key: '%s', type: %s, result: %s", key, type.getSimpleName(), result); - } + @Override + public String toString() { + return String.format("key: '%s', regexp: '%s', result: %s", key, regexp, result); } - - private static class TestMatchData { - public final String key; - public final String regexp; - - public boolean result; - - public TestMatchData(String key, String regexp) { - this.key = key; - this.regexp = regexp; - } - - public TestMatchData withExpectedResult(boolean result) { - this.result = result; - return this; - } - - @Override - public String toString() { - return String.format("key: '%s', regexp: '%s', result: %s", key, regexp, result); - } - } - + } } |
