@Test public void batchCreateFailsWhenAnyInsertOperationFail() { List<Note> notes = new ArrayList<Note>(); Note note = new Note(); note.id = 1; notes.add(note); Note note2 = new Note(); note2.id = 1; notes.add(note2); // both elements have same primary key,therefore should fail Dao<Integer, Note> dao = dbLite.getDao(Note.class); boolean isSuccessful = dao.batchCreate(notes); Cursor cursor = db.rawQuery("SELECT * FROM Note WHERE id=?", new String[] {"1"}); Assert.assertFalse("Batch Create Did Not Fail", isSuccessful); Assert.assertFalse("Batch Create Did Not Fail", cursor.moveToFirst()); }
@Test public void batchCreateMethodTest() { List<Note> notes = new ArrayList<Note>(); Note note = new Note(); note.id = 1; notes.add(note); Note note2 = new Note(); note2.id = 2; notes.add(note2); Dao<Integer, Note> dao = dbLite.getDao(Note.class); boolean result = dao.batchCreate(notes); Cursor cursor = db.query("Note", null, null, null, null, null, null); while (cursor.moveToNext()) { Note actual = new Note(); actual.id = cursor.getInt(cursor.getColumnIndex("id")); Assert.assertEquals(actual.id, notes.get(cursor.getPosition()).id); } Assert.assertTrue(result); }