URIPath { static String removePartsBefore(String from, int index) { int applied = -1; String finding = from; int appliedSlash; while (applied < index) { appliedSlash = finding.indexOf('/'); boolean hasNoSlash = appliedSlash == -1; if (hasNoSlash) return ""; finding = finding.substring(appliedSlash + 1); applied++; } return "/" + finding; } URIPath(String path); String asString(); Optional<String> getPart(int index); boolean endsWith(String suffix); URIPath omitFirst(); int length(); @Override String toString();  }
@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); }
@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); }