HttpMatchers { public static Matcher<Response> created() { final int statusCode = Response.Status.CREATED.getStatusCode(); return new CustomMatcher<Response>("created status (" + statusCode + ") with location header") { @Override public boolean matches(Object o) { if (!(o instanceof Response)) { return false; } Response response = (Response) o; if (response.getStatus() == statusCode) { String header = response.getHeaderString("Location"); return (header != null); } else { return false; } } @Override public void describeMismatch(Object item, Description description) { Response response = (Response) item; provideDescription(response, description); } }; }  static Matcher<Response> successful(); static Matcher<Response> clientError(); static Matcher<Response> redirection(); static Matcher<Response> informational(); static Matcher<Response> other(); static Matcher<Response> noContent(); static Matcher<Response> serverError(); static Matcher<Response> created();  }
@Test public void createdMatcher() { Matcher<Response> created = HttpMatchers.created(); Response response = mock(Response.class); when(response.getHeaderString("Location")).thenReturn("http: when(response.getStatus()).thenReturn(201); assertThat(response, is(created)); }