ReservationDescriptor implements Descriptor<RecommendedReservation, ReservationDescriptor, Reservation> { @Override public Optional<RecommendedReservation> recommend(final Money amount) { final Money actual = reservation.getMyReservation() .getReservedAmount(); if (amount.equals(actual)) { return Optional.of(new RecommendedReservation(this, amount)); } else { LOGGER.warn("Requested reservation of {} while it is worth {}. ", amount, actual); return Optional.empty(); } } ReservationDescriptor(final Reservation reservation, final Supplier<Loan> loanSupplier); @Override Reservation item(); @Override Loan related(); @Override Optional<RecommendedReservation> recommend(final Money amount); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test void recommendAmount() { final Reservation mockedReservation = ReservationDescriptorTest.mockReservation(); final ReservationDescriptor ld = new ReservationDescriptor(mockedReservation, () -> null); final Optional<RecommendedReservation> r = ld.recommend(Money.from(1_000)); assertThat(r).isPresent(); final RecommendedReservation recommendation = r.get(); assertSoftly(softly -> { softly.assertThat(recommendation.descriptor()) .isSameAs(ld); softly.assertThat(recommendation.amount()) .isEqualTo(Money.from(1_000)); }); }
@Test void recommendWrongAmount() { final Reservation mockedReservation = ReservationDescriptorTest.mockReservation(); final ReservationDescriptor ld = new ReservationDescriptor(mockedReservation, () -> null); final Optional<RecommendedReservation> r = ld.recommend(Money.from(1)); assertThat(r).isEmpty(); }