### Question:
AnnotatedDaoInvoker implements DaoInvoker { public Object insert(final Object entity) { final EntityMethod method = daoRuntimeInfo.getDefaultInsertMethod(); assertMethod(method, Insert.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_insert_with_entity_return() { DaoInvoker invoker = new AnnotatedDaoInvoker(fullDao, fullDaoRuntimeInfo); Object toPersist = new Object(); Object expectedResult = new Object(); when(fullDao.insertIt(toPersist)).thenReturn(expectedResult); Object result = invoker.insert(toPersist); verify(fullDao).insertIt(same(toPersist)); assertSame(expectedResult, result); }
@Test public void test_insert_with_null_return() { DaoInvoker invoker = new AnnotatedDaoInvoker(fullDao, fullDaoRuntimeInfo); Object toPersist = new Object(); when(fullDao.insertIt(toPersist)).thenReturn(null); Object result = invoker.insert(toPersist); verify(fullDao).insertIt(same(toPersist)); assertNull(result); }
@Test public void test_insert_with_named_method() { DaoInvoker invoker = new AnnotatedDaoInvoker(fullDao, fullDaoRuntimeInfo); Object toPersist = new Object(); invoker.insert("insertIt", toPersist); invoker.insert("insertIt2", toPersist); invoker.insert("insertIt3", toPersist); verify(fullDao).insertIt(same(toPersist)); verify(fullDao).insertIt2(same(toPersist)); verify(fullDao).insertItDiff(same(toPersist)); }
@Test public void test_insert_noEntityReturned() { DaoInvoker invoker = new AnnotatedDaoInvoker(daoNoEntityReturned, daoNoEntityReturnedRuntimeInfo); Object toPersist = new Object(); when(daoNoEntityReturned.persistIt(toPersist)).thenReturn(toPersist); Object result = invoker.insert(toPersist); verify(daoNoEntityReturned).persistIt(same(toPersist)); assertNull(result); }
@Test(groups = "unit", expectedExceptions = NoMethodWithAnnotationFoundException.class) public void test_insert_no_annotation() { DaoInvoker invoker = new AnnotatedDaoInvoker(minimumDao, minimumDaoRuntimeInfo); Object toPersist = new Object(); invoker.insert(toPersist); }