protected static Zonky harmlessZonky(final int availableBalance) { final Zonky zonky = mock(Zonky.class); final BigDecimal balance = BigDecimal.valueOf(availableBalance); when(zonky.getWallet()).thenReturn(new Wallet(1, 2, balance, balance)); when(zonky.getRestrictions()).thenReturn(new Restrictions(true)); when(zonky.getBlockedAmounts()).thenAnswer(i -> Stream.empty()); when(zonky.getStatistics()).thenReturn(Statistics.empty()); when(zonky.getDevelopments(anyInt())).thenAnswer(i -> Stream.empty()); return zonky; }
protected static Zonky harmlessZonky(final int availableBalance) { final Zonky zonky = mock(Zonky.class); final BigDecimal balance = BigDecimal.valueOf(availableBalance); when(zonky.getWallet()).thenReturn(new Wallet(1, 2, balance, balance)); when(zonky.getRestrictions()).thenReturn(new Restrictions(true)); when(zonky.getBlockedAmounts()).thenAnswer(i -> Stream.empty()); when(zonky.getStatistics()).thenReturn(Statistics.empty()); when(zonky.getDevelopments(anyInt())).thenAnswer(i -> Stream.empty()); return zonky; }
@Test void unacceptablePortfolioDueToLowBalance() { final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY); final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(p); final PortfolioOverview portfolio = mock(PortfolioOverview.class); when(portfolio.getCzkAvailable()).thenReturn(BigDecimal.ZERO); when(portfolio.getCzkInvested()).thenReturn(BigDecimal.ZERO); final Stream<RecommendedParticipation> result = s.recommend(Collections.singletonList(mockDescriptor()), portfolio, new Restrictions()); assertThat(result).isEmpty(); }
@Test void minimumOverRemaining() { final Restrictions restrictions = new Restrictions(); final int minimumInvestment = restrictions.getMinimumInvestmentAmount(); final Loan l = mockLoan(minimumInvestment - 1); final ParsedStrategy s = mock(ParsedStrategy.class); when(s.getMinimumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment); when(s.getMaximumInvestmentSizeInCzk(eq(l.getRating()))) .thenReturn(minimumInvestment * 2); when(s.getMaximumInvestmentShareInPercent()).thenReturn(100); final BiFunction<MarketplaceLoan, Integer, Integer> r = new InvestmentSizeRecommender(s, restrictions); assertThat(r.apply(l, minimumInvestment * 2)).isEqualTo(0); }
@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(); }
@Test void recommendationRoundedUnderMinimum() { final Restrictions restrictions = new Restrictions(); final int minimumInvestment = restrictions.getMinimumInvestmentAmount(); final Loan l = mockLoan(minimumInvestment - 1); final ParsedStrategy s = mock(ParsedStrategy.class); // next line will cause the recommendation to be rounded to 800, which will be below the minimum investment when(s.getMinimumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn( minimumInvestment - 1); when(s.getMaximumInvestmentSizeInCzk(eq(l.getRating()))) .thenReturn(minimumInvestment); when(s.getMaximumInvestmentShareInPercent()).thenReturn(100); final BiFunction<MarketplaceLoan, Integer, Integer> r = new InvestmentSizeRecommender(s, restrictions); assertThat(r.apply(l, minimumInvestment * 2)).isEqualTo(0); } }
@Test void nothingMoreToInvest() { final Restrictions restrictions = new Restrictions(); final ParsedStrategy s = getStrategy(); final Loan l = mockLoan(restrictions.getMinimumInvestmentAmount() - 1); final InvestmentSizeRecommender r = new InvestmentSizeRecommender(s, restrictions); // with unlimited balance, make maximum possible recommendation final int actualInvestment = r.apply(l, Integer.MAX_VALUE); assertThat(actualInvestment).isEqualTo(0); }