@Test public void refreshCredential_whenNeeded_shouldReturnFalse() throws Exception { credential.setAccessToken(ACCESS_TOKEN); credential.setRefreshToken(REFRESH_TOKEN); credential.setExpiresInSeconds(OAuth2Helper.DEFAULT_REFRESH_WINDOW - 60L); mockHttpTransport.setHttpStatusCode(500); assertFalse(oAuth2Helper.refreshCredentialIfNeeded(credential)); }
@Test public void refreshCredential_whenNeeded_shouldThrowException() throws Exception { credential.setAccessToken(ACCESS_TOKEN); credential.setRefreshToken(REFRESH_TOKEN); credential.setExpiresInSeconds(OAuth2Helper.DEFAULT_REFRESH_WINDOW - 60L); mockHttpTransport.setHttpStatusCode(404); mockHttpTransport.setHttpResponseContent("failed"); exception.expect(AuthException.class); exception.expectCause(isA(IOException.class)); oAuth2Helper.refreshCredentialIfNeeded(credential); }