use of com.github.robozonky.common.remote.Zonky 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.common.remote.Zonky in project robozonky by RoboZonky.
the class SellingTest method noSaleDueToNoData.
@Test
void noSaleDueToNoData() {
// no data is inserted into portfolio, therefore nothing happens
final Zonky zonky = mockApi();
final Portfolio portfolio = new Portfolio(mockBalance(zonky));
new Selling(ALL_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(any());
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class PurchasingTest method noneAccepted.
@Test
void noneAccepted() {
final Zonky zonky = mockApi();
final Participation mock = mock(Participation.class);
when(mock.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(250));
final Purchasing exec = new Purchasing(NONE_ACCEPTING, mockAuthentication(zonky), true);
final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
final List<Event> e = this.getNewEvents();
assertThat(e).hasSize(2);
assertSoftly(softly -> {
softly.assertThat(e).first().isInstanceOf(PurchasingStartedEvent.class);
softly.assertThat(e).last().isInstanceOf(PurchasingCompletedEvent.class);
});
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class PurchasingTest method someAccepted.
@Test
void someAccepted() {
final int loanId = 1;
final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setRemainingInvestment(1000).setMyInvestment(mockMyInvestment()).setDatePublished(OffsetDateTime.now()).build();
final Zonky zonky = mockApi();
when(zonky.getLoan(eq(loanId))).thenReturn(loan);
final Participation mock = mock(Participation.class);
when(mock.getId()).thenReturn(1);
when(mock.getLoanId()).thenReturn(loan.getId());
when(mock.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(250));
when(mock.getRating()).thenReturn(loan.getRating());
final Purchasing exec = new Purchasing(ALL_ACCEPTING, mockAuthentication(zonky), true);
final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
assertThat(exec.apply(portfolio, Collections.singleton(mock))).isNotEmpty();
// purchase as balance changed
verify(zonky, never()).purchase(eq(mock));
final List<Event> e = this.getNewEvents();
assertThat(e).hasSize(5);
assertSoftly(softly -> {
softly.assertThat(e).first().isInstanceOf(PurchasingStartedEvent.class);
softly.assertThat(e.get(1)).isInstanceOf(PurchaseRecommendedEvent.class);
softly.assertThat(e.get(2)).isInstanceOf(PurchaseRequestedEvent.class);
softly.assertThat(e.get(3)).isInstanceOf(InvestmentPurchasedEvent.class);
softly.assertThat(e).last().isInstanceOf(PurchasingCompletedEvent.class);
});
// purchase as marketplace first initialized
assertThat(exec.apply(portfolio, Collections.singleton(mock))).isNotEmpty();
// no balance change, no marketplace change => don't purchase
assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
// nothing changed, so no more purchase
verify(zonky, never()).purchase(eq(mock));
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class PurchasingTest method mockApi.
private static Zonky mockApi() {
final Zonky zonky = mock(Zonky.class);
when(zonky.getLoan(anyInt())).thenAnswer(invocation -> {
final int id = invocation.getArgument(0);
return Loan.custom().setId(id).setAmount(200).build();
});
when(zonky.getWallet()).thenReturn(new Wallet(BigDecimal.valueOf(10000), BigDecimal.valueOf(9000)));
return zonky;
}
Aggregations