Search in sources :

Example 6 with SpellbookDao

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);
}
Also used : SpellDao(com.iluwatar.servicelayer.spell.SpellDao) Spellbook(com.iluwatar.servicelayer.spellbook.Spellbook) WizardDao(com.iluwatar.servicelayer.wizard.WizardDao) SpellbookDao(com.iluwatar.servicelayer.spellbook.SpellbookDao) Wizard(com.iluwatar.servicelayer.wizard.Wizard) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

SpellDao (com.iluwatar.servicelayer.spell.SpellDao)6 SpellbookDao (com.iluwatar.servicelayer.spellbook.SpellbookDao)6 WizardDao (com.iluwatar.servicelayer.wizard.WizardDao)6 Test (org.junit.jupiter.api.Test)5 Spellbook (com.iluwatar.servicelayer.spellbook.Spellbook)3 Wizard (com.iluwatar.servicelayer.wizard.Wizard)3 Spell (com.iluwatar.servicelayer.spell.Spell)2 HashSet (java.util.HashSet)2 SpellDaoImpl (com.iluwatar.servicelayer.spell.SpellDaoImpl)1 SpellbookDaoImpl (com.iluwatar.servicelayer.spellbook.SpellbookDaoImpl)1 WizardDaoImpl (com.iluwatar.servicelayer.wizard.WizardDaoImpl)1