use of com.github.robozonky.common.remote.Zonky 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.common.remote.Zonky 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.common.remote.Zonky in project robozonky by RoboZonky.
the class PurchasingTest method noItems.
@Test
void noItems() {
final Zonky zonky = mockApi();
final Purchasing exec = new Purchasing(ALL_ACCEPTING, mockAuthentication(zonky), true);
final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
assertThat(exec.apply(portfolio, Collections.emptyList())).isEmpty();
final List<Event> e = this.getNewEvents();
assertThat(e).isEmpty();
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class SessionTest method mockZonky.
private static Zonky mockZonky(final BigDecimal balance) {
final Zonky zonky = mock(Zonky.class);
when(zonky.getWallet()).thenReturn(new Wallet(balance, balance));
return zonky;
}
use of com.github.robozonky.common.remote.Zonky 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