/** * {@inheritDoc} */ public boolean matchesMethod(RequestInfo<?> request) { if (matchAllMethods) return true; //noinspection SimplifiableIfStatement if (request == null || request.getMethod() == null) return false; return matchingMethods().contains(request.getMethod()); } }
@Test public void static_factory_with_path_arg_only_sets_values_as_expected() { // given String path = "/" + UUID.randomUUID().toString(); // when SingleMatcher matcher = SingleMatcher.match(path); // then assertThat(matcher.matchingPathTemplates(), is(Arrays.asList(path))); assertThat(matcher.matchingMethods(), notNullValue()); assertThat(matcher.matchingMethods().isEmpty(), is(true)); assertThat(matcher.isMatchAllMethods(), is(true)); }
@Test public void static_factory_with_path_and_methods_varargs_sets_values_as_expected() { // given String path = "/" + UUID.randomUUID().toString(); HttpMethod[] methodVarargs = new HttpMethod[]{HttpMethod.GET, HttpMethod.PUT}; // when SingleMatcher matcher = SingleMatcher.match(path, methodVarargs); // then assertThat(matcher.matchingPathTemplates(), is(Arrays.asList(path))); assertThat(matcher.matchingMethods(), notNullValue()); assertThat(matcher.matchingMethods().size(), is(methodVarargs.length)); for (HttpMethod expectedMethod : methodVarargs) { assertThat(matcher.matchingMethods().contains(expectedMethod), is(true)); } assertThat(matcher.isMatchAllMethods(), is(false)); }
@Test public void static_factory_with_path_and_methods_collection_sets_values_as_expected() { // given String path = "/" + UUID.randomUUID().toString(); Collection<HttpMethod> methodCollection = Arrays.asList(HttpMethod.GET, HttpMethod.PUT); // when SingleMatcher matcher = SingleMatcher.match(path, methodCollection); // then assertThat(matcher.matchingPathTemplates(), is(Arrays.asList(path))); assertThat(matcher.matchingMethods(), is(methodCollection)); assertThat(matcher.isMatchAllMethods(), is(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)); }