@Test(expected = ApiException.class) public void nonJSONErrorResponse() { try { mockServer.expect(requestTo("https://api.twitter.com/1.1/statuses/home_timeline.json?count=20&include_entities=true")) .andExpect(method(GET)) .andRespond(withBadRequest().body("<h1>HTML response</h1>").contentType(APPLICATION_JSON)); twitter.timelineOperations().getHomeTimeline(); } catch (ApiException e) { assertEquals("Error consuming Twitter REST API", e.getMessage()); throw e; } }