RequestFilter { public boolean isMatch(@NonNull String url) { for (String r : regex) { String trimUrl = url.split("\\?")[0]; if (!trimUrl.endsWith("/")) { trimUrl = trimUrl + "/"; } if (trimUrl.matches(r)) { return true; } } return false; } RequestFilter(@NonNull List<String> rules); boolean isMatch(@NonNull String url); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void isMatch_checkAgainstResources() { RequestFilter requestFilter = new RequestFilter(Collections.singletonList("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: }
@Test public void isMatch_checkAgainstPrefix() { RequestFilter requestFilter = new RequestFilter(Collections.singletonList("/todos/*")); assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: }
@Test public void isMatch_checkAgainstPrefixWithoutSlash() { RequestFilter requestFilter = new RequestFilter(Collections.singletonList("todos/*")); assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: }
@Test public void isMatch_checkWithoutResources() { RequestFilter requestFilter = new RequestFilter(Collections.singletonList("/todos/")); assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: }
@Test public void isMatch_checkWithoutResourcesWithoutSlash() { RequestFilter requestFilter = new RequestFilter(Collections.singletonList("/todos")); assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: }
@Test public void isMatch_exact() { RequestFilter requestFilter = new RequestFilter(Collections.singletonList("https: assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: }
@Test public void isMatch_againstMultipleRules() { RequestFilter requestFilter = new RequestFilter(Arrays.asList( "/todos", "/todoscommentscomments/*/users" )); assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("/todos/1/")); assertTrue(requestFilter.isMatch("todos/1/")); assertTrue(requestFilter.isMatch("www.test.com/todos")); assertTrue(requestFilter.isMatch("www.test.com/todos/")); assertTrue(requestFilter.isMatch("todos?query=1")); assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("/todos/1/comments/1")); assertTrue(requestFilter.isMatch("/todos/1/comments/1/")); assertTrue(requestFilter.isMatch("https: assertTrue(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("https: assertFalse(requestFilter.isMatch("/comments")); }