ParticipationDescriptor implements Descriptor<RecommendedParticipation, ParticipationDescriptor, Participation> { public Optional<RecommendedParticipation> recommend() { return recommend(participation.getRemainingPrincipal()); } ParticipationDescriptor(final Participation participation, final Supplier<Loan> related);  ParticipationDescriptor(final Participation participation, final Supplier<Loan> related,
            final Supplier<ParticipationDetail> detail); @Override Participation item(); @Override Loan related(); Optional<ParticipationDetail> detail(); Optional<RecommendedParticipation> recommend(); @Override Optional<RecommendedParticipation> recommend(final Money amount); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test void recommend() { final Participation p = mockParticipation(BigDecimal.TEN); final ParticipationDescriptor pd = new ParticipationDescriptor(p, () -> LOAN); final Optional<RecommendedParticipation> r = pd.recommend(); assertThat(r).isPresent(); assertSoftly(softly -> { softly.assertThat(r.get() .amount()) .isEqualTo(p.getRemainingPrincipal()); softly.assertThat(r.get() .descriptor() .related()) .isSameAs(LOAN); softly.assertThat(r.get() .descriptor()) .isEqualTo(pd); }); }
@Test void recommendWrong() { final Participation p = mockParticipation(BigDecimal.TEN); final ParticipationDescriptor pd = new ParticipationDescriptor(p, () -> LOAN); final Optional<RecommendedParticipation> r = pd.recommend(p.getRemainingPrincipal() .subtract(1)); assertThat(r).isEmpty(); }