use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class BlockedAmountsTest method newBlockedAmounts.
@Test
void newBlockedAmounts() {
final Zonky zonky = harmlessZonky(10_000);
when(zonky.getBlockedAmounts()).thenReturn(Stream.of(BA1, BA2));
final Authenticated auth = mockAuthentication(zonky);
final Portfolio p = mock(Portfolio.class);
final BlockedAmounts blockedAmounts = new BlockedAmounts();
// verify the first two blocked amounts were registered
blockedAmounts.accept(p, auth);
verify(p).newBlockedAmount(eq(auth), eq(BA1));
verify(p).newBlockedAmount(eq(auth), eq(BA2));
// verify only the new blocked amount was registered, and that it only happened the first time
reset(p);
when(zonky.getBlockedAmounts()).thenAnswer((Answer<Stream<BlockedAmount>>) invocation -> Stream.of(BA1, BA2, BA3));
blockedAmounts.accept(p, auth);
blockedAmounts.accept(p, auth);
verify(p, times(1)).newBlockedAmount(eq(auth), eq(BA3));
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class DaemonInvestmentModeTest method get.
@Test
void get() throws Exception {
final Authenticated a = mockAuthentication(mock(Zonky.class));
final Investor.Builder b = new Investor.Builder().asDryRun();
final ExecutorService e = Executors.newFixedThreadPool(1);
final PortfolioUpdater p = mock(PortfolioUpdater.class);
try {
final DaemonInvestmentMode d = new DaemonInvestmentMode(t -> {
}, a, p, b, mock(StrategyProvider.class), Duration.ofSeconds(1), Duration.ofSeconds(1));
// will block
final Future<ReturnCode> f = e.submit(() -> d.apply(lifecycle));
assertThatThrownBy(() -> f.get(1, TimeUnit.SECONDS)).isInstanceOf(TimeoutException.class);
// unblock
lifecycle.resumeToShutdown();
// should now finish
assertThat(f.get()).isEqualTo(ReturnCode.OK);
verify(p).run();
} finally {
e.shutdownNow();
}
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class DaemonOperationTest method standard.
@Test
void standard() {
final Authenticated a = mock(Authenticated.class);
final BiConsumer<Portfolio, Authenticated> operation = mock(BiConsumer.class);
final DaemonOperation d = new CustomOperation(a, operation);
d.run();
verify(operation).accept(any(), eq(a));
assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class DaemonOperationTest method exceptional.
@Test
void exceptional() {
final Authenticated a = mock(Authenticated.class);
doThrow(IllegalStateException.class).when(a).run(any());
final DaemonOperation d = new CustomOperation(a, null);
d.run();
assertThat(this.getNewEvents()).first().isInstanceOf(RoboZonkyDaemonFailedEvent.class);
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class InvestmentDaemonTest method underBalance.
@Test
void underBalance() {
final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK - 1);
final Authenticated a = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Supplier<Optional<InvestmentStrategy>> s = Optional::empty;
final InvestingDaemon d = new InvestingDaemon(t -> {
}, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
d.run();
verify(z, never()).getAvailableLoans((Select) notNull());
}
Aggregations