BackupItemsFetcher { public @NonNull Cursor getItemsForDataType(DataType dataType, ContactGroupIds group, int max) { if (LOCAL_LOGV) Log.v(TAG, "getItemsForDataType(type=" + dataType + ", max=" + max + ")"); return performQuery(queryBuilder.buildQueryForDataType(dataType, group, max)); } BackupItemsFetcher(@NonNull ContentResolver resolver,
                       @NonNull BackupQueryBuilder queryBuilder); @NonNull Cursor getItemsForDataType(DataType dataType, ContactGroupIds group, int max); long getMostRecentTimestamp(DataType dataType);  }
@Test public void shouldGetItemsForDataType() throws Exception { preferences.getDataTypePreferences().setBackupEnabled(true, SMS); assertThat(fetcher.getItemsForDataType(SMS, null, -1).getCount()).isEqualTo(0); verifyZeroInteractions(resolver); }
@Test public void shouldCatchSQLiteExceptions() throws Exception { preferences.getDataTypePreferences().setBackupEnabled(true, SMS); when(resolver.query(any(Uri.class), any(String[].class), anyString(), any(String[].class), anyString())) .thenThrow(new SQLiteException()); mockEmptyQuery(); assertThat(fetcher.getItemsForDataType(SMS, null, -1).getCount()).isEqualTo(0); }
@Test public void shouldCatchNullPointerExceptions() throws Exception { preferences.getDataTypePreferences().setBackupEnabled(true, SMS); when(resolver.query(any(Uri.class), any(String[].class), anyString(), any(String[].class), anyString())) .thenThrow(new NullPointerException()); mockEmptyQuery(); assertThat(fetcher.getItemsForDataType(SMS, null, -1).getCount()).isEqualTo(0); }