use of com.github.robozonky.api.notifications.Event 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.notifications.Event 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.api.notifications.Event 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);
}
});
});
}
use of com.github.robozonky.api.notifications.Event in project robozonky by RoboZonky.
the class SessionTest method investmentIgnoredWhenNoConfirmationProviderAndCaptcha.
@Test
void investmentIgnoredWhenNoConfirmationProviderAndCaptcha() {
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
final RecommendedLoan r = ld.recommend(200).get();
final Collection<LoanDescriptor> availableLoans = Collections.singletonList(ld);
// setup APIs
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
final Authenticated auth = mockAuthentication(z);
final Investor p = mock(Investor.class);
doReturn(new ZonkyResponse(ZonkyResponseType.REJECTED)).when(p).invest(eq(r), anyBoolean());
doReturn(Optional.empty()).when(p).getConfirmationProviderId();
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Session t = new Session(portfolio, new LinkedHashSet<>(availableLoans), p, auth);
final boolean result = t.invest(r);
assertThat(result).isFalse();
// validate event
final List<Event> newEvents = this.getNewEvents();
assertThat(newEvents).hasSize(2);
assertSoftly(softly -> {
softly.assertThat(newEvents.get(0)).isInstanceOf(InvestmentRequestedEvent.class);
softly.assertThat(newEvents.get(1)).isInstanceOf(InvestmentSkippedEvent.class);
});
}
use of com.github.robozonky.api.notifications.Event in project robozonky by RoboZonky.
the class SessionTest method underBalance.
@Test
void underBalance() {
// setup APIs
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK - 1);
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
// run test
final Session it = new Session(portfolio, Collections.emptySet(), getInvestor(auth), auth);
final Optional<RecommendedLoan> recommendation = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(BigDecimal.valueOf(Defaults.MINIMUM_INVESTMENT_IN_CZK));
final boolean result = it.invest(recommendation.get());
// verify result
assertThat(result).isFalse();
final List<Event> newEvents = this.getNewEvents();
assertThat(newEvents).isEmpty();
}
Aggregations