/** * Convert the descriptor into an actual investment recommendation. This will be executed by the * {@link InvestmentStrategy}. * @param amount The amount recommended to invest. * @param confirmationRequired Whether or not {@link ConfirmationProvider} is required to confirm the investment. * @return Empty if amount is out of bounds. */ public Optional<RecommendedLoan> recommend(final int amount, final boolean confirmationRequired) { final int remaining = loan.getNonReservedRemainingInvestment(); if (amount <= remaining) { return Optional.of(new RecommendedLoan(this, amount, confirmationRequired)); } else { LOGGER.warn("Can not recommend {} CZK with {} CZK remaining in loan #{}.", amount, remaining, loan.getId()); return Optional.empty(); } }
/** * Convert the descriptor into an actual investment recommendation. This will be executed by the * {@link InvestmentStrategy}. * @param amount The amount recommended to invest. * @param confirmationRequired Whether or not {@link ConfirmationProvider} is required to confirm the investment. * @return Empty if amount is out of bounds. */ public Optional<RecommendedLoan> recommend(final int amount, final boolean confirmationRequired) { final int remaining = loan.getNonReservedRemainingInvestment(); if (amount <= remaining) { return Optional.of(new RecommendedLoan(this, amount, confirmationRequired)); } else { LOGGER.warn("Can not recommend {} CZK with {} CZK remaining in loan #{}.", amount, remaining, loan.getId()); return Optional.empty(); } }
@Test void constructorNoLoanDescriptor() { final int amount = 200; assertThatThrownBy(() -> new RecommendedLoan(null, amount, true)) .isInstanceOf(IllegalArgumentException.class); }
@Test void equalsSame() { final LoanDescriptor ld = RecommendedLoanTest.mockLoanDescriptor(); final int amount = 200; final boolean confirmationRequired = true; final RecommendedLoan r1 = new RecommendedLoan(ld, amount, confirmationRequired); assertThat(r1).isEqualTo(r1); final RecommendedLoan r2 = new RecommendedLoan(ld, amount, confirmationRequired); assertThat(r1).isEqualTo(r2); }
@Test void notEqualsDifferentAmount() { final LoanDescriptor ld = RecommendedLoanTest.mockLoanDescriptor(); final int amount = 200; final boolean confirmationRequired = true; final RecommendedLoan r1 = new RecommendedLoan(ld, amount, confirmationRequired); final RecommendedLoan r2 = new RecommendedLoan(ld, amount + 1, confirmationRequired); assertThat(r1).isNotEqualTo(r2); }
@Test void notEqualsDifferentConfirmationRequirements() { final LoanDescriptor ld = RecommendedLoanTest.mockLoanDescriptor(); final int amount = 200; final RecommendedLoan r1 = new RecommendedLoan(ld, amount, true); final RecommendedLoan r2 = new RecommendedLoan(ld, amount, false); assertThat(r1).isNotEqualTo(r2); }
@Test void notEqualsDifferentLoanDescriptor() { final int amount = 200; final boolean confirmationRequired = true; final RecommendedLoan r1 = new RecommendedLoan(RecommendedLoanTest.mockLoanDescriptor(), amount, confirmationRequired); final RecommendedLoan r2 = new RecommendedLoan(RecommendedLoanTest.mockLoanDescriptor(), amount, confirmationRequired); assertThat(r1).isNotEqualTo(r2); }
@Test void notEqualsDifferentJavaType() { final RecommendedLoan r1 = new RecommendedLoan(RecommendedLoanTest.mockLoanDescriptor(), 200, true); assertThat(r1).isNotEqualTo(r1.toString()); } }
@Test void constructor() { final LoanDescriptor ld = RecommendedLoanTest.mockLoanDescriptor(); final int amount = 200; final RecommendedLoan r = new RecommendedLoan(ld, amount, true); SoftAssertions.assertSoftly(softly -> { softly.assertThat(r.descriptor()).isSameAs(ld); softly.assertThat(r.amount()).isEqualTo(BigDecimal.valueOf(amount)); softly.assertThat(r.isConfirmationRequired()).isTrue(); }); }