GitHubAuthenticatorImpl implements GitHubAuthenticator, OAuthCallback, GitHubAuthenticatorViewImpl.ActionDelegate { @Override public void onAuthenticated(OAuthStatus authStatus) { if (view.isGenerateKeysSelected()) { generateSshKeys(authStatus); return; } callback.onSuccess(authStatus); } @Inject  GitHubAuthenticatorImpl(SshKeyService sshKeyService,
                                   GitHubAuthenticatorView view,
                                   DialogFactory dialogFactory,
                                   GitHubLocalizationConstant locale,
                                   @RestContext String baseUrl,
                                   DtoUnmarshallerFactory dtoUnmarshallerFactory,
                                   NotificationManager notificationManager,
                                   AppContext appContext); @Override void authorize(@NotNull final AsyncCallback<OAuthStatus> callback); @Override void onCancelled(); @Override void onAccepted(); @Override void onAuthenticated(OAuthStatus authStatus); static final String GITHUB_HOST; }
@Test public void onAuthenticatedWhenGenerateKeysIsSelected() throws Exception { String userId = "userId"; OAuthStatus authStatus = mock(OAuthStatus.class); SshKeyProvider keyProvider = mock(SshKeyProvider.class); Map<String, SshKeyProvider> providers = new HashMap<>(); providers.put(GITHUB_HOST, keyProvider); CurrentUser user = mock(CurrentUser.class); ProfileDescriptor profile = mock(ProfileDescriptor.class); when(view.isGenerateKeysSelected()).thenReturn(true); when(sshKeyService.getSshKeyProviders()).thenReturn(providers); when(appContext.getCurrentUser()).thenReturn(user); when(user.getProfile()).thenReturn(profile); when(profile.getId()).thenReturn(userId); gitHubAuthenticator.onAuthenticated(authStatus); verify(view).isGenerateKeysSelected(); verify(sshKeyService, times(2)).getSshKeyProviders(); verify(appContext).getCurrentUser(); verify(keyProvider).generateKey(eq(userId), Matchers.<AsyncCallback<Void>>anyObject()); }