ModelAdapter { public void delete(@NonNull ModelClass model) { Long id = getModelId(model); if (isModelExists(id)) { modelCache.removeModel(id); getDatabase().delete(tableInfo.getTableName(), tableInfo.getPrimaryKeyColumnName() + "=?", new String[]{id.toString()}); ModelChangeNotifier.get().notifyModelChanged(model, ChangeAction.DELETE); ModelChangeNotifier.get().notifyTableChanged(tableInfo.getModelClass(), ChangeAction.DELETE); } setModelId(model, 0L); } ModelAdapter(@NonNull TableInfo tableInfo); @NonNull TableInfo getTableInfo(); @NonNull ModelCache<ModelClass> getModelCache(); @Nullable ModelClass load(@NonNull Class<ModelClass> type, long id); @NonNull Long save(@NonNull ModelClass model); void delete(@NonNull ModelClass model); void loadFromCursor(@NonNull ModelClass model, @NonNull Cursor cursor); @Nullable Long getModelId(@NonNull ModelClass model); static final int INSERT_FAILED; }
@Test public void testDelete() { TestModel model = new TestModel(); testModelModelAdapter.save(model); assertEquals(1, getCount()); testModelModelAdapter.delete(model); assertEquals(0, getCount()); }