SampleDao { public void deleteSample(Sample sample, Long userIdMakingChange) { Database db = dbp.get(); int newUpdateSequence = sample.getUpdateSequence() + 1; Date newUpdateTime = db.nowPerApp(); db.toInsert("insert into sample_history (sample_id, sample_name, update_sequence, update_time, update_user_id," + " is_deleted) values (?,?,?,?,?,'Y')") .argLong(sample.getSampleId()) .argString(sample.getName()) .argInteger(newUpdateSequence) .argDate(newUpdateTime) .argLong(userIdMakingChange) .insert(1); db.toDelete("delete from sample where sample_id=?") .argLong(sample.getSampleId()) .update(1); sample.setUpdateSequence(newUpdateSequence); sample.setUpdateTime(newUpdateTime); } SampleDao(Supplier<Database> dbp); void createSample(final Sample sample, Long userIdMakingChange); Sample findSampleById(final Long sampleId, boolean lockRow); void updateSample(Sample sample, Long userIdMakingChange); void deleteSample(Sample sample, Long userIdMakingChange);  }
@Test public void testDelete() throws Exception { Date before = new Date(now.getTime() - 5000); Sample sample = new Sample(); sample.setSampleId(100L); sample.setName("Foo"); sample.setUpdateSequence(13); sample.setUpdateTime(before); sampleDao.deleteSample(sample, 23L); assertEquals(new Long(100L), sample.getSampleId()); assertEquals("Foo", sample.getName()); assertEquals(new Integer(14), sample.getUpdateSequence()); assertEquals(now, sample.getUpdateTime()); verify(db).update(anyString(), eq("delete from sample where sample_id=100")); verify(db).insert(eq("insert into sample_history (sample_id, sample_name, update_sequence, update_time, update_user_id, is_deleted) values (?,?,?,?,?,'Y')"), anyString()); verifyNoMoreInteractions(db); }