@Override public void onDestroy() { super.onDestroy(); if (LOCAL_LOGV) Log.v(TAG, "SmsBackupService#onDestroy(state=" + getState() + ")"); service = null; }
@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); }
@Before public void before() { initMocks(this); config = getBackupConfig(EnumSet.of(SMS)); when(service.getApplicationContext()).thenReturn(RuntimeEnvironment.application); when(service.getState()).thenReturn(state); when(preferences.getDataTypePreferences()).thenReturn(dataTypePreferences); task = new BackupTask(service, fetcher, converter, syncer, authPreferences, preferences, accessor, tokenRefresher); context = RuntimeEnvironment.application; }
@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 shouldCheckForValidStore() throws Exception { when(authPreferences.getStoreUri()).thenReturn("invalid"); Intent intent = new Intent(MANUAL.name()); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(MessagingException.class); }
@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 shouldCheckForConnectivityBeforeBackingUp() throws Exception { Intent intent = new Intent(MANUAL.name()); shadowConnectivityManager.setActiveNetworkInfo(null); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(NoConnectionException.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); }