public BackupConfig retryWithStore(BackupImapStore store) { return new BackupConfig(store, currentTry + 1, maxItemsPerSync, groupToBackup, backupType, typesToBackup, debug); }
private BackupState handleAuthError(BackupConfig config, XOAuth2AuthenticationFailedException e) { if (e.getStatus() == 400) { appLogDebug("need to perform xoauth2 token refresh"); if (config.currentTry < 1) { try { tokenRefresher.refreshOAuth2Token(); // we got a new token, let's handleAuthError one more time - we need to pass in a new store object // since the auth params on it are immutable appLogDebug("token refreshed, retrying"); return fetchAndBackupItems(config.retryWithStore(service.getBackupImapStore())); } catch (MessagingException ignored) { Log.w(TAG, ignored); } catch (TokenRefreshException refreshException) { appLogDebug("error refreshing token: "+refreshException+", cause="+refreshException.getCause()); } } else { appLogDebug("no new token obtained, giving up"); } } else { appLogDebug("unexpected xoauth status code " + e.getStatus()); } return transition(ERROR, e); }
@Test(expected = IllegalArgumentException.class) public void shouldCheckForDataTypesEmpty() throws Exception { new BackupConfig(mock(BackupImapStore.class), 0, -1, ContactGroup.EVERYBODY, BackupType.MANUAL, EnumSet.noneOf(DataType.class), false); }
@Test(expected = IllegalArgumentException.class) public void shouldCheckForPositiveTry() throws Exception { new BackupConfig(mock(BackupImapStore.class), -1, -1, ContactGroup.EVERYBODY, BackupType.MANUAL, EnumSet.of(DataType.MMS), false); } }
@SuppressWarnings("ConstantConditions") @Test(expected = IllegalArgumentException.class) public void shouldCheckForDataTypesNull() throws Exception { new BackupConfig(mock(BackupImapStore.class), 0, -1, ContactGroup.EVERYBODY, BackupType.MANUAL, null, false); }
private BackupConfig getBackupConfig(EnumSet<DataType> types) { return new BackupConfig(store, 0, 100, new ContactGroup(-1), BackupType.MANUAL, types, false ); }
private BackupConfig getBackupConfig(BackupType backupType, EnumSet<DataType> enabledTypes, BackupImapStore imapStore) { return new BackupConfig( imapStore, 0, getPreferences().getMaxItemsPerSync(), getPreferences().getBackupContactGroup(), backupType, enabledTypes, getPreferences().isAppLogDebug() ); }
@Test public void shouldSkipItems() throws Exception { when(fetcher.getMostRecentTimestamp(any(DataType.class))).thenReturn(-23L); BackupState finalState = task.doInBackground(new BackupConfig( store, 0, 100, new ContactGroup(-1), BackupType.SKIP, EnumSet.of(SMS), false ) ); verify(dataTypePreferences).setMaxSyncedDate(DataType.SMS, -23); verifyZeroInteractions(dataTypePreferences); assertThat(finalState).isNotNull(); assertThat(finalState.isFinished()).isTrue(); }