MagicServiceImpl implements MagicService { @Override public List<Wizard> findWizardsWithSpellbook(String name) { Spellbook spellbook = spellbookDao.findByName(name); return new ArrayList<>(spellbook.getWizards()); } MagicServiceImpl(WizardDao wizardDao, SpellbookDao spellbookDao, SpellDao spellDao); @Override List<Wizard> findAllWizards(); @Override List<Spellbook> findAllSpellbooks(); @Override List<Spell> findAllSpells(); @Override List<Wizard> findWizardsWithSpellbook(String name); @Override List<Wizard> findWizardsWithSpell(String name);  }
@Test public void testFindWizardsWithSpellbook() throws Exception { final String bookname = "bookname"; final Spellbook spellbook = mock(Spellbook.class); final Set<Wizard> wizards = new HashSet<>(); wizards.add(mock(Wizard.class)); wizards.add(mock(Wizard.class)); wizards.add(mock(Wizard.class)); when(spellbook.getWizards()).thenReturn(wizards); final SpellbookDao spellbookDao = mock(SpellbookDao.class); when(spellbookDao.findByName(eq(bookname))).thenReturn(spellbook); final WizardDao wizardDao = mock(WizardDao.class); final SpellDao spellDao = mock(SpellDao.class); final MagicServiceImpl service = new MagicServiceImpl(wizardDao, spellbookDao, spellDao); verifyZeroInteractions(wizardDao, spellbookDao, spellDao, spellbook); final List<Wizard> result = service.findWizardsWithSpellbook(bookname); verify(spellbookDao).findByName(eq(bookname)); verify(spellbook).getWizards(); assertNotNull(result); assertEquals(3, result.size()); verifyNoMoreInteractions(wizardDao, spellbookDao, spellDao); }