use of com.iluwatar.servicelayer.spellbook.SpellbookDao in project java-design-patterns by iluwatar.
the class MagicServiceImplTest method testFindWizardsWithSpellbook.
@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);
}
Aggregations