use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class AuthenticatedTest method restrictions.
@Test
void restrictions() {
final Zonky z = mock(Zonky.class);
when(z.getRestrictions()).thenAnswer(invocation -> mock(Restrictions.class));
final AbstractAuthenticated a = new AbstractAuthenticated() {
@Override
public <T> T call(final Function<Zonky, T> operation) {
return operation.apply(z);
}
@Override
public SecretProvider getSecretProvider() {
return null;
}
};
// stale
final Restrictions r = a.getRestrictions(Instant.now().minus(Duration.ofMinutes(10)));
assertThat(r).isNotNull();
// should refresh
final Restrictions r2 = a.getRestrictions();
assertThat(r2).isNotNull().isNotEqualTo(r);
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class LoanCacheTest method emptyGetLoan.
@Test
void emptyGetLoan() {
final LoanCache c = new LoanCache();
final int loanId = 1;
// nothing returned at first
assertThat(c.getLoan(loanId)).isEmpty();
final MyInvestment mi = mock(MyInvestment.class);
when(mi.getTimeCreated()).thenReturn(OffsetDateTime.now());
final Loan loan = Loan.custom().setId(loanId).setMyInvestment(mi).build();
final Zonky z = harmlessZonky(10_000);
when(z.getLoan(eq(loanId))).thenReturn(loan);
// return the freshly retrieved loan
assertThat(c.getLoan(loanId, z)).isEqualTo(loan);
final Investment i = Investment.custom().setLoanId(loanId).build();
assertThat(c.getLoan(i, z)).isEqualTo(loan);
assertThat(i.getInvestmentDate()).isNotEmpty();
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class StrategyExecutorTest method rechecksMarketplaceIfFirstCheckFailed.
@Test
void rechecksMarketplaceIfFirstCheckFailed() {
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);
doThrow(new IllegalStateException()).when(mocked).execute(any(), any(), any());
Assertions.assertThatThrownBy(() -> mocked.apply(p, marketplace)).isInstanceOf(IllegalStateException.class);
// now the method won't throw, but must be executed again
reset(mocked);
mocked.apply(p, marketplace);
verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
// marketplace stays the same + balance stays the same+ previous update passed = no update should be triggered
reset(mocked);
when(mocked.hasMarketplaceUpdates(eq(marketplace))).thenReturn(false);
mocked.apply(p, marketplace);
verify(mocked, never()).execute(any(), any(), any());
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class StrategyExecutorTest method doesNotInvestOnEmptyMarketplace.
@Test
void doesNotInvestOnEmptyMarketplace() {
final Zonky zonky = harmlessZonky(10_000);
final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = spy(new AlwaysFreshNeverInvesting());
e.apply(p, Collections.emptyList());
verify(e, never()).execute(any(), any(), any());
}
use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.
the class ZonkySettingsValidatorTest method properLogin.
@Test
void properLogin() {
// mock data
final ZonkyApiToken token = mock(ZonkyApiToken.class);
final OAuth oauth = mock(OAuth.class);
when(oauth.login(any(), any())).thenReturn(token);
final Zonky zonky = mock(Zonky.class);
final ApiProvider provider = mockApiProvider(oauth, token, zonky);
// execute SUT
final ZonkySettingsValidator validator = new ZonkySettingsValidator(() -> provider);
final InstallData d = ZonkySettingsValidatorTest.mockInstallData();
final DataValidator.Status result = validator.validateData(d);
// test
assertThat(result).isEqualTo(DataValidator.Status.OK);
verify(oauth).login(eq(ZonkySettingsValidatorTest.USERNAME), eq(ZonkySettingsValidatorTest.PASSWORD.toCharArray()));
verify(zonky).logout();
}
Aggregations