use of com.github.robozonky.api.remote.entities.Wallet in project robozonky by RoboZonky.
the class ZonkyTest method wallet.
@Test
void wallet() {
final ControlApi control = mock(ControlApi.class);
final Api<ControlApi> ca = mockApi(control);
final PaginatedApi<RawLoan, LoanApi> la = mockApi();
final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
when(wa.execute((Function<WalletApi, Wallet>) any())).thenReturn(mock(Wallet.class));
final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
final Wallet w = z.getWallet();
assertThat(w).isNotNull();
}
use of com.github.robozonky.api.remote.entities.Wallet in project robozonky by RoboZonky.
the class RemoteBalanceImplTest method testDryRun.
@Test
void testDryRun() {
final BigDecimal startingBalance = BigDecimal.valueOf(2_000);
final Zonky z = harmlessZonky(startingBalance.intValue());
final Authenticated a = mockAuthentication(z);
final RefreshableBalance rb = new RefreshableBalance(a);
rb.run();
final RemoteBalance b = new RemoteBalanceImpl(rb, true);
Assertions.assertThat(b.get()).isEqualTo(startingBalance);
// test some local updates
b.update(THOUSAND.negate());
Assertions.assertThat(b.get()).isEqualTo(THOUSAND);
b.update(THOUSAND.negate());
Assertions.assertThat(b.get()).isEqualTo(BigDecimal.ZERO);
// make a remote update to ensure local updates are still persisted
when(z.getWallet()).thenReturn(new Wallet(startingBalance.subtract(THOUSAND)));
// register the remote update
rb.run();
Assertions.assertThat(b.get()).isEqualTo(THOUSAND.negate());
}
use of com.github.robozonky.api.remote.entities.Wallet in project robozonky by RoboZonky.
the class PurchasingTest method mockApi.
private static Zonky mockApi() {
final Zonky zonky = mock(Zonky.class);
when(zonky.getLoan(anyInt())).thenAnswer(invocation -> {
final int id = invocation.getArgument(0);
return Loan.custom().setId(id).setAmount(200).build();
});
when(zonky.getWallet()).thenReturn(new Wallet(BigDecimal.valueOf(10000), BigDecimal.valueOf(9000)));
return zonky;
}
use of com.github.robozonky.api.remote.entities.Wallet in project robozonky by RoboZonky.
the class StrategyExecutorTest method rechecksMarketplaceIfBalanceIncreased.
@Test
void rechecksMarketplaceIfBalanceIncreased() {
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);
// marketplace never has any updates
when(mocked.hasMarketplaceUpdates(any())).thenReturn(false);
// fresh balance, check marketplace
mocked.apply(p, marketplace);
verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
// nothing changed, still only ran once
mocked.apply(p, marketplace);
verify(mocked, times(1)).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
// increase remote balance
when(zonky.getWallet()).thenReturn(new Wallet(BigDecimal.valueOf(100_000)));
// should have checked marketplace
mocked.apply(p, marketplace);
verify(mocked, times(2)).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
}
use of com.github.robozonky.api.remote.entities.Wallet in project robozonky by RoboZonky.
the class AbstractZonkyLeveragingTest method harmlessZonky.
protected static Zonky harmlessZonky(final int availableBalance) {
final Zonky zonky = mock(Zonky.class);
final BigDecimal balance = BigDecimal.valueOf(availableBalance);
when(zonky.getWallet()).thenReturn(new Wallet(1, 2, balance, balance));
when(zonky.getBlockedAmounts()).thenReturn(Stream.empty());
return zonky;
}
Aggregations