DatabasePersistence extends Persistence { @Override public void clearPendingLogState() { mPendingDbIdentifiers.clear(); mPendingDbIdentifiersGroups.clear(); AppCenterLog.debug(LOG_TAG, "Cleared pending log states"); } DatabasePersistence(Context context);   DatabasePersistence(Context context, int version, @SuppressWarnings("SameParameterValue") final ContentValues schema); @Override boolean setMaxStorageSize(long maxStorageSizeInBytes); @Override long putLog(@NonNull Log log, @NonNull String group, @IntRange(from = Flags.NORMAL, to = Flags.CRITICAL) int flags); @Override void deleteLogs(@NonNull String group, @NonNull String id); @Override void deleteLogs(String group); @Override int countLogs(@NonNull String group); @Override @Nullable String getLogs(@NonNull String group, @NonNull Collection<String> pausedTargetKeys, @IntRange(from = 0) int limit, @NonNull List<Log> outLogs); @Override void clearPendingLogState(); @Override void close();  }
@Test public void clearPendingLogState() throws Exception { final int groupCount = 4; final int logCount = 10; List<List<ContentValues>> list = new ArrayList<>(); for (int i = 0; i < groupCount; i++) { List<ContentValues> iterator = new ArrayList<>(); for (long l = 1; l <= logCount; l++) { ContentValues values = mock(ContentValues.class); when(values.getAsLong(DatabaseManager.PRIMARY_KEY)).thenReturn(l + i * logCount); when(values.getAsString(DatabasePersistence.COLUMN_LOG)).thenReturn("{}"); iterator.add(values); } list.add(iterator); } DatabaseManager mockDatabaseManager = mock(DatabaseManager.class); whenNew(DatabaseManager.class).withAnyArguments().thenReturn(mockDatabaseManager); when(mockDatabaseManager.nextValues(any(Cursor.class))).thenCallRealMethod(); for (int i = 0; i < groupCount; i++) { MockCursor mockCursor = new MockCursor(list.get(i)); mockCursor.mockBuildValues(mockDatabaseManager); when(mockDatabaseManager.getCursor(any(SQLiteQueryBuilder.class), any(String[].class), eq(new String[]{String.valueOf(i)}), anyString())) .thenReturn(mockCursor); } LogSerializer mockLogSerializer = mock(LogSerializer.class); when(mockLogSerializer.deserializeLog(anyString(), anyString())).thenReturn(mock(Log.class)); DatabasePersistence persistence = new DatabasePersistence(mock(Context.class)); persistence.setLogSerializer(mockLogSerializer); for (int i = 0; i < groupCount; i++) { persistence.getLogs(String.valueOf(i), Collections.<String>emptyList(), logCount, new ArrayList<Log>()); } assertEquals(groupCount, persistence.mPendingDbIdentifiersGroups.size()); assertEquals(groupCount * logCount, persistence.mPendingDbIdentifiers.size()); persistence.clearPendingLogState(); assertEquals(0, persistence.mPendingDbIdentifiersGroups.size()); assertEquals(0, persistence.mPendingDbIdentifiers.size()); }