use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class SessionTest method underAmount.
@Test
void underAmount() {
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(0);
final Authenticated auth = mockAuthentication(z);
final RecommendedLoan recommendation = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(Defaults.MINIMUM_INVESTMENT_IN_CZK).get();
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Session t = new Session(portfolio, Collections.singleton(recommendation.descriptor()), getInvestor(auth), auth);
final boolean result = t.invest(recommendation);
// verify result
assertThat(result).isFalse();
final List<Event> newEvents = this.getNewEvents();
assertThat(newEvents).isEmpty();
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class SessionTest method discardingInvestments.
@Test
void discardingInvestments() {
final int loanId = 1, loanId2 = 2;
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor(loanId);
final LoanDescriptor ld2 = AbstractZonkyLeveragingTest.mockLoanDescriptor(loanId2);
final Collection<LoanDescriptor> lds = Arrays.asList(ld, ld2, AbstractZonkyLeveragingTest.mockLoanDescriptor());
// discard the loan
final SessionState sst = new SessionState(lds);
sst.discard(ld);
// setup APIs
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
when(z.getLoan(eq(loanId2))).thenReturn(ld2.item());
final Authenticated auth = mockAuthentication(z);
// prepare portfolio that has the other loan as pending
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
portfolio.newBlockedAmount(auth, new BlockedAmount(loanId2, BigDecimal.valueOf(200), TransactionCategory.SMP_BUY));
// test that the loans are not available
final Session it = new Session(portfolio, new LinkedHashSet<>(lds), getInvestor(auth), auth);
assertSoftly(softly -> {
softly.assertThat(it.getAvailable()).hasSize(1).doesNotContain(ld, ld2);
softly.assertThat(it.getResult()).isEmpty();
});
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class RepaymentsTest method registerNewRepayments.
@Test
void registerNewRepayments() {
final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setRemainingInvestment(0).build();
final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.OK).build();
// first, portfolio contains one active investment; no repaid
final Zonky z = harmlessZonky(10_000);
when(z.getLoan(eq(l.getId()))).thenReturn(l);
final Portfolio p = new Portfolio(Collections.singletonList(i), mockBalance(z));
final Authenticated a = mockAuthentication(z);
final Repayments r = new Repayments();
r.accept(p, a);
assertThat(getNewEvents()).isEmpty();
// now, portfolio has the same investment marked as paid; event will be triggered
Investment.markAsPaid(i);
r.accept(p, a);
assertThat(getNewEvents()).first().isInstanceOf(LoanRepaidEvent.class);
// make sure the loan was retrieved from Zonky
verify(z).getLoan(eq(l.getId()));
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class SessionTest method empty.
@Test
void empty() {
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.empty(), null, true);
assertThat(i).isEmpty();
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class SessionTest method properReal.
@Test
void properReal() {
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()), false);
assertThat(i).hasSize(1);
assertThat(this.getNewEvents()).hasSize(5);
verify(z).purchase(eq(p));
verify(portfolio).newBlockedAmount(eq(auth), argThat((a) -> a.getLoanId() == l.getId()));
}
Aggregations