Search in sources :

Example 1 with Wallet

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();
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) Wallet(com.github.robozonky.api.remote.entities.Wallet) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 2 with Wallet

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());
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Wallet(com.github.robozonky.api.remote.entities.Wallet) BigDecimal(java.math.BigDecimal) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 3 with Wallet

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;
}
Also used : Wallet(com.github.robozonky.api.remote.entities.Wallet) Zonky(com.github.robozonky.common.remote.Zonky)

Example 4 with Wallet

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));
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Wallet(com.github.robozonky.api.remote.entities.Wallet) Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 5 with Wallet

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;
}
Also used : Wallet(com.github.robozonky.api.remote.entities.Wallet) BigDecimal(java.math.BigDecimal) Zonky(com.github.robozonky.common.remote.Zonky)

Aggregations

Wallet (com.github.robozonky.api.remote.entities.Wallet)7 Zonky (com.github.robozonky.common.remote.Zonky)6 Test (org.junit.jupiter.api.Test)3 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)2 BigDecimal (java.math.BigDecimal)2 CollectionsApi (com.github.robozonky.api.remote.CollectionsApi)1 ControlApi (com.github.robozonky.api.remote.ControlApi)1 LoanApi (com.github.robozonky.api.remote.LoanApi)1 ParticipationApi (com.github.robozonky.api.remote.ParticipationApi)1 PortfolioApi (com.github.robozonky.api.remote.PortfolioApi)1 WalletApi (com.github.robozonky.api.remote.WalletApi)1 BlockedAmount (com.github.robozonky.api.remote.entities.BlockedAmount)1 Participation (com.github.robozonky.api.remote.entities.Participation)1 RawDevelopment (com.github.robozonky.api.remote.entities.RawDevelopment)1 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)1 RawLoan (com.github.robozonky.api.remote.entities.RawLoan)1 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)1 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)1 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)1 Authenticated (com.github.robozonky.app.authentication.Authenticated)1