RequestMatchers { public static RequestMatcher hasQueryParameters() { return new RequestMatcher("matched query parameters") { @Override protected boolean matchesSafely(RecordedRequest item) { try { URL mockUrl = new URL("http", "localhost", item.getPath()); List<QueryParam> queryParams = RestMockUtils.splitQuery(mockUrl); return queryParams.size() > 0; } catch (MalformedURLException e) { return false; } catch (UnsupportedEncodingException e) { return false; } } }; } private  RequestMatchers(); static RequestMatcher pathContains(final String urlPart); static RequestMatcher pathDoesNotContain(final String urlPart); static RequestMatcher pathMatchesRegex(final String pattern); static RequestMatcher pathEndsWith(final String urlPart); static RequestMatcher pathEndsWithIgnoringQueryParams(final String endOfUrlPath); static RequestMatcher pathStartsWith(final String urlPart); static RequestMatcher hasHeaderNames(final String... headerNames); static RequestMatcher hasQueryParameters(); static RequestMatcher hasQueryParameterNames(final String... expectedParamsNames); static RequestMatcher hasExactQueryParameters(final QueryParam... expectedParams); static RequestMatcher httpMethodIs(final String method); static RequestMatcher isGET(); static RequestMatcher isPOST(); static RequestMatcher isPATCH(); static RequestMatcher isDELETE(); static RequestMatcher isPUT(); static RequestMatcher isHEAD();  }
@Test public void shouldRecognizeProperQueryParameters() throws IOException { RecordedRequest recordedRequest = createRecordedRequest("/foo/bar?baz=ban"); RequestMatcher matcher = RequestMatchers.hasQueryParameters(); assertTrue(matcher.matches(recordedRequest)); }