Search in sources :

Example 36 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class PortfolioUpdaterTest method updatingDependants.

@Test
void updatingDependants() {
    final Zonky z = harmlessZonky(10_000);
    final Authenticated a = mockAuthentication(z);
    final PortfolioDependant dependant = mock(PortfolioDependant.class);
    final PortfolioUpdater instance = new PortfolioUpdater((t) -> {
    }, a, mockBalance(z));
    instance.registerDependant(dependant);
    instance.run();
    // this is the call to update Portfolio
    verify(a, times(2)).call(any());
    final Optional<Portfolio> result = instance.get();
    // make sure that the dependants were called with the proper value of Portfolio
    verify(dependant).accept(eq(result.get()), eq(a));
    // it's false when update finished
    assertThat(instance.isUpdating()).isFalse();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) PortfolioDependant(com.github.robozonky.app.portfolio.PortfolioDependant) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 37 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio 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 38 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class StrategyExecutorTest method doesNotInvestOnEmptyMarketplace.

@Test
void doesNotInvestOnEmptyMarketplace() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = spy(new AlwaysFreshNeverInvesting());
    e.apply(p, Collections.emptyList());
    verify(e, never()).execute(any(), any(), any());
}
Also used : 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)

Aggregations

Portfolio (com.github.robozonky.app.portfolio.Portfolio)38 Test (org.junit.jupiter.api.Test)34 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)33 Zonky (com.github.robozonky.common.remote.Zonky)30 Authenticated (com.github.robozonky.app.authentication.Authenticated)29 Event (com.github.robozonky.api.notifications.Event)16 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)13 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)12 Optional (java.util.Optional)10 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)9 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)8 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)8 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)8 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)8 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)8 InvestmentRequestedEvent (com.github.robozonky.api.notifications.InvestmentRequestedEvent)8 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)8 LoanRecommendedEvent (com.github.robozonky.api.notifications.LoanRecommendedEvent)8 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)8 PurchaseRequestedEvent (com.github.robozonky.api.notifications.PurchaseRequestedEvent)7