RideRequestActivity extends Activity implements LoginCallback, RideRequestViewCallback { @Override public void onErrorReceived(@NonNull RideRequestViewError error) { rideRequestView.cancelLoad(); Intent data = new Intent(); data.putExtra(RIDE_REQUEST_ERROR, error); switch (error) { case CONNECTIVITY_ISSUE: rideRequestErrorDialog = buildRetryAlert( R.string.ub__ride_request_activity_widget_error, R.string.ub__ride_error_try_again, android.R.string.cancel, data); rideRequestErrorDialog.show(); break; case NO_ACCESS_TOKEN: case UNAUTHORIZED: accessTokenStorage.removeAccessToken(); login(); break; default: rideRequestErrorDialog = buildErrorAlert(R.string.ub__ride_request_activity_widget_error, android.R.string.ok, data); rideRequestErrorDialog.show(); } }  @NonNull static Intent newIntent(@NonNull Context context,
            @Nullable RideParameters rideParameters,
            @NonNull SessionConfiguration loginConfiguration,
            @Nullable String accessTokenStorageKey); @Override void onCreate(Bundle savedInstanceState); @Override void onErrorReceived(@NonNull RideRequestViewError error); @Override void onLoginCancel(); @Override void onLoginError(@NonNull AuthenticationError error); @Override void onLoginSuccess(@NonNull AccessToken accessToken); @Override void onAuthorizationCodeReceived(@NonNull String authorizationCode); @Override void onRequestPermissionsResult(
            int requestCode,
            @NonNull String[] permissions,
            @NonNull int[] grantResults); static final String AUTHENTICATION_ERROR; static final String RIDE_REQUEST_ERROR; }
@Test public void onLoad_whenSomeRideRequestViewErrorOccurs_shouldReturnResultIntentError() { ShadowActivity shadowActivity = shadowOf(activity); activity.onErrorReceived(RideRequestViewError.UNKNOWN); ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog); String message = "The Ride Request Widget encountered a problem."; assertEquals(message, shadowAlertDialog.getMessage()); activity.rideRequestErrorDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick(); assertNotNull(shadowActivity.getResultIntent()); assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode()); assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra (RideRequestActivity.RIDE_REQUEST_ERROR)); }
@Test public void onLoad_whenErrorOccursAndUserHitsBackWhenAlertShows_shouldReturnResultIntentError() { ShadowActivity shadowActivity = shadowOf(activity); activity.onErrorReceived(RideRequestViewError.UNKNOWN); ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog); String message = "The Ride Request Widget encountered a problem."; assertEquals(message, shadowAlertDialog.getMessage()); activity.rideRequestErrorDialog.onBackPressed(); assertNotNull(shadowActivity.getResultIntent()); assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode()); assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra (RideRequestActivity.RIDE_REQUEST_ERROR)); }