private void assertResponseOk(int expectedStatus, String expectedBody) throws JSONException {
   if (recorder.getHttpStatusCode() == HttpServletResponse.SC_OK) {
     String body = recorder.getResponseAsString();
     assertStartsWith(MakeRequestHandler.UNPARSEABLE_CRUFT, body);
     body = body.substring(MakeRequestHandler.UNPARSEABLE_CRUFT.length());
     JSONObject object = new JSONObject(body);
     object = object.getJSONObject(REQUEST_URL.toString());
     assertEquals(expectedStatus, object.getInt("rc"));
     assertEquals(expectedBody, object.getString("body"));
   } else {
     fail("Invalid response for request.");
   }
 }
  @Test
  public void doPostException() throws Exception {
    setupPost();
    expect(fixture.httpFetcher.fetch(request))
        .andThrow(
            new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE));
    fixture.replay();

    servlet.doPost(fixture.request, recorder);

    assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode());
    assertContains(ERROR_MESSAGE, recorder.getResponseAsString());
  }