LoginActivity extends Activity implements AuthenticationClient.AuthenticationClientListener { @Override public void onClientComplete(AuthenticationResponse response) { Intent resultIntent = new Intent(); Bundle bundle = new Bundle(); bundle.putParcelable(RESPONSE_KEY, response); resultIntent.putExtra(EXTRA_AUTH_RESPONSE, bundle); setResult(Activity.RESULT_OK, resultIntent); finish(); }  static Intent getAuthIntent(Activity contextActivity, AuthenticationRequest request); @Override void onClientComplete(AuthenticationResponse response); @Override void onClientCancelled(); static final String REQUEST_KEY; static final String RESPONSE_KEY; static final int REQUEST_CODE; }
@Test public void shouldFinishLoginActivityWhenCompleted() { Activity context = Robolectric .buildActivity(Activity.class) .create() .get(); AuthenticationRequest request = new AuthenticationRequest.Builder("test", AuthenticationResponse.Type.TOKEN, "test: AuthenticationResponse response = new AuthenticationResponse.Builder() .setType(AuthenticationResponse.Type.TOKEN) .setAccessToken("test_token") .setExpiresIn(3600) .build(); Bundle bundle = new Bundle(); bundle.putParcelable(LoginActivity.REQUEST_KEY, request); Intent intent = new Intent(context, LoginActivity.class); intent.putExtra(LoginActivity.EXTRA_AUTH_REQUEST, bundle); ActivityController<LoginActivity> loginActivityActivityController = buildActivity(LoginActivity.class) .withIntent(intent); final LoginActivity loginActivity = loginActivityActivityController.get(); final ShadowActivity shadowLoginActivity = shadowOf(loginActivity); shadowLoginActivity.setCallingActivity(context.getComponentName()); loginActivityActivityController.create(); assertFalse(loginActivity.isFinishing()); loginActivity.onClientComplete(response); assertTrue(loginActivity.isFinishing()); assertEquals(Activity.RESULT_OK, shadowLoginActivity.getResultCode()); assertEquals(response, shadowLoginActivity.getResultIntent().getBundleExtra(LoginActivity.EXTRA_AUTH_RESPONSE).get(LoginActivity.RESPONSE_KEY)); }