Fixed parameterized test errors

This commit is contained in:
Risto Lahtela 2021-03-16 10:51:46 +02:00
parent baab6e5f88
commit ebffd886fe

View File

@ -47,16 +47,16 @@ class URIPathTest {
assertEquals(expected, result); assertEquals(expected, result);
} }
@ParameterizedTest @ParameterizedTest(name = "URIPath {0} gets part {1}: {2}")
@CsvSource({ @CsvSource({
"/", "0", "", "/", "0", " ",
"/example/target", "0", "example", "/example/target", "0", "example",
"/example/target", "1", "target", "/example/target", "1", "target",
"/example/target/", "2", "", "/example/target/", "2", " ",
}) })
void partGettingWorksProperly(String targetURI, int partNumber, String expectedPart) { void partGettingWorksProperly(String targetURI, int partNumber, String expectedPart) {
URIPath target = new URIPath(targetURI); URIPath target = new URIPath(targetURI);
Optional<String> expected = Optional.ofNullable(expectedPart); Optional<String> expected = Optional.ofNullable(expectedPart.trim());
Optional<String> result = target.getPart(partNumber); Optional<String> result = target.getPart(partNumber);
assertEquals(expected, result); assertEquals(expected, result);
} }
@ -101,18 +101,18 @@ class URIPathTest {
assertEquals(expected, result); assertEquals(expected, result);
} }
@ParameterizedTest @ParameterizedTest(name = "URIPath {0} removes parts before part {1}: {2}")
@CsvSource({ @CsvSource({
"/example/target", "1", "/target", "/example/target", "1", "/target",
"/example/target/", "2", "/", "/example/target/", "2", "/",
"/example/target", "2", "", "/example/target", "2", " ",
"/example/target", "0", "/example/target", "/example/target", "0", "/example/target",
"/example/target/", "1", "/target/", "/example/target/", "1", "/target/",
"", "1", "" " ", "1", " "
}) })
void partsAreRemoved(String test, int removeThisMany, String expected) { void partsAreRemoved(String test, int removeThisMany, String expected) {
String result = URIPath.removePartsBefore(test, removeThisMany); String result = URIPath.removePartsBefore(test.trim(), removeThisMany);
assertEquals(expected, result); assertEquals(expected.trim(), result);
} }
} }