GoogleAuthProvider extends AuthProvider { Scope[] getScopes() { return scopes; } GoogleAuthProvider(@NonNull String serverClientId, @NonNull AuthenticationAPIClient client);  GoogleAuthProvider(@NonNull String connectionName, @NonNull String serverClientId, @NonNull AuthenticationAPIClient client); void setRequiredPermissions(@NonNull String[] androidPermissions); void rememberLastLogin(boolean rememberLastLogin); void setScopes(@NonNull Scope... scope); @Override boolean authorize(int requestCode, int resultCode, @Nullable Intent intent); @Override boolean authorize(@Nullable Intent intent); @Override String[] getRequiredAndroidPermissions(); @Override void stop(); @Override void clearSession();  }
@Test public void shouldHaveNonNullScopes() throws Exception { assertThat(provider.getScopes(), is(notNullValue())); }
@Test public void shouldCallAuth0OAuthEndpointWhenGoogleTokenIsReceived() throws Exception { provider.start(activity, callback, PERMISSION_REQ_CODE, AUTH_REQ_CODE); provider.setParameters(Collections.<String, Object>singletonMap("key", "value")); when(client.loginWithOAuthAccessToken(TOKEN, CONNECTION_NAME)).thenReturn(authenticationRequest); final List<Scope> list = Arrays.asList(provider.getScopes()); provider.googleCallback.onSuccess(createGoogleSignInAccountFromToken(TOKEN, new HashSet<>(list))); ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class); verify(client).loginWithOAuthAccessToken(TOKEN, CONNECTION_NAME); verify(authenticationRequest).addAuthenticationParameters(mapCaptor.capture()); assertThat(mapCaptor.getValue(), is(notNullValue())); assertThat((Map<String, Object>) mapCaptor.getValue(), is(hasEntry("key", (Object) "value"))); }
@Test public void shouldCallAuth0OAuthEndpointWithCustomConnectionNameWhenGoogleTokenIsReceived() throws Exception { provider = new GoogleAuthProviderMock("my-custom-connection", SERVER_CLIENT_ID, client, google); provider.setParameters(Collections.<String, Object>singletonMap("key", "value")); provider.start(activity, callback, PERMISSION_REQ_CODE, AUTH_REQ_CODE); when(client.loginWithOAuthAccessToken(TOKEN, "my-custom-connection")).thenReturn(authenticationRequest); provider.googleCallback.onSuccess(createGoogleSignInAccountFromToken(TOKEN, new HashSet<>(Arrays.asList(provider.getScopes())))); ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class); verify(client).loginWithOAuthAccessToken(TOKEN, "my-custom-connection"); verify(authenticationRequest).addAuthenticationParameters(mapCaptor.capture()); assertThat(mapCaptor.getValue(), is(notNullValue())); assertThat((Map<String, Object>) mapCaptor.getValue(), is(hasEntry("key", (Object) "value"))); }
@Test public void shouldFailWithExceptionWhenCredentialsRequestFailed() { shouldFailRequest(authenticationRequest); when(client.loginWithOAuthAccessToken(TOKEN, CONNECTION_NAME)) .thenReturn(authenticationRequest); provider.start(activity, callback, PERMISSION_REQ_CODE, AUTH_REQ_CODE); provider.googleCallback.onSuccess(createGoogleSignInAccountFromToken(TOKEN, new HashSet<>(Arrays.asList(provider.getScopes())))); verify(callback).onFailure(any(AuthenticationException.class)); }
@Test public void shouldSucceedIfCredentialsRequestSucceeded() throws Exception { shouldYieldCredentialsForRequest(authenticationRequest, credentials); when(client.loginWithOAuthAccessToken(TOKEN, CONNECTION_NAME)) .thenReturn(authenticationRequest); provider.start(activity, callback, PERMISSION_REQ_CODE, AUTH_REQ_CODE); provider.googleCallback.onSuccess(createGoogleSignInAccountFromToken(TOKEN, new HashSet<>(Arrays.asList(provider.getScopes())))); verify(callback).onSuccess(eq(credentials)); }
@Test public void shouldHaveDefaultScope() throws Exception { assertThat(provider.getScopes(), is(arrayWithSize(1))); assertThat(provider.getScopes()[0].toString(), is(new Scope(Scopes.PLUS_LOGIN).toString())); }