PurchaseResult extends Result<PurchaseFailureType> { public static PurchaseResult failure(final ClientErrorException ex) { return new PurchaseResult(ex); } private  PurchaseResult(); private  PurchaseResult(final ClientErrorException ex); static PurchaseResult success(); static PurchaseResult failure(final ClientErrorException ex);  }
@Test void sameCauseEquals() { assertThat(PurchaseResult.failure(new BadRequestException())).isEqualTo( PurchaseResult.failure(new BadRequestException())); }
@Test void nullException() { assertThat(PurchaseResult.failure(null)) .matches(r -> !r.isSuccess()) .matches(r -> r.getFailureType() .isPresent() && r.getFailureType() .get() == UNKNOWN); }
@Test void unknownException() { assertThat(PurchaseResult.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(PurchaseResult.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(PurchaseResult.failure(ex)) .matches(r -> !r.isSuccess()) .matches(r -> r.getFailureType() .isPresent() && r.getFailureType() .get() == INSUFFICIENT_BALANCE); }