@Test public void useCustomDataStore() throws Exception { Credential credential = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod()) .setTransport(new MockHttpTransport()) .setJsonFactory(new MockJsonFactory()) .setClientAuthentication(Mockito.mock(HttpExecuteInterceptor.class))
@Test public void authenticate_whenCantAuthenticate_shouldThrowException() throws Exception { exception.expect(AuthException.class); exception.expectCause(any(IOException.class)); String authorizationCode = "authorizationCode"; mockHttpTransport.setHttpResponseContent("failed"); mockHttpTransport.setHttpStatusCode(403); OAuth2Credentials oAuth2Credentials = new OAuth2Credentials.Builder() .setClientSecrets("CLIENT_ID", "CLIENT_SECRET") .setRedirectUri("http://redirect") .setHttpTransport(mockHttpTransport) .build(); oAuth2Credentials.authenticate(authorizationCode, "userId"); }
@Before public void setUp() { mockHttpTransport = new MockHttpTransport(); }