use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class Checker method getOneLoanFromMarketplace.
static Optional<RawLoan> getOneLoanFromMarketplace(final Supplier<ApiProvider> apiProviderSupplier) {
try {
final ApiProvider p = apiProviderSupplier.get();
final Collection<RawLoan> loans = p.marketplace();
/*
* find a loan that is likely to stay on the marketplace for so long that the notification will
* successfully come through.
*/
return loans.stream().sorted(Checker.COMPARATOR).findFirst();
} catch (final Exception t) {
Checker.LOGGER.warn("Failed obtaining a loan.", t);
return Optional.empty();
}
}
use of com.github.robozonky.common.remote.ApiProvider 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();
}
use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class ZonkySettingsValidatorTest method error.
@Test
void error() {
// mock data
final OAuth oauth = mock(OAuth.class);
when(oauth.login(any(), any())).thenThrow(new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR));
final ApiProvider provider = mockApiProvider(oauth);
final InstallData d = ZonkySettingsValidatorTest.mockInstallData();
// execute SUT
final ZonkySettingsValidator validator = new ZonkySettingsValidator(() -> provider);
final DataValidator.Status result = validator.validateData(d);
// test
assertThat(result).isEqualTo(DataValidator.Status.ERROR);
}
use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class CheckerTest method confirmationsMarketplaceFail.
@Test
void confirmationsMarketplaceFail() {
final ApiProvider provider = mock(ApiProvider.class);
doThrow(new IllegalStateException("Testing")).when(provider).marketplace();
final boolean result = Checker.confirmations(mock(ConfirmationProvider.class), "", SECRET, () -> provider);
assertThat(result).isFalse();
}
Aggregations