/** * @return A new multi-matcher with the given path template that matches all HTTP methods ({@link * #isMatchAllMethods()} will return true). */ public static MultiMatcher match(Collection<String> matchingPathTemplates) { return new MultiMatcher(matchingPathTemplates, Collections.emptyList(), true); }
/** * @return A new multi-matcher with the given path templates that match the given HTTP methods. */ public static MultiMatcher match(Collection<String> matchingPathTemplates, 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(Collection<String>) method."); } return new MultiMatcher(matchingPathTemplates, matchingMethods, false); }
/** * @return A new multi-matcher with the given path templates that match the given HTTP methods. */ public static MultiMatcher match(Collection<String> matchingPathTemplates, 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(Collection<String>) method."); } return new MultiMatcher(matchingPathTemplates, Arrays.asList(matchingMethods), false); }
@DataProvider(value = { "true", "false" }) @Test(expected = IllegalArgumentException.class) public void constructor_throws_IllegalArgumentException_on_null_or_empty_path_template(boolean useNull) { // given Collection<String> pathTemplates = (useNull) ? null : Collections.emptyList(); // expect new MultiMatcher(pathTemplates, Collections.emptyList(), false); }
@Test(expected = IllegalArgumentException.class) public void constructor_throws_IllegalArgumentException_on_path_template_that_does_not_start_with_forward_slash() { Collection<String> paths = new ArrayList<String>() {{ add("whoops"); }}; // expect new MultiMatcher(paths, Collections.emptyList(), false); }
@Test(expected = IllegalArgumentException.class) public void constructor_throws_IllegalArgumentException_on_null_method_collection() { Collection<String> paths = new ArrayList<String>() {{ add("/some/path"); }}; // expect new MultiMatcher(paths, null, false); }
@SuppressWarnings("ConstantConditions") @Test public void constructor_sets_fields_as_expected() { // given String path1 = "/" + UUID.randomUUID().toString(); String path2 = "/" + UUID.randomUUID().toString(); Collection<String> paths = new ArrayList<String>() {{ add(path1); add(path2); }}; Collection<HttpMethod> methods = Arrays.asList(HttpMethod.CONNECT, HttpMethod.PATCH); boolean matchAllMethods = false; // when MultiMatcher matcher = new MultiMatcher(paths, methods, matchAllMethods); // then assertThat(matcher.matchingPathTemplates(), is(paths)); assertThat(matcher.matchingMethods(), is(methods)); assertThat(matcher.isMatchAllMethods(), is(matchAllMethods)); }