use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class ZonkySettingsValidatorTest method warning.
@Test
void warning() {
// mock data
final OAuth oauth = mock(OAuth.class);
when(oauth.login(any(), any())).thenThrow(new IllegalStateException());
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.WARNING);
}
use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class ZonkySettingsValidatorTest method mockApiProvider.
private static ApiProvider mockApiProvider(final OAuth oauth, final ZonkyApiToken token, final Zonky zonky) {
final ApiProvider api = mock(ApiProvider.class);
when(api.oauth(any(Function.class))).then(i -> {
final Function f = i.getArgument(0);
return f.apply(oauth);
});
doAnswer(i -> {
final Function f = i.getArgument(1);
return f.apply(zonky);
}).when(api).authenticated(mockToken(token), any(Function.class));
doAnswer(i -> {
final Consumer f = i.getArgument(1);
f.accept(zonky);
return null;
}).when(api).authenticated(mockToken(token), any(Consumer.class));
return api;
}
use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class ZonkySettingsValidator method validateDataPossiblyThrowingException.
@Override
public DataValidator.Status validateDataPossiblyThrowingException(final InstallData installData) {
final String username = Variables.ZONKY_USERNAME.getValue(installData);
final String password = Variables.ZONKY_PASSWORD.getValue(installData);
final ApiProvider p = apiSupplier.get();
return p.oauth((oauth) -> {
try {
LOGGER.info("Logging in.");
final ZonkyApiToken token = oauth.login(username, password.toCharArray());
LOGGER.info("Logging out.");
p.authenticated(token, Zonky::logout);
return DataValidator.Status.OK;
} catch (final ServerErrorException t) {
LOGGER.log(Level.SEVERE, "Failed accessing Zonky.", t);
return DataValidator.Status.ERROR;
} catch (final Exception t) {
LOGGER.log(Level.WARNING, "Failed logging in.", t);
return DataValidator.Status.WARNING;
}
});
}
use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class CheckerTest method mockApiThatReturnsOneLoan.
private static ApiProvider mockApiThatReturnsOneLoan() {
final RawLoan l = mock(RawLoan.class);
final ApiProvider provider = mock(ApiProvider.class);
doReturn(Collections.singletonList(l)).when(provider).marketplace();
return provider;
}
use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.
the class CheckerTest method confirmationsMarketplaceWithoutLoans.
@Test
void confirmationsMarketplaceWithoutLoans() {
final ApiProvider provider = mock(ApiProvider.class);
when(provider.marketplace()).thenReturn(Collections.emptyList());
final boolean result = Checker.confirmations(mock(ConfirmationProvider.class), "", SECRET, () -> provider);
assertThat(result).isFalse();
}
Aggregations