InvestmentDescriptor implements Descriptor<RecommendedInvestment, InvestmentDescriptor, Investment> { public Optional<RecommendedInvestment> recommend() { return recommend(getRemainingPrincipal()); } InvestmentDescriptor(final Investment investment, final Supplier<Loan> related); @Override Investment item(); @Override Loan related(); Optional<RecommendedInvestment> recommend(); @Override Optional<RecommendedInvestment> recommend(final Money amount); @Override boolean equals(final Object o); @Override String toString(); @Override int hashCode();  }
@Test void recommend() { final BigDecimal remainingPrincipal = BigDecimal.TEN; final Investment i = mockInvestment(remainingPrincipal); final InvestmentDescriptor id = new InvestmentDescriptor(i, () -> LOAN); assertThat(id.item()).isSameAs(i); final Optional<RecommendedInvestment> r = id.recommend(); assertThat(r).isPresent(); assertSoftly(softly -> { softly.assertThat(r.get() .amount()) .isEqualTo(Money.from(remainingPrincipal)); softly.assertThat(r.get() .descriptor()) .isEqualTo(id); softly.assertThat(r.get() .descriptor() .related()) .isSameAs(LOAN); }); }
@Test void recommendWrong() { final BigDecimal remainingPrincipal = BigDecimal.TEN; final Investment i = mockInvestment(remainingPrincipal); final InvestmentDescriptor id = new InvestmentDescriptor(i, () -> LOAN); final Optional<RecommendedInvestment> r = id.recommend(Money.from(remainingPrincipal.subtract(BigDecimal.ONE))); assertThat(r).isEmpty(); }