Revert changes to URIPathTest.java

This commit is contained in:
Risto Lahtela 2021-03-16 11:36:45 +02:00
parent 1c8fa4c18e
commit 2e753516e2

View File

@ -17,8 +17,6 @@
package com.djrapitops.plan.delivery.web.resolver.request;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.util.Optional;
@ -31,6 +29,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
*/
class URIPathTest {
@Test
void firstPartEmptyForRoot() {
URIPath target = new URIPath("/");
Optional<String> expected = Optional.of("");
Optional<String> result = target.getPart(0);
assertEquals(expected, result);
}
@Test
void fullTargetForRoot() {
URIPath target = new URIPath("/");
@ -39,6 +45,14 @@ class URIPathTest {
assertEquals(expected, result);
}
@Test
void firstPart() {
URIPath target = new URIPath("/example/target");
Optional<String> expected = Optional.of("example");
Optional<String> result = target.getPart(0);
assertEquals(expected, result);
}
@Test
void fullTarget() {
URIPath target = new URIPath("/example/target");
@ -47,17 +61,11 @@ class URIPathTest {
assertEquals(expected, result);
}
@ParameterizedTest
@CsvSource({
"/", "0", " ",
"/example/target", "0", "example",
"/example/target", "1", "target",
"/example/target/", "2", " ",
})
void partGettingWorksProperly(String targetURI, int partNumber, String expectedPart) {
URIPath target = new URIPath(targetURI);
Optional<String> expected = Optional.ofNullable(expectedPart.trim());
Optional<String> result = target.getPart(partNumber);
@Test
void secondPart() {
URIPath target = new URIPath("/example/target");
Optional<String> expected = Optional.of("target");
Optional<String> result = target.getPart(1);
assertEquals(expected, result);
}
@ -69,6 +77,14 @@ class URIPathTest {
assertEquals(expected, result);
}
@Test
void emptyLastPart() {
URIPath target = new URIPath("/example/target/");
Optional<String> expected = Optional.of("");
Optional<String> result = target.getPart(2);
assertEquals(expected, result);
}
@Test
void omitRoot() {
URIPath target = new URIPath("/").omitFirst();
@ -101,18 +117,52 @@ class URIPathTest {
assertEquals(expected, result);
}
@ParameterizedTest
@CsvSource({
"/example/target", "1", "/target",
"/example/target/", "2", "/",
"/example/target", "2", " ",
"/example/target", "0", "/example/target",
"/example/target/", "1", "/target/",
" ", "1", " "
})
void partsAreRemoved(String test, int removeThisMany, String expected) {
String result = URIPath.removePartsBefore(test.trim(), removeThisMany);
assertEquals(expected.trim(), result);
@Test
void partsAreRemoved() {
String test = "/example/target";
String expected = "/target";
String result = URIPath.removePartsBefore(test, 1);
assertEquals(expected, result);
}
@Test
void partsAreRemoved2() {
String test = "/example/target/";
String expected = "/";
String result = URIPath.removePartsBefore(test, 2);
assertEquals(expected, result);
}
@Test
void partsAreRemoved3() {
String test = "/example/target";
String expected = "";
String result = URIPath.removePartsBefore(test, 2);
assertEquals(expected, result);
}
@Test
void partsAreRemoved4() {
String test = "/example/target";
String expected = "/example/target";
String result = URIPath.removePartsBefore(test, 0);
assertEquals(expected, result);
}
@Test
void partsAreRemoved5() {
String test = "/example/target/";
String expected = "/";
String result = URIPath.removePartsBefore(test, 2);
assertEquals(expected, result);
}
@Test
void noPartsToRemove() {
String test = "";
String expected = "";
String result = URIPath.removePartsBefore(test, 1);
assertEquals(expected, result);
}
}