@Test public void ShouldDelegateToBackup_WhenActivityResultReceived() throws Exception { reset(getBackup()); activity.onActivityResult(1, Activity.RESULT_OK, null); verify(getBackup()).start(); }
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case 1: if (resultCode == RESULT_OK) { backup.start(); } break; case 2: intentPicker = null; if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); uploadToDrive(mFolderDriveId); } break; case 3: if (resultCode == RESULT_OK) { DriveId driveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); DriveFile file = driveId.asDriveFile(); downloadFromDrive(file); } else { showErrorDialog(); } finish(); break; case 4: if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); Intent intent = getIntent(); finish(); startActivity(intent); } break; } }
BackupActivity extends AppCompatActivity { @Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case 1: if (resultCode == RESULT_OK) { backup.start(); } break; case 2: intentPicker = null; if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); uploadToDrive(mFolderDriveId); } break; case 3: if (resultCode == RESULT_OK) { DriveId driveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); DriveFile file = driveId.asDriveFile(); downloadFromDrive(file); } else { showErrorDialog(); } finish(); break; case 4: if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); Intent intent = getIntent(); finish(); startActivity(intent); } break; } } }
BackupActivity extends AppCompatActivity { @Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case 1: if (resultCode == RESULT_OK) { backup.start(); } break; case 2: intentPicker = null; if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); uploadToDrive(mFolderDriveId); } break; case 3: if (resultCode == RESULT_OK) { DriveId driveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); DriveFile file = driveId.asDriveFile(); downloadFromDrive(file); } else { showErrorDialog(); } finish(); break; case 4: if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); Intent intent = getIntent(); finish(); startActivity(intent); } break; } }  }
BackupActivity extends AppCompatActivity { @Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case 1: if (resultCode == RESULT_OK) { backup.start(); } break; case 2: intentPicker = null; if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); uploadToDrive(mFolderDriveId); } break; case 3: if (resultCode == RESULT_OK) { DriveId driveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); DriveFile file = driveId.asDriveFile(); downloadFromDrive(file); } else { showErrorDialog(); } finish(); break; case 4: if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); Intent intent = getIntent(); finish(); startActivity(intent); } break; } }  @Override void onCreate(final Bundle savedInstanceState); void downloadFromDrive(DriveFile file); void connectClient(); void disconnectClient(); boolean onOptionsItemSelected(MenuItem item); }
BackupActivity extends AppCompatActivity { @Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case 1: if (resultCode == RESULT_OK) { backup.start(); } break; case 2: intentPicker = null; if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); uploadToDrive(mFolderDriveId); } break; case 3: if (resultCode == RESULT_OK) { DriveId driveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); DriveFile file = driveId.asDriveFile(); downloadFromDrive(file); } else { showErrorDialog(); } finish(); break; case 4: if (resultCode == RESULT_OK) { DriveId mFolderDriveId = data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); saveBackupFolder(mFolderDriveId.encodeToString()); Intent intent = getIntent(); finish(); startActivity(intent); } break; } }  @Override void onCreate(final Bundle savedInstanceState); void downloadFromDrive(DriveFile file); void connectClient(); void disconnectClient(); boolean onOptionsItemSelected(MenuItem item);  }