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();
}
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());
}
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());
}
Aggregations