private void invest(final InvestmentStrategy strategy) { boolean invested; do { invested = strategy.recommend(getAvailable(), tenant.getPortfolio().getOverview(), tenant.getRestrictions()) .peek(r -> tenant.fire(loanRecommended(r))) .anyMatch(this::invest); // keep trying until investment opportunities are exhausted } while (invested); }
private void invest(final InvestmentStrategy strategy) { boolean invested; do { invested = strategy.recommend(getAvailable(), tenant.getPortfolio().getOverview(), tenant.getRestrictions()) .peek(r -> tenant.fire(loanRecommended(r))) .anyMatch(this::invest); // keep trying until investment opportunities are exhausted } while (invested); }
@Test void unacceptablePortfolioDueToLowBalance() { final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY); final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p); final PortfolioOverview portfolio = mock(PortfolioOverview.class); when(portfolio.getCzkAvailable()).thenReturn(BigDecimal.valueOf(p.getMinimumBalance() - 1)); final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(mockLoan(2))), portfolio, new Restrictions()); assertThat(result).isEmpty(); }