/** * @return A new single matcher with the given path template that matches all HTTP methods ({@link * #isMatchAllMethods()} will return true). */ public static SingleMatcher match(String matchingPathTemplate) { return new SingleMatcher(matchingPathTemplate, Collections.emptyList(), true); }
/** * @return A new single matcher with the given path template that matches the given HTTP methods. */ public static SingleMatcher match(String matchingPathTemplate, HttpMethod... matchingMethods) { if (matchingMethods == null || matchingMethods.length == 0) { throw new IllegalArgumentException("matchingMethods cannot be null or empty. If you want to match all " + "methods use the single-arg match(String) method."); } return new SingleMatcher(matchingPathTemplate, Arrays.asList(matchingMethods), false); }
/** * @return A new single matcher with the given path template that matches the given HTTP methods. */ public static SingleMatcher match(String matchingPathTemplate, Collection<HttpMethod> matchingMethods) { if (matchingMethods == null || matchingMethods.isEmpty()) { throw new IllegalArgumentException("matchingMethods cannot be null or empty. If you want to match all " + "methods use the single-arg match(String) method."); } return new SingleMatcher(matchingPathTemplate, matchingMethods, false); }
@Test(expected = IllegalArgumentException.class) public void constructor_throws_IllegalArgumentException_on_path_template_that_does_not_start_with_forward_slash() { // expect new SingleMatcher("whoops", Collections.emptyList(), false); }
@Test(expected = IllegalArgumentException.class) public void constructor_throws_IllegalArgumentException_on_null_method_collection() { // expect new SingleMatcher("/some/path", null, false); }
@Test(expected = IllegalArgumentException.class) public void constructor_throws_IllegalArgumentException_on_null_path_template() { // expect new SingleMatcher(null, Collections.emptyList(), false); }
@SuppressWarnings("ConstantConditions") @Test public void constructor_sets_fields_as_expected() { // given String path = "/" + UUID.randomUUID().toString(); Collection<HttpMethod> methods = Arrays.asList(HttpMethod.CONNECT, HttpMethod.PATCH); boolean matchAllMethods = false; // when SingleMatcher matcher = new SingleMatcher(path, methods, matchAllMethods); // then assertThat(matcher.matchingPathTemplates(), is(Arrays.asList(path))); assertThat(matcher.matchingMethods(), is(methods)); assertThat(matcher.isMatchAllMethods(), is(matchAllMethods)); }