InvestingSession extends AbstractSession<RecommendedLoan, LoanDescriptor, Loan> { @Override protected boolean accept(final RecommendedLoan recommendation) { if (!isBalanceAcceptable(recommendation)) { logger.debug("Will not invest in {} due to balance ({}) likely too low.", recommendation, tenant.getKnownBalanceUpperBound()); return false; } logger.debug("Will attempt to invest in {}.", recommendation); final Either<InvestmentFailureType, Money> response = investor.invest(recommendation); return response.fold(failure -> unsuccessfulInvestment(recommendation, failure), amount -> successfulInvestment(recommendation, amount)); } InvestingSession(final Collection<LoanDescriptor> marketplace, final PowerTenant tenant); static Collection<Loan> invest(final PowerTenant tenant, final Collection<LoanDescriptor> loans,
            final InvestmentStrategy strategy);  }
@Test void successful() { final int amountToInvest = 200; final RecommendedLoan r = mockLoanDescriptor().recommend(Money.from(amountToInvest)) .get(); final Zonky z = harmlessZonky(); final PowerTenant auth = mockTenant(z); final InvestingSession t = new InvestingSession(Collections.emptySet(), auth); final boolean result = t.accept(r); assertSoftly(softly -> { softly.assertThat(result) .isTrue(); softly.assertThat(t.getAvailable()) .doesNotContain(r.descriptor()); }); final List<Loan> investments = t.getResult(); assertThat(investments).hasSize(1); final List<Event> newEvents = getEventsRequested(); assertThat(newEvents) .hasSize(1) .first() .isInstanceOf(InvestmentMadeEvent.class); verify(auth).setKnownBalanceUpperBound(eq(Money.from(Integer.MAX_VALUE - 200))); }