@Test public void shouldGetAndSetBackgroundDataSetting() throws Exception { assertThat(connectivityManager.getBackgroundDataSetting()).isFalse(); shadowOf(connectivityManager).setBackgroundDataSetting(true); assertThat(connectivityManager.getBackgroundDataSetting()).isTrue(); }
@Test public void shouldCheckForLoginCredentials() throws Exception { Intent intent = new Intent(); when(authPreferences.isLoginInformationSet()).thenReturn(false); shadowConnectivityManager.setBackgroundDataSetting(true); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(RequiresLoginException.class); }
@Test public void shouldCheckForEnabledDataTypes() throws Exception { when(dataTypePreferences.enabled()).thenReturn(EnumSet.noneOf(DataType.class)); Intent intent = new Intent(); when(authPreferences.isLoginInformationSet()).thenReturn(true); shadowConnectivityManager.setBackgroundDataSetting(true); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(BackupDisabledException.class); assertThat(service.getState().state).isEqualTo(SmsSyncState.FINISHED_BACKUP); }
@Test public void shouldCheckForWifiConnectivity() throws Exception { Intent intent = new Intent(); when(preferences.isWifiOnly()).thenReturn(true); shadowConnectivityManager.setBackgroundDataSetting(true); shadowWifiManager.setWifiEnabled(false); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(RequiresWifiException.class); }
@Test public void shouldNotCheckForConnectivityBeforeBackingUpWithNewScheduler() throws Exception { when(preferences.isUseOldScheduler()).thenReturn(false); Intent intent = new Intent(REGULAR.name()); shadowConnectivityManager.setActiveNetworkInfo(null); shadowConnectivityManager.setBackgroundDataSetting(true); service.handleIntent(intent); verify(backupTask).execute(any(BackupConfig.class)); }
@Test public void shouldCheckForWifiConnectivityAndNetworkType() throws Exception { Intent intent = new Intent(); when(preferences.isWifiOnly()).thenReturn(true); shadowConnectivityManager.setBackgroundDataSetting(true); shadowConnectivityManager.setActiveNetworkInfo(connectedViaEdge()); shadowWifiManager.setWifiEnabled(true); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(RequiresWifiException.class); }
@Test public void shouldScheduleNextRegularBackupAfterFinished() throws Exception { shadowConnectivityManager.setBackgroundDataSetting(true); Intent intent = new Intent(REGULAR.name()); service.handleIntent(intent); verify(backupTask).execute(any(BackupConfig.class)); service.backupStateChanged(service.transition(SmsSyncState.FINISHED_BACKUP, null)); verify(backupJobs).scheduleRegular(); assertThat(shadowOf(service).isStoppedBySelf()).isTrue(); assertThat(shadowOf(service).isForegroundStopped()).isTrue(); }