use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class InvestmentDaemonTest method standard.
@Test
void standard() {
final int loanId = 1;
final MarketplaceLoan ml = MarketplaceLoan.custom().setId(loanId).setRating(Rating.A).build();
final Loan l = Loan.custom().setId(loanId).setRating(Rating.A).build();
final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK);
when(z.getAvailableLoans((Select) notNull())).thenReturn(Stream.of(ml));
when(z.getLoan(eq(loanId))).thenReturn(l);
final Authenticated a = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final InvestmentStrategy is = mock(InvestmentStrategy.class);
final Supplier<Optional<InvestmentStrategy>> s = () -> Optional.of(is);
final InvestingDaemon d = new InvestingDaemon(t -> {
}, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
d.run();
verify(z).getAvailableLoans((Select) notNull());
verify(z).getLoan(ml.getId());
verify(is).recommend(any(), any(), any());
assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class PortfolioUpdaterTest method backoffFailed.
@Test
void backoffFailed() {
final Zonky z = harmlessZonky(10_000);
// will always fail
doThrow(IllegalStateException.class).when(z).getInvestments();
final Authenticated a = mockAuthentication(z);
final Consumer<Throwable> t = mock(Consumer.class);
final PortfolioUpdater instance = new PortfolioUpdater(t, a, mockBalance(z), Duration.ofSeconds(2));
instance.run();
assertSoftly(softly -> {
softly.assertThat(instance.get()).isEmpty();
softly.assertThat(instance.isUpdating()).isTrue();
});
verify(t).accept(notNull());
}
use of com.github.robozonky.app.authentication.Authenticated 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.authentication.Authenticated in project robozonky by RoboZonky.
the class AbstractZonkyLeveragingTest method mockAuthentication.
protected static Authenticated mockAuthentication(final Zonky zonky) {
final Authenticated auth = mock(Authenticated.class);
when(auth.getSecretProvider()).thenReturn(SecretProvider.fallback("someone", "password".toCharArray()));
when(auth.getRestrictions()).thenReturn(new Restrictions());
doAnswer(invocation -> {
final Function<Zonky, Object> operation = invocation.getArgument(0);
return operation.apply(zonky);
}).when(auth).call(any());
doAnswer(invocation -> {
final Consumer<Zonky> operation = invocation.getArgument(0);
operation.accept(zonky);
return null;
}).when(auth).run(any());
return auth;
}
Aggregations