use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.
the class AbstractZonkyLeveragingTest method mockLoanDescriptor.
private static LoanDescriptor mockLoanDescriptor(final int loanId, final boolean withCaptcha) {
final LoanBuilder b = Loan.custom().setId(loanId).setRemainingInvestment(Integer.MAX_VALUE).setDatePublished(OffsetDateTime.now()).setMyInvestment(mockMyInvestment());
if (withCaptcha) {
// enable CAPTCHA for the rating
System.setProperty(Settings.Key.CAPTCHA_DELAY_D.getName(), "120");
b.setRating(Rating.D);
} else {
// disable CAPTCHA for the rating
System.setProperty(Settings.Key.CAPTCHA_DELAY_AAAAA.getName(), "0");
b.setRating(Rating.AAAAA);
}
return new LoanDescriptor(b.build());
}
use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.
the class StrategyExecutorTest method rechecksMarketplaceIfFirstCheckFailed.
@Test
void rechecksMarketplaceIfFirstCheckFailed() {
final Zonky zonky = harmlessZonky(10_000);
final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
final Loan loan = Loan.custom().build();
final LoanDescriptor ld = new LoanDescriptor(loan);
final Collection<LoanDescriptor> marketplace = Collections.singleton(ld);
// prepare the executor, have it fail when executing the investment operation
final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = new AlwaysFreshNeverInvesting();
final StrategyExecutor<LoanDescriptor, InvestmentStrategy> mocked = spy(e);
doThrow(new IllegalStateException()).when(mocked).execute(any(), any(), any());
Assertions.assertThatThrownBy(() -> mocked.apply(p, marketplace)).isInstanceOf(IllegalStateException.class);
// now the method won't throw, but must be executed again
reset(mocked);
mocked.apply(p, marketplace);
verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
// marketplace stays the same + balance stays the same+ previous update passed = no update should be triggered
reset(mocked);
when(mocked.hasMarketplaceUpdates(eq(marketplace))).thenReturn(false);
mocked.apply(p, marketplace);
verify(mocked, never()).execute(any(), any(), any());
}
use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.
the class StrategyExecutorTest method doesNotInvestOnEmptyMarketplace.
@Test
void doesNotInvestOnEmptyMarketplace() {
final Zonky zonky = harmlessZonky(10_000);
final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = spy(new AlwaysFreshNeverInvesting());
e.apply(p, Collections.emptyList());
verify(e, never()).execute(any(), any(), any());
}
use of com.github.robozonky.api.strategies.LoanDescriptor 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.LoanDescriptor 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