### Question:
AnnotatedDaoInvoker implements DaoInvoker { public Object delete(final Object entity) { final EntityMethod method = daoRuntimeInfo.getDefaultDeleteMethod(); assertMethod(method, Delete.class); return method.invoke(dao, entity); } AnnotatedDaoInvoker(final Object dao, final AnnotatedDaoRuntimeInfo daoRuntimeInfo); void flush(); Object update(final Object entity); Object update(String name, Object entity); Object insert(final Object entity); Object insert(String name, Object entity); Object delete(final Object entity); Object delete(String name, Object entity); Object lookupByQuery(final String query, final Object ... parameters); Object lookupByQuery(final String query, final Map<String, ?> parameters); Object lookup(final String name, final Map<String, ?> parameters); Object lookup(final String name, final Object ... parameters);  }### Answer:
@Test public void test_update_noEntityReturned() { DaoInvoker invoker = new AnnotatedDaoInvoker(daoNoEntityReturned, daoNoEntityReturnedRuntimeInfo); Object toDelete = new Object(); when(daoNoEntityReturned.deleteIt(toDelete)).thenReturn(toDelete); Object result = invoker.delete(toDelete); verify(daoNoEntityReturned).deleteIt(same(toDelete)); assertNull(result); }
@Test public void test_delete_with_entity_return() { DaoInvoker invoker = new AnnotatedDaoInvoker(fullDao, fullDaoRuntimeInfo); Object toDelete = new Object(); Object expectedResult = new Object(); when(fullDao.deleteIt(toDelete)).thenReturn(expectedResult); Object result = invoker.delete(toDelete); verify(fullDao).deleteIt(same(toDelete)); assertSame(expectedResult, result); }
@Test public void test_delete_with_null_return() { DaoInvoker invoker = new AnnotatedDaoInvoker(fullDao, fullDaoRuntimeInfo); Object toDelete = new Object(); when(fullDao.deleteIt(toDelete)).thenReturn(null); Object result = invoker.delete(toDelete); verify(fullDao).deleteIt(same(toDelete)); assertNull(result); }
@Test public void test_delete_with_named_method() { DaoInvoker invoker = new AnnotatedDaoInvoker(fullDao, fullDaoRuntimeInfo); Object toDelete = new Object(); invoker.delete("deleteIt", toDelete); invoker.delete("deleteIt2", toDelete); invoker.delete("deleteIt3", toDelete); verify(fullDao).deleteIt(same(toDelete)); verify(fullDao).deleteIt2(same(toDelete)); verify(fullDao).deleteItDiff(same(toDelete)); }
@Test(groups = "unit", expectedExceptions = NoMethodWithAnnotationFoundException.class) public void test_delete_no_annotation() { DaoInvoker invoker = new AnnotatedDaoInvoker(minimumDao, minimumDaoRuntimeInfo); Object toDelete = new Object(); invoker.delete(toDelete); }
@Test public void test_delete_noEntityReturned() { DaoInvoker invoker = new AnnotatedDaoInvoker(daoNoEntityReturned, daoNoEntityReturnedRuntimeInfo); Object toDelete = new Object(); when(daoNoEntityReturned.deleteIt(toDelete)).thenReturn(toDelete); Object result = invoker.delete(toDelete); verify(daoNoEntityReturned).deleteIt(same(toDelete)); assertNull(result); }