DbAdapter implements StorageService { public int deleteEvents(Table table, String lastId) { int n = 0; try { final SQLiteDatabase db = mDb.getWritableDatabase(); String deleteParams = KEY_TABLE+"=? AND "+REPORTS_TABLE+"_id <= ?"; n = db.delete(REPORTS_TABLE, deleteParams, new String[]{table.name, lastId}); } catch (final SQLiteException e) { Logger.log(TAG, "Failed to clean up events from table: " + table.name, Logger.SDK_DEBUG); mDb.delete(); } finally { mDb.close(); } return n; } DbAdapter(Context context); static DbAdapter getInstance(Context context); int addEvent(Table table, String data); int count(Table table); Batch getEvents(Table table, int limit); List<Table> getTables(); int deleteEvents(Table table, String lastId); void deleteTable(Table table); void vacuum(); static final String KEY_DATA; static final String KEY_TOKEN; static final String KEY_TABLE; static final String KEY_CREATED_AT; static final String TABLES_TABLE; static final String REPORTS_TABLE; }
@Test public void deleteEvents() { SQLiteDatabase db = mock(SQLiteDatabase.class); when(handler.getWritableDatabase()).thenReturn(db); adapter.deleteEvents(table, "100"); verify(db, times(1)).delete(eq(DbAdapter.REPORTS_TABLE), anyString(), any(String[].class)); }