Utils { public static String getPathOnly(String fullPath) { if (fullPath == null || fullPath.isEmpty()) return fullPath; int index = fullPath.indexOf('?'); if (index == -1) { index = fullPath.indexOf('#'); return index == -1 ? fullPath : fullPath.substring(0, index); } return fullPath.substring(0, index); } private  Utils(); static String readStream(InputStream inputStream); static String getPathOnly(String fullPath);  }
@Test public void testGetPath() { assertNull(Utils.getPathOnly(null)); assertTrue(Utils.getPathOnly("").isEmpty()); String path = "/path"; assertEquals(path, Utils.getPathOnly("/path?query#fragment")); assertEquals(path, Utils.getPathOnly("/path?query")); assertEquals(path, Utils.getPathOnly("/path")); assertEquals(path, Utils.getPathOnly("/path#fragment")); }