### Question:
SetupObserver extends ContentObserver { public void onChange(boolean selfChange) { boolean previousSetupComplete = mUserBackupManagerService.isSetupComplete(); boolean newSetupComplete = getSetupCompleteSettingForUser(mContext, mUserId); boolean resolvedSetupComplete = previousSetupComplete || newSetupComplete; mUserBackupManagerService.setSetupComplete(resolvedSetupComplete); if (MORE_DEBUG) { Slog.d( TAG, "Setup complete change: was=" + previousSetupComplete + " new=" + newSetupComplete + " resolved=" + resolvedSetupComplete); } synchronized (mUserBackupManagerService.getQueueLock()) { if (resolvedSetupComplete && !previousSetupComplete && mUserBackupManagerService.isEnabled()) { if (MORE_DEBUG) { Slog.d(TAG, "Setup complete so starting backups"); } KeyValueBackupJob.schedule(mUserBackupManagerService.getUserId(), mContext, mUserBackupManagerService.getConstants()); mUserBackupManagerService.scheduleNextFullBackupJob(0); } } } SetupObserver(UserBackupManagerService userBackupManagerService, Handler handler); void onChange(boolean selfChange);  }### Answer:
@Test public void testOnChange_whenNewlySetup_updatesState() throws Exception { SetupObserver setupObserver = new SetupObserver(mUserBackupManagerService, new Handler()); mUserBackupManagerService.setSetupComplete(false); changeSetupCompleteSettingForUser(true, USER_ID); setupObserver.onChange(true); assertThat(mUserBackupManagerService.isSetupComplete()).isTrue(); }
@Test public void testOnChange_whenPreviouslySetup_doesNotUpdateState() throws Exception { SetupObserver setupObserver = new SetupObserver(mUserBackupManagerService, new Handler()); mUserBackupManagerService.setSetupComplete(true); changeSetupCompleteSettingForUser(false, USER_ID); setupObserver.onChange(true); assertThat(mUserBackupManagerService.isSetupComplete()).isTrue(); }
@Test public void testOnChange_whenNotPreviouslySetup_doesNotUpdateStateIfNoChange() throws Exception { SetupObserver setupObserver = new SetupObserver(mUserBackupManagerService, new Handler()); mUserBackupManagerService.setSetupComplete(false); changeSetupCompleteSettingForUser(false, USER_ID); setupObserver.onChange(true); assertThat(mUserBackupManagerService.isSetupComplete()).isFalse(); }
@Test public void testOnChange_whenNewlySetup_schedulesBackup() throws Exception { SetupObserver setupObserver = new SetupObserver(mUserBackupManagerService, new Handler()); mUserBackupManagerService.setSetupComplete(false); changeSetupCompleteSettingForUser(true, USER_ID); mUserBackupManagerService.setEnabled(true); mUserBackupManagerService.enqueueFullBackup("testPackage", 0); setupObserver.onChange(true); assertThat( mShadowJobScheduler.getPendingJob( getJobIdForUser( KeyValueBackupJob.MIN_JOB_ID, KeyValueBackupJob.MAX_JOB_ID, USER_ID))) .isNotNull(); assertThat( mShadowJobScheduler.getPendingJob( getJobIdForUser( FullBackupJob.MIN_JOB_ID, FullBackupJob.MAX_JOB_ID, USER_ID))) .isNotNull(); }