use of com.github.robozonky.api.strategies.RecommendedLoan in project robozonky by RoboZonky.
the class SessionTest method investmentFailed.
@Test
void investmentFailed() {
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
final Authenticated auth = mockAuthentication(z);
final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
final Exception thrown = new ServiceUnavailableException();
final Investor p = mock(Investor.class);
doThrow(thrown).when(p).invest(eq(r), anyBoolean());
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
assertThatThrownBy(() -> t.invest(r)).isSameAs(thrown);
}
use of com.github.robozonky.api.strategies.RecommendedLoan in project robozonky by RoboZonky.
the class NaturalLanguageInvestmentStrategyTest method recommendationIsMade.
@Test
void recommendationIsMade() {
final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, Collections.emptySet());
final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p);
final PortfolioOverview portfolio = mock(PortfolioOverview.class);
when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk() - 1);
when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
final Loan l = mockLoan(100_000);
final Loan l2 = mockLoan(100);
final LoanDescriptor ld = new LoanDescriptor(l);
final List<RecommendedLoan> result = s.recommend(Arrays.asList(new LoanDescriptor(l2), ld), portfolio, new Restrictions()).collect(Collectors.toList());
assertThat(result).hasSize(1);
final RecommendedLoan r = result.get(0);
assertSoftly(softly -> {
softly.assertThat(r.descriptor()).isEqualTo(ld);
softly.assertThat(r.amount()).isEqualTo(BigDecimal.valueOf(Defaults.MINIMUM_INVESTMENT_IN_CZK));
softly.assertThat(r.isConfirmationRequired()).isFalse();
});
}
use of com.github.robozonky.api.strategies.RecommendedLoan in project robozonky by RoboZonky.
the class NaturalLanguageInvestmentStrategyTest method unacceptablePortfolioDueToOverInvestment.
@Test
void unacceptablePortfolioDueToOverInvestment() {
final DefaultValues v = new DefaultValues(DefaultPortfolio.EMPTY);
v.setTargetPortfolioSize(1000);
final ParsedStrategy p = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap());
final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p);
final PortfolioOverview portfolio = mock(PortfolioOverview.class);
when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk());
final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(mockLoan(2))), portfolio, new Restrictions());
assertThat(result).isEmpty();
}
Aggregations