@Test
public void shouldFinishLoginActivityWhenCompleted() {

    Activity context = Robolectric
            .buildActivity(Activity.class)
            .create()
            .get();
    AuthenticationRequest request = new AuthenticationRequest.Builder("test", AuthenticationResponse.Type.TOKEN, "test://test").build();
    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));
}