InvestmentResult extends Result<InvestmentFailureType> { public static InvestmentResult failure(final ClientErrorException ex) { return new InvestmentResult(ex); } private  InvestmentResult(); private  InvestmentResult(final ClientErrorException ex); static InvestmentResult success(); static InvestmentResult failure(final ClientErrorException ex);  }
@Test void sameCauseEquals() { assertThat(InvestmentResult.failure(new BadRequestException())) .isEqualTo(InvestmentResult.failure(new BadRequestException())); }
@Test void nullException() { assertThat(InvestmentResult.failure(null)) .matches(r -> !r.isSuccess()) .matches(r -> r.getFailureType() .isPresent() && r.getFailureType() .get() == UNKNOWN); }
@Test void unknownException() { assertThat(InvestmentResult.failure(new ClientErrorException(410))) .matches(r -> !r.isSuccess()) .matches(r -> r.getFailureType() .isPresent() && r.getFailureType() .get() == UNKNOWN); }
@Test void noReason() { final Response response = Response.status(400) .build(); final ClientErrorException ex = new BadRequestException(response); assertThat(InvestmentResult.failure(ex)) .matches(r -> !r.isSuccess()) .matches(r -> r.getFailureType() .isPresent() && r.getFailureType() .get() == UNKNOWN); }
@Test void insufficientBalance() { final Response response = Response.status(400) .entity(INSUFFICIENT_BALANCE.getReason() .get()) .build(); final ClientErrorException ex = new BadRequestException(response); assertThat(InvestmentResult.failure(ex)) .matches(r -> !r.isSuccess()) .matches(r -> r.getFailureType() .isPresent() && r.getFailureType() .get() == INSUFFICIENT_BALANCE); }