@Test
  public void canBeCreatedAroundMessage() {
    // Arrange:
    final ErrorResponse response = new ErrorResponse(new TimeInstant(29), "badness", 500);

    // Assert:
    Assert.assertThat(response.getTimeStamp(), IsEqual.equalTo(new TimeInstant(29)));
    Assert.assertThat(response.getError(), IsEqual.equalTo("Internal Server Error"));
    Assert.assertThat(response.getMessage(), IsEqual.equalTo("badness"));
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(500));
  }
  @Test
  public void responseWithoutDescriptionsCanBeRoundTripped() {
    // Act:
    final ErrorResponse response =
        createRoundTrippedResponse(new ErrorResponse(new TimeInstant(54), null, 890));

    // Assert:
    Assert.assertThat(response.getTimeStamp(), IsEqual.equalTo(new TimeInstant(54)));
    Assert.assertThat(response.getError(), IsNull.nullValue());
    Assert.assertThat(response.getMessage(), IsNull.nullValue());
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(890));
  }
  @Test
  public void responseCanBeRoundTripped() {
    // Act:
    final ErrorResponse response =
        createRoundTrippedResponse(new ErrorResponse(new TimeInstant(18), "badness", 500));

    // Assert:
    Assert.assertThat(response.getTimeStamp(), IsEqual.equalTo(new TimeInstant(18)));
    Assert.assertThat(response.getError(), IsEqual.equalTo("Internal Server Error"));
    Assert.assertThat(response.getMessage(), IsEqual.equalTo("badness"));
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(500));
  }
  @Test
  public void canBeCreatedAroundUnknownHttpStatus() {
    // Arrange:
    final ErrorResponse response =
        new ErrorResponse(new TimeInstant(18), "exception message", -123);

    // Assert:
    Assert.assertThat(response.getTimeStamp(), IsEqual.equalTo(new TimeInstant(18)));
    Assert.assertThat(response.getError(), IsNull.nullValue());
    Assert.assertThat(response.getMessage(), IsEqual.equalTo("exception message"));
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(-123));
  }
  @Test
  public void canBeCreatedAroundException() {
    // Arrange:
    final ErrorResponse response =
        new ErrorResponse(
            new TimeInstant(18), new RuntimeException("exception message"), HttpStatus.NOT_FOUND);

    // Assert:
    Assert.assertThat(response.getTimeStamp(), IsEqual.equalTo(new TimeInstant(18)));
    Assert.assertThat(response.getError(), IsEqual.equalTo("Not Found"));
    Assert.assertThat(response.getMessage(), IsEqual.equalTo("exception message"));
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(404));
  }
  @Test
  public void shouldReturn500OnGatewayException() throws Exception {
    mockFdaGateway.exception = new GatewayException();
    final MvcResult mvcResult =
        mvc.perform(
                MockMvcRequestBuilders.get("/api/events")
                    .contentType(MediaType.APPLICATION_JSON)
                    .accept(MediaType.APPLICATION_JSON)
                    .param("productNdc", MockOpenFdaGateway.ASPIRIN_NDC))
            .andExpect(MockMvcResultMatchers.status().isInternalServerError())
            .andReturn();

    final ErrorResponse response =
        SimpleObjectMapper.mapResponse(mvcResult.getResponse(), ErrorResponse.class);

    assertThat(response.getMessage(), equalTo("Error communicating with OpenFDA API"));
  }