use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class NaturalLanguagePurchaseStrategyTest method recommendationIsMade.
@Test
void recommendationIsMade() {
final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
final ParsedStrategy ps = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap(), new FilterSupplier(v, null, Collections.emptySet()));
final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(ps);
final PortfolioOverview portfolio = mock(PortfolioOverview.class);
when(portfolio.getCzkAvailable()).thenReturn(ps.getMinimumBalance());
when(portfolio.getCzkInvested()).thenReturn(ps.getMaximumInvestmentSizeInCzk() - 1);
when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
final Participation p = spy(mockParticipation());
// not recommended due to balance
doReturn(BigDecimal.valueOf(100000)).when(p).getRemainingPrincipal();
doReturn(Rating.A).when(p).getRating();
final Participation p2 = spy(mockParticipation());
// check amounts under Zonky investment minimum
final int amount = Defaults.MINIMUM_INVESTMENT_IN_CZK - 1;
doReturn(BigDecimal.valueOf(amount)).when(p2).getRemainingPrincipal();
doReturn(Rating.A).when(p2).getRating();
final ParticipationDescriptor pd = mockDescriptor(p2);
final List<RecommendedParticipation> result = s.recommend(Arrays.asList(mockDescriptor(p), pd), portfolio, new Restrictions()).collect(Collectors.toList());
assertThat(result).hasSize(1);
final RecommendedParticipation r = result.get(0);
assertSoftly(softly -> {
softly.assertThat(r.descriptor()).isEqualTo(pd);
softly.assertThat(r.amount()).isEqualTo(pd.item().getRemainingPrincipal());
});
}
use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class ParsedStrategyTest method matchesAlsoSellFilter.
@Test
void matchesAlsoSellFilter() {
final MarketplaceFilter accepting = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
final Collection<MarketplaceFilter> filters = Collections.singleton(accepting);
final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
final FilterSupplier s = new FilterSupplier(v, Collections.emptySet(), Collections.emptySet(), filters);
final ParsedStrategy ps = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap(), s);
final Loan l = mockLoan(200_000);
final LoanDescriptor ld = new LoanDescriptor(l);
assertThat(ps.getApplicableLoans(Collections.singleton(ld))).isEmpty();
final Participation p = mock(Participation.class);
final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
assertThat(ps.getApplicableParticipations(Collections.singleton(pd))).isEmpty();
}
use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class ZonkyTest method purchase.
@Test
void purchase() {
final ControlApi control = mock(ControlApi.class);
final Api<ControlApi> ca = mockApi(control);
final PaginatedApi<RawLoan, LoanApi> la = mockApi();
final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
final Participation p = mock(Participation.class);
when(p.getRemainingPrincipal()).thenReturn(BigDecimal.TEN);
when(p.getId()).thenReturn(1);
z.purchase(p);
verify(control).purchase(eq(p.getId()), any());
}
use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class ZonkyTest method cancel.
@Test
void cancel() {
final ControlApi control = mock(ControlApi.class);
final Api<ControlApi> ca = mockApi(control);
final PaginatedApi<RawLoan, LoanApi> la = mockApi();
final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
final Investment i = mock(Investment.class);
when(i.getId()).thenReturn(1);
z.cancel(i);
verify(control).cancel(eq(i.getId()));
}
Aggregations