use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.
the class SessionTest method investmentFailed.
@Test
void investmentFailed() {
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
final Authenticated auth = mockAuthentication(z);
final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
final Exception thrown = new ServiceUnavailableException();
final Investor p = mock(Investor.class);
doThrow(thrown).when(p).invest(eq(r), anyBoolean());
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
assertThatThrownBy(() -> t.invest(r)).isSameAs(thrown);
}
use of com.github.robozonky.app.portfolio.Portfolio 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.portfolio.Portfolio 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.portfolio.Portfolio 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());
}
use of com.github.robozonky.app.portfolio.Portfolio 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));
}
Aggregations