HttpMatchers { public static Matcher<Response> clientError() { return new CustomMatcher<Response>("4xx (client error) family of responses") { @Override public boolean matches(Object o) { return (o instanceof Response) && (((Response) o).getStatusInfo().getFamily() == Response.Status.Family.CLIENT_ERROR); } @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 clientErrorMatcher() { Matcher<Response> clientError = HttpMatchers.clientError(); Response response = mock(Response.class); Response.StatusType statusType = mock(Response.StatusType.class); when(response.getStatusInfo()).thenReturn(statusType); when(statusType.getFamily()).thenReturn(Response.Status.Family.CLIENT_ERROR); assertThat(response, is(clientError)); }