Search in sources :

Example 6 with Spellbook

use of com.iluwatar.servicelayer.spellbook.Spellbook 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

Spellbook (com.iluwatar.servicelayer.spellbook.Spellbook)6 Spell (com.iluwatar.servicelayer.spell.Spell)4 Wizard (com.iluwatar.servicelayer.wizard.Wizard)4 SpellDao (com.iluwatar.servicelayer.spell.SpellDao)3 SpellbookDao (com.iluwatar.servicelayer.spellbook.SpellbookDao)3 WizardDao (com.iluwatar.servicelayer.wizard.WizardDao)3 SpellDaoImpl (com.iluwatar.servicelayer.spell.SpellDaoImpl)2 SpellbookDaoImpl (com.iluwatar.servicelayer.spellbook.SpellbookDaoImpl)2 WizardDaoImpl (com.iluwatar.servicelayer.wizard.WizardDaoImpl)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 MagicService (com.iluwatar.servicelayer.magic.MagicService)1 MagicServiceImpl (com.iluwatar.servicelayer.magic.MagicServiceImpl)1 ArrayList (java.util.ArrayList)1 Criteria (org.hibernate.Criteria)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1