private BackupState skip(Iterable<DataType> types) { appLog(R.string.app_log_skip_backup_skip_messages); for (DataType type : types) { try { preferences.getDataTypePreferences().setMaxSyncedDate(type, fetcher.getMostRecentTimestamp(type)); } catch (SecurityException e ) { return new BackupState(ERROR, 0, 0, MANUAL, type, e); } } Log.i(TAG, "All messages skipped."); return new BackupState(FINISHED_BACKUP, 0, 0, MANUAL, null, null); }
@Test public void shouldReturnDefaultIfDataTypeCannotBeRead() throws Exception { for (DataType type : DataType.values()) { assertThat(fetcher.getMostRecentTimestamp(type)).isEqualTo(-1); } }
@Test public void shouldMostRecentTimestampForItemTypeMMS() throws Exception { mockMostRecentTimestampForType(MMS, 23L); assertThat(fetcher.getMostRecentTimestamp(MMS)).isEqualTo(23L); }
@Test public void shouldGetMostRecentTimestampForItemTypeSMS() throws Exception { mockMostRecentTimestampForType(SMS, 23L); assertThat(fetcher.getMostRecentTimestamp(SMS)).isEqualTo(23L); }
@Test public void shouldGetMostRecentTimestampForItemTypeCallLog() throws Exception { mockMostRecentTimestampForType(CALLLOG, 23L); assertThat(fetcher.getMostRecentTimestamp(CALLLOG)).isEqualTo(23L); }
@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(); }