Search in sources :

Example 6 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class FinancialCalculatorTest method actualInterest.

private static void actualInterest(final Rating rating, final int threshold) {
    final Investment i = Investment.fresh(mockLoan(rating), 1000).setInterestRate(BigDecimal.TEN).setPaidInterest(BigDecimal.valueOf(500)).setPaidPenalty(BigDecimal.ONE).setCurrentTerm(50).setSmpFee(BigDecimal.ONE);
    final BigDecimal before = FinancialCalculator.actualInterestAfterFees(i, getPortfolioOverview(threshold - 1));
    final BigDecimal after = FinancialCalculator.actualInterestAfterFees(i, getPortfolioOverview(threshold));
    assertThat(after).isGreaterThan(before);
    final BigDecimal afterSmpFee = FinancialCalculator.actualInterestAfterFees(i, getPortfolioOverview(threshold), true);
    assertThat(after).isGreaterThan(afterSmpFee);
}
Also used : BigDecimal(java.math.BigDecimal) MyInvestment(com.github.robozonky.api.remote.entities.MyInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Example 7 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class FinancialCalculatorTest method fees.

private static void fees(final Rating rating, final int threshold) {
    final Investment i = Investment.fresh(mockLoan(rating), 1000);
    final BigDecimal before = FinancialCalculator.estimateFeeRate(i, getPortfolioOverview(threshold - 1));
    final BigDecimal after = FinancialCalculator.estimateFeeRate(i, getPortfolioOverview(threshold));
    assertThat(after).isLessThan(before);
}
Also used : BigDecimal(java.math.BigDecimal) MyInvestment(com.github.robozonky.api.remote.entities.MyInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Example 8 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class JmxListenerServiceTest method getParametersForSaleOffered.

private DynamicTest getParametersForSaleOffered() {
    final Loan l = mockLoan();
    final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
    final Event evt = new SaleOfferedEvent(i, l);
    final Consumer<SoftAssertions> before = (softly) -> {
        final OperationsMBean mbean = getOperationsMBean();
        softly.assertThat(mbean.getOfferedInvestments()).isEmpty();
    };
    final Consumer<SoftAssertions> after = (softly) -> {
        final OperationsMBean mbean = getOperationsMBean();
        softly.assertThat(mbean.getOfferedInvestments()).containsOnlyKeys(i.getLoanId());
        softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
    };
    return getParameters(evt, before, after);
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) SoftAssertions(org.assertj.core.api.SoftAssertions) TestFactory(org.junit.jupiter.api.TestFactory) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) AfterAll(org.junit.jupiter.api.AfterAll) BigDecimal(java.math.BigDecimal) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) BeforeAll(org.junit.jupiter.api.BeforeAll) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Assertions(org.assertj.core.api.Assertions) ShutdownHook(com.github.robozonky.app.ShutdownHook) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) EventListener(com.github.robozonky.api.notifications.EventListener) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) DynamicTest(org.junit.jupiter.api.DynamicTest) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) AbstractRoboZonkyTest(com.github.robozonky.test.AbstractRoboZonkyTest) Collections(java.util.Collections) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) SoftAssertions(org.assertj.core.api.SoftAssertions) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Example 9 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class DelinquentsTest method noLongerDelinquent.

@Test
void noLongerDelinquent() {
    final PortfolioOverview po = mock(PortfolioOverview.class);
    final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
    final Function<Investment, Loan> f = (id) -> l;
    // register delinquence
    Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    // ignore events just emitted
    this.readPreexistingEvents();
    // the investment is no longer delinquent
    Delinquents.update(Collections.emptyList(), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanNoLongerDelinquentEvent.class);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 10 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class DelinquentsTest method paid.

@Test
void paid() {
    final PortfolioOverview po = mock(PortfolioOverview.class);
    final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.PAID).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
    final Function<Investment, Loan> f = (id) -> l;
    // register delinquence
    Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    // ignore events just emitted
    this.readPreexistingEvents();
    // the investment is paid
    Delinquents.update(Collections.emptyList(), Collections.singletonList(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanRepaidEvent.class);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)52 Test (org.junit.jupiter.api.Test)34 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)24 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)20 BigDecimal (java.math.BigDecimal)20 Event (com.github.robozonky.api.notifications.Event)13 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)13 Authenticated (com.github.robozonky.app.authentication.Authenticated)13 Zonky (com.github.robozonky.common.remote.Zonky)13 Collection (java.util.Collection)13 Assertions (org.assertj.core.api.Assertions)13 SoftAssertions (org.assertj.core.api.SoftAssertions)13 Mockito (org.mockito.Mockito)13 Collections (java.util.Collections)12 Stream (java.util.stream.Stream)11 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)10 Portfolio (com.github.robozonky.app.portfolio.Portfolio)9 Participation (com.github.robozonky.api.remote.entities.Participation)8 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)8 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)7