use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class SessionTest method properDryRun.
@Test
void properDryRun() {
final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setRemainingInvestment(200).setMyInvestment(mockMyInvestment()).build();
final Participation p = mock(Participation.class);
when(p.getLoanId()).thenReturn(l.getId());
when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
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 Zonky z = mockZonky(BigDecimal.valueOf(100_000));
when(z.getLoan(eq(l.getId()))).thenReturn(l);
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = spy(Portfolio.create(z, mockBalance(z)));
final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), true);
assertThat(i).hasSize(1);
assertThat(this.getNewEvents()).hasSize(5);
verify(z, never()).purchase(eq(p));
verify(portfolio).newBlockedAmount(eq(auth), argThat((a) -> a.getLoanId() == l.getId()));
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class InvestingTest method noItems.
@Test
void noItems() {
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(1000);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Investor.Builder builder = new Investor.Builder().asDryRun();
final Authenticated auth = mockAuthentication(z);
final Investing exec = new Investing(builder, ALL_ACCEPTING, auth);
assertThat(exec.apply(portfolio, Collections.emptyList())).isEmpty();
}
use of com.github.robozonky.common.remote.Zonky 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.common.remote.Zonky 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();
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class SessionTest method constructor.
@Test
void constructor() {
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
final Authenticated auth = mockAuthentication(z);
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
final Collection<LoanDescriptor> lds = Collections.singleton(ld);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Session it = new Session(portfolio, new LinkedHashSet<>(lds), getInvestor(auth), auth);
assertSoftly(softly -> {
softly.assertThat(it.getAvailable()).isNotSameAs(lds).containsExactly(ld);
softly.assertThat(it.getResult()).isEmpty();
});
}
Aggregations