InvestingSession extends AbstractSession<RecommendedLoan, LoanDescriptor, Loan> { public static Collection<Loan> invest(final PowerTenant tenant, final Collection<LoanDescriptor> loans, final InvestmentStrategy strategy) { final InvestingSession s = new InvestingSession(loans, tenant); final PortfolioOverview portfolioOverview = tenant.getPortfolio() .getOverview(); s.tenant.fire(executionStartedLazy(() -> executionStarted(portfolioOverview))); if (!s.getAvailable() .isEmpty()) { s.invest(strategy); } final Collection<Loan> result = s.getResult(); s.tenant.fire(executionCompletedLazy(() -> executionCompleted(result, tenant.getPortfolio() .getOverview()))); return Collections.unmodifiableCollection(result); } InvestingSession(final Collection<LoanDescriptor> marketplace, final PowerTenant tenant); static Collection<Loan> invest(final PowerTenant tenant, final Collection<LoanDescriptor> loans,
            final InvestmentStrategy strategy);  }
@Test void makeInvestment() { final Zonky z = harmlessZonky(); final int amount = 200; final LoanDescriptor ld = mockLoanDescriptor(); final int loanId = ld.item() .getId(); final PowerTenant auth = mockTenant(z); final Collection<LoanDescriptor> lds = Arrays.asList(ld, mockLoanDescriptor()); final Collection<Loan> i = InvestingSession.invest(auth, lds, mockStrategy(loanId, amount)); assertThat(i).hasSize(1); final List<Event> newEvents = getEventsRequested(); assertThat(newEvents).hasSize(4); assertSoftly(softly -> { softly.assertThat(newEvents.get(0)) .isInstanceOf(ExecutionStartedEvent.class); softly.assertThat(newEvents.get(1)) .isInstanceOf(LoanRecommendedEvent.class); softly.assertThat(newEvents.get(2)) .isInstanceOf(InvestmentMadeEvent.class); softly.assertThat(newEvents.get(3)) .isInstanceOf(ExecutionCompletedEvent.class); }); verify(auth).setKnownBalanceUpperBound(eq(Money.from(Integer.MAX_VALUE - 200))); }