use of com.github.robozonky.api.notifications.PurchaseRequestedEvent in project robozonky by RoboZonky.
the class Session method purchase.
public boolean purchase(final RecommendedParticipation recommendation) {
Events.fire(new PurchaseRequestedEvent(recommendation));
final Participation participation = recommendation.descriptor().item();
final Loan loan = recommendation.descriptor().related();
final boolean purchased = isDryRun || actualPurchase(participation);
if (purchased) {
final Investment i = Investment.fresh(participation, loan, recommendation.amount());
markSuccessfulPurchase(i);
Events.fire(new InvestmentPurchasedEvent(i, loan, portfolioOverview));
}
return purchased;
}
use of com.github.robozonky.api.notifications.PurchaseRequestedEvent 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