Search in sources :

Example 41 with Loan

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

the class LoanCacheTest method emptyGetLoan.

@Test
void emptyGetLoan() {
    final LoanCache c = new LoanCache();
    final int loanId = 1;
    // nothing returned at first
    assertThat(c.getLoan(loanId)).isEmpty();
    final MyInvestment mi = mock(MyInvestment.class);
    when(mi.getTimeCreated()).thenReturn(OffsetDateTime.now());
    final Loan loan = Loan.custom().setId(loanId).setMyInvestment(mi).build();
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(loanId))).thenReturn(loan);
    // return the freshly retrieved loan
    assertThat(c.getLoan(loanId, z)).isEqualTo(loan);
    final Investment i = Investment.custom().setLoanId(loanId).build();
    assertThat(c.getLoan(i, z)).isEqualTo(loan);
    assertThat(i.getInvestmentDate()).isNotEmpty();
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MyInvestment(com.github.robozonky.api.remote.entities.MyInvestment) Zonky(com.github.robozonky.common.remote.Zonky) MyInvestment(com.github.robozonky.api.remote.entities.MyInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 42 with Loan

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

the class StrategyExecutorTest method rechecksMarketplaceIfFirstCheckFailed.

@Test
void rechecksMarketplaceIfFirstCheckFailed() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final Loan loan = Loan.custom().build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Collection<LoanDescriptor> marketplace = Collections.singleton(ld);
    // prepare the executor, have it fail when executing the investment operation
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = new AlwaysFreshNeverInvesting();
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> mocked = spy(e);
    doThrow(new IllegalStateException()).when(mocked).execute(any(), any(), any());
    Assertions.assertThatThrownBy(() -> mocked.apply(p, marketplace)).isInstanceOf(IllegalStateException.class);
    // now the method won't throw, but must be executed again
    reset(mocked);
    mocked.apply(p, marketplace);
    verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
    // marketplace stays the same + balance stays the same+  previous update passed = no update should be triggered
    reset(mocked);
    when(mocked.hasMarketplaceUpdates(eq(marketplace))).thenReturn(false);
    mocked.apply(p, marketplace);
    verify(mocked, never()).execute(any(), any(), any());
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 43 with Loan

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

the class LoanCache method getLoan.

public Loan getLoan(final int loanId, final Zonky api) {
    return getLoan(loanId).orElseGet(() -> {
        final Loan l = api.getLoan(loanId);
        addLoan(loanId, l);
        return l;
    });
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan)

Example 44 with Loan

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

the class InvestmentSizeRecommenderTest method minimumOverBalance.

@Test
void minimumOverBalance() {
    final Loan l = mockLoan(100_000);
    final ParsedStrategy s = mock(ParsedStrategy.class);
    final int minimumInvestment = 1000;
    when(s.getMinimumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment);
    when(s.getMaximumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment * 2);
    when(s.getMaximumInvestmentShareInPercent()).thenReturn(100);
    final BiFunction<Loan, Integer, Integer> r = new InvestmentSizeRecommender(s, minimumInvestment * 10);
    assertThat(r.apply(l, minimumInvestment - 1)).isEqualTo(0);
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Test(org.junit.jupiter.api.Test)

Example 45 with Loan

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

the class InvestmentSizeRecommenderTest method nothingMoreToInvest.

@Test
void nothingMoreToInvest() {
    final ParsedStrategy s = getStrategy();
    final Loan l = mockLoan(Defaults.MINIMUM_INVESTMENT_IN_CZK - 1);
    final InvestmentSizeRecommender r = new InvestmentSizeRecommender(s, Defaults.MAXIMUM_INVESTMENT_IN_CZK);
    // with unlimited balance, make maximum possible recommendation
    final int actualInvestment = r.apply(l, Integer.MAX_VALUE);
    assertThat(actualInvestment).isEqualTo(0);
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Test(org.junit.jupiter.api.Test)

Aggregations

Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)53 Test (org.junit.jupiter.api.Test)46 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)25 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)20 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)19 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)14 Zonky (com.github.robozonky.common.remote.Zonky)14 SoftAssertions (org.assertj.core.api.SoftAssertions)14 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)13 Assertions (org.assertj.core.api.Assertions)13 Mockito (org.mockito.Mockito)13 Event (com.github.robozonky.api.notifications.Event)12 Portfolio (com.github.robozonky.app.portfolio.Portfolio)12 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 Stream (java.util.stream.Stream)10 Optional (java.util.Optional)9 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)8 Participation (com.github.robozonky.api.remote.entities.Participation)8