Search in sources :

Example 1 with Investment

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

the class InvestmentDescriptorTest method recommend.

@Test
void recommend() {
    final BigDecimal remainingPrincipal = BigDecimal.TEN;
    final Investment i = mockInvestment(remainingPrincipal);
    final InvestmentDescriptor id = new InvestmentDescriptor(i);
    final Optional<RecommendedInvestment> r = id.recommend(remainingPrincipal);
    assertThat(r).isPresent();
    assertSoftly(softly -> {
        softly.assertThat(r.get().amount()).isEqualTo(remainingPrincipal);
        softly.assertThat(r.get().descriptor()).isEqualTo(id);
    });
}
Also used : BigDecimal(java.math.BigDecimal) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test)

Example 2 with Investment

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

the class RecommendedInvestmentTest method equals.

@Test
void equals() {
    final BigDecimal remainingPrincipal = BigDecimal.TEN;
    final Investment i = mockInvestment(remainingPrincipal);
    final InvestmentDescriptor d = new InvestmentDescriptor(i);
    final RecommendedInvestment r = new RecommendedInvestment(d, remainingPrincipal);
    assertSoftly(softly -> {
        softly.assertThat(r).isNotEqualTo(null);
        softly.assertThat(r).isNotEqualTo(UUID.randomUUID().toString());
        softly.assertThat(r).isEqualTo(r);
    });
    final RecommendedInvestment r2 = new RecommendedInvestment(d, remainingPrincipal);
    assertSoftly(softly -> {
        softly.assertThat(r).isEqualTo(r2);
        softly.assertThat(r2).isEqualTo(r);
    });
    final RecommendedInvestment r3 = new RecommendedInvestment(new InvestmentDescriptor(mockInvestment(remainingPrincipal)), remainingPrincipal);
    assertThat(r).isNotEqualTo(r3);
}
Also used : BigDecimal(java.math.BigDecimal) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test)

Example 3 with Investment

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

the class ZonkyTest method sell.

@Test
void sell() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
    final Investment p = Investment.custom().setRemainingPrincipal(BigDecimal.TEN).setSmpFee(BigDecimal.ONE).setId(1).build();
    z.sell(p);
    verify(control).offer(any());
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 4 with Investment

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

the class ZonkyTest method investAndlogout.

@Test
void investAndlogout() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final int loanId = 1;
    final RawLoan loan = mock(RawLoan.class);
    when(loan.getId()).thenReturn(loanId);
    when(loan.getAmount()).thenReturn(200.0);
    when(loan.getRemainingInvestment()).thenReturn(200.0);
    when(la.execute((Function<LoanApi, RawLoan>) any())).thenReturn(loan);
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
    final Loan l = z.getLoan(loanId);
    final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
    z.invest(i);
    z.logout();
    verify(control, times(1)).invest(any());
    verify(control, times(1)).logout();
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 5 with Investment

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

the class FinancialCalculatorTest method expectedInterestRate.

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

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