use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class PortfolioOverviewTest method somePortfolio.
@Test
void somePortfolio() {
final int balance = 5000;
final Investment i1 = Investment.fresh(mockLoan(Rating.A), 400);
final Investment i2 = Investment.fresh(mockLoan(Rating.B), 600);
final PortfolioOverview o = PortfolioOverview.calculate(BigDecimal.valueOf(balance), () -> Stream.of(i1, i2));
assertSoftly(softly -> {
softly.assertThat(o.getShareOnInvestment(Rating.A)).isEqualTo(new BigDecimal("0.4"));
softly.assertThat(o.getShareOnInvestment(Rating.B)).isEqualTo(new BigDecimal("0.6"));
softly.assertThat(o.getCzkAvailable()).isEqualTo(balance);
softly.assertThat(o.getCzkInvested()).isEqualTo(1000);
softly.assertThat(o.getCzkAtRisk()).isEqualTo(0);
softly.assertThat(o.getAtRiskShareOnInvestment(Rating.A)).isEqualTo(BigDecimal.ZERO);
});
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class JmxListenerServiceTest method getParametersForInvestmentMade.
private DynamicTest getParametersForInvestmentMade() {
final Loan l = mockLoan();
final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
final PortfolioOverview po = PortfolioOverview.calculate(BigDecimal.valueOf(1000), Stream::empty);
final Event evt = new InvestmentMadeEvent(i, l, po);
final Consumer<SoftAssertions> before = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getSuccessfulInvestments()).isEmpty();
};
final Consumer<SoftAssertions> after = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getSuccessfulInvestments()).containsOnlyKeys(l.getId());
softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
};
return getParameters(evt, before, after);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class JmxListenerServiceTest method getParametersForInvestmentPurchased.
private DynamicTest getParametersForInvestmentPurchased() {
final Loan l = mockLoan();
final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
final Event evt = new InvestmentPurchasedEvent(i, l, PortfolioOverview.calculate(BigDecimal.valueOf(2000), Stream::empty));
final Consumer<SoftAssertions> before = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getPurchasedInvestments()).isEmpty();
};
final Consumer<SoftAssertions> after = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getPurchasedInvestments()).containsOnlyKeys(i.getLoanId());
softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
};
return getParameters(evt, before, after);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class DelinquentsTest method newDelinquence.
@Test
void newDelinquence() {
final PortfolioOverview po = mock(PortfolioOverview.class);
final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setAmount(200).setMyInvestment(mockMyInvestment()).build();
final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.now().minusDays(1)).build();
final Function<Investment, Loan> f = (id) -> l;
// make sure new delinquencies are reported and stored
Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertSoftly(softly -> {
softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
softly.assertThat(this.getNewEvents()).hasSize(1);
});
assertThat(this.getNewEvents().get(0)).isInstanceOf(LoanNowDelinquentEvent.class);
// make sure delinquencies are persisted even when there are none present
Delinquents.update(Collections.emptyList(), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertSoftly(softly -> {
softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
softly.assertThat(this.getNewEvents()).hasSize(2);
});
assertThat(this.getNewEvents().get(1)).isInstanceOf(LoanNoLongerDelinquentEvent.class);
// and when they are no longer active, they're gone for good
Delinquents.update(Collections.emptyList(), Collections.singleton(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertThat(Delinquents.getDelinquents()).hasSize(0);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class PortfolioTest method mockSold.
private static Investment mockSold() {
final Investment i = Investment.custom().build();
Investment.markAsSold(i);
return i;
}
Aggregations