ErrorResponse implements Method.Response { public static Builder builder() { return new Builder(); } @VisibleForTesting  ErrorResponse(String type, Optional<String> description); static Builder builder(); String getType(); Optional<String> getDescription(); @Override boolean equals(Object o); @Override int hashCode(); static final Method.Response.Name ERROR_METHOD; }
@Test public void buildShouldReturnDefaultErrorWhenNoParameter() { ErrorResponse expected = new ErrorResponse(ErrorResponse.DEFAULT_ERROR_MESSAGE, Optional.empty()); ErrorResponse actual = ErrorResponse .builder() .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void buildShouldReturnDefaultErrorWhenNullParameter() { ErrorResponse expected = new ErrorResponse(ErrorResponse.DEFAULT_ERROR_MESSAGE, Optional.empty()); ErrorResponse actual = ErrorResponse .builder() .type(null) .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void buildShouldReturnDefinedErrorWhenTypeParameter() { ErrorResponse expected = new ErrorResponse("my error", Optional.empty()); ErrorResponse actual = ErrorResponse .builder() .type("my error") .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void buildShouldReturnDefinedErrorWhenTypeParameterAndNullDescription() { ErrorResponse expected = new ErrorResponse("my error", Optional.empty()); ErrorResponse actual = ErrorResponse .builder() .type("my error") .description(null) .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void buildShouldReturnDefinedErrorWithDescriptionWhenTypeAndDescriptionParameters() { ErrorResponse expected = new ErrorResponse("my error", Optional.of("custom description")); ErrorResponse actual = ErrorResponse .builder() .type("my error") .description("custom description") .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }