use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class PortfolioTest method getActiveForSecondaryMarketplace.
@Test
void getActiveForSecondaryMarketplace() {
final Investment i = mockInvestment(true, true);
final Investment i2 = mockInvestment(true, false);
final Investment i3 = mockInvestment(false, false);
final Investment i4 = mockInvestment(false, true);
// ignored because sold
final Investment i5 = mockSold();
final Portfolio instance = new Portfolio(Arrays.asList(i, i2, i3, i4, i5), null);
assertThat(instance.getActiveForSecondaryMarketplace()).containsExactly(i2);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class PortfolioTest method getActiveWithPaymentStatus.
@Test
void getActiveWithPaymentStatus() {
final Investment i = mockInvestment(PaymentStatus.OK);
final Investment i2 = mockInvestment(PaymentStatus.DUE);
// ignored because not interested
final Investment i3 = mockInvestment(PaymentStatus.WRITTEN_OFF);
// ignored because sold
final Investment i4 = mockSold();
final Portfolio instance = new Portfolio(Arrays.asList(i, i2, i3, i4), null);
final PaymentStatuses p = PaymentStatuses.of(PaymentStatus.OK, PaymentStatus.DUE);
assertThat(instance.getActiveWithPaymentStatus(p)).containsExactly(i, i2);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class SellingTest method saleMade.
private void saleMade(final boolean isDryRun) {
final Investment i = mockInvestment();
final Zonky zonky = mockApi();
final Portfolio portfolio = new Portfolio(Collections.singleton(i), mockBalance(zonky));
new Selling(ALL_ACCEPTING, isDryRun).accept(portfolio, mockAuthentication(zonky));
final List<Event> e = getNewEvents();
assertThat(e).hasSize(5);
assertSoftly(softly -> {
softly.assertThat(e.get(0)).isInstanceOf(SellingStartedEvent.class);
softly.assertThat(e.get(1)).isInstanceOf(SaleRecommendedEvent.class);
softly.assertThat(e.get(2)).isInstanceOf(SaleRequestedEvent.class);
softly.assertThat(e.get(3)).isInstanceOf(SaleOfferedEvent.class);
softly.assertThat(e.get(4)).isInstanceOf(SellingCompletedEvent.class);
});
final VerificationMode m = isDryRun ? never() : times(1);
assertThat(i.isOnSmp()).isTrue();
verify(zonky, m).sell(argThat(inv -> i.getLoanId() == inv.getLoanId()));
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class SellingTest method noSaleDueToStrategyForbidding.
@Test
void noSaleDueToStrategyForbidding() {
final Investment i = mockInvestment();
final Zonky zonky = mockApi();
final Portfolio portfolio = new Portfolio(Collections.singleton(i), mockBalance(zonky));
new Selling(NONE_ACCEPTING, true).accept(portfolio, mockAuthentication(zonky));
final List<Event> e = getNewEvents();
assertThat(e).hasSize(2);
assertSoftly(softly -> {
softly.assertThat(e.get(0)).isInstanceOf(SellingStartedEvent.class);
softly.assertThat(e.get(1)).isInstanceOf(SellingCompletedEvent.class);
});
verify(zonky, never()).sell(eq(i));
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class SessionTest method underBalance.
@Test
void underBalance() {
final Participation p = mock(Participation.class);
when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
final Loan l = Loan.custom().build();
final PurchaseStrategy s = mock(PurchaseStrategy.class);
when(s.recommend(any(), any(), any())).thenAnswer(i -> {
final Collection<ParticipationDescriptor> participations = i.getArgument(0);
return participations.stream().map(ParticipationDescriptor::recommend).flatMap(o -> o.map(Stream::of).orElse(Stream.empty()));
});
final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
final Zonky z = mockZonky();
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), true);
assertSoftly(softly -> {
softly.assertThat(i).isEmpty();
softly.assertThat(this.getNewEvents()).has(new Condition<List<? extends Event>>() {
@Override
public boolean matches(final List<? extends Event> events) {
return events.stream().noneMatch(e -> e instanceof PurchaseRequestedEvent);
}
});
});
}
Aggregations