use of com.github.robozonky.api.strategies.InvestmentStrategy in project robozonky by RoboZonky.
the class InvestmentDaemonTest method standard.
@Test
void standard() {
final int loanId = 1;
final MarketplaceLoan ml = MarketplaceLoan.custom().setId(loanId).setRating(Rating.A).build();
final Loan l = Loan.custom().setId(loanId).setRating(Rating.A).build();
final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK);
when(z.getAvailableLoans((Select) notNull())).thenReturn(Stream.of(ml));
when(z.getLoan(eq(loanId))).thenReturn(l);
final Authenticated a = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final InvestmentStrategy is = mock(InvestmentStrategy.class);
final Supplier<Optional<InvestmentStrategy>> s = () -> Optional.of(is);
final InvestingDaemon d = new InvestingDaemon(t -> {
}, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
d.run();
verify(z).getAvailableLoans((Select) notNull());
verify(z).getLoan(ml.getId());
verify(is).recommend(any(), any(), any());
assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
use of com.github.robozonky.api.strategies.InvestmentStrategy 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.InvestmentStrategy 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.InvestmentStrategy 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.InvestmentStrategy 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