RecommendedInvestment implements Recommended<RecommendedInvestment, InvestmentDescriptor, Investment> { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || !Objects.equals(getClass(), o.getClass())) { return false; } final RecommendedInvestment that = (RecommendedInvestment) o; return Objects.equals(descriptor, that.descriptor); } RecommendedInvestment(final InvestmentDescriptor participationDescriptor, final Money amount); @Override InvestmentDescriptor descriptor(); @Override Money amount(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test void equals() { final BigDecimal remainingPrincipal = BigDecimal.TEN; final Investment i = mockInvestment(remainingPrincipal); final InvestmentDescriptor d = new InvestmentDescriptor(i, () -> LOAN); final RecommendedInvestment r = new RecommendedInvestment(d, Money.from(remainingPrincipal)); assertSoftly(softly -> { softly.assertThat(r) .isNotEqualTo(null); softly.assertThat(r) .isNotEqualTo(UUID.randomUUID() .toString()); softly.assertThat(r) .isEqualTo(r); }); final RecommendedInvestment r2 = new RecommendedInvestment(d, Money.from(remainingPrincipal)); assertSoftly(softly -> { softly.assertThat(r) .isEqualTo(r2); softly.assertThat(r2) .isEqualTo(r); }); final RecommendedInvestment r3 = new RecommendedInvestment( new InvestmentDescriptor(mockInvestment(remainingPrincipal), () -> LOAN), Money.from(remainingPrincipal)); assertThat(r).isNotEqualTo(r3); }