AuthenticationClient { public static AuthenticationResponse getResponse(int resultCode, Intent intent) { if (resultCode == Activity.RESULT_OK && LoginActivity.getResponseFromIntent(intent) != null) { return LoginActivity.getResponseFromIntent(intent); } else { return new AuthenticationResponse.Builder() .setType(AuthenticationResponse.Type.EMPTY) .build(); } } AuthenticationClient(Activity activity); static void openLoginInBrowser(Activity contextActivity, AuthenticationRequest request); static Intent createLoginActivityIntent(Activity contextActivity, AuthenticationRequest request); static void openLoginActivity(Activity contextActivity, int requestCode, AuthenticationRequest request); static void stopLoginActivity(Activity contextActivity, int requestCode); static AuthenticationResponse getResponse(int resultCode, Intent intent); static void openDownloadSpotifyActivity(Activity contextActivity); static void openDownloadSpotifyActivity(Activity contextActivity, String campaign); static boolean isAvailable(Context ctx, Intent intent);  }
@Test public void getResponseShouldReturnAParcableIfEverythingIsOk() { String responseUrl = "testschema: "&token_type=Bearer&expires_in=3600&state=test_state"; Uri responseUri = Uri.parse(responseUrl); AuthenticationResponse result = AuthenticationResponse.fromUri(responseUri); Intent intent = mock(Intent.class); Bundle bundle = new Bundle(); bundle.putParcelable(LoginActivity.RESPONSE_KEY, result); when(intent.getBundleExtra(eq(LoginActivity.EXTRA_AUTH_RESPONSE))) .thenReturn(bundle); AuthenticationResponse response = AuthenticationClient.getResponse(Activity.RESULT_OK, intent); assertEquals(result.getType(), response.getType()); assertEquals(result.getAccessToken(), response.getAccessToken()); }
@Test public void getResponseShouldReturnEmptyWhenSomethingWentWrong() { Intent intent = mock(Intent.class); AuthenticationResponse response = AuthenticationClient.getResponse(Activity.RESULT_CANCELED, intent); assertEquals(AuthenticationResponse.Type.EMPTY, response.getType()); assertNull(response.getAccessToken()); }