コード例 #1
0
  @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));
  }
コード例 #2
0
  @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));
  }
コード例 #3
0
  @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));
  }
コード例 #4
0
  @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));
  }
コード例 #5
0
  @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));
  }
コード例 #6
0
  @Test
  public void responseCanBeSerialized() {
    // Arrange:
    final JsonSerializer serializer = new JsonSerializer();
    final ErrorResponse response = new ErrorResponse(new TimeInstant(18), "badness", 500);

    // Act:
    response.serialize(serializer);
    final JSONObject jsonObject = serializer.getObject();

    // Assert:
    Assert.assertThat(jsonObject.get("timeStamp"), IsEqual.equalTo(18));
    Assert.assertThat(jsonObject.get("error"), IsEqual.equalTo("Internal Server Error"));
    Assert.assertThat(jsonObject.get("message"), IsEqual.equalTo("badness"));
    Assert.assertThat(jsonObject.get("status"), IsEqual.equalTo(500));
  }