use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class MagicServiceImplTest method testFindAllSpellbooks.
@Test
public void testFindAllSpellbooks() throws Exception {
final WizardDao wizardDao = mock(WizardDao.class);
final SpellbookDao spellbookDao = mock(SpellbookDao.class);
final SpellDao spellDao = mock(SpellDao.class);
final MagicServiceImpl service = new MagicServiceImpl(wizardDao, spellbookDao, spellDao);
verifyZeroInteractions(wizardDao, spellbookDao, spellDao);
service.findAllSpellbooks();
verify(spellbookDao).findAll();
verifyNoMoreInteractions(wizardDao, spellbookDao, spellDao);
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class MagicServiceImplTest method testFindAllSpells.
@Test
public void testFindAllSpells() throws Exception {
final WizardDao wizardDao = mock(WizardDao.class);
final SpellbookDao spellbookDao = mock(SpellbookDao.class);
final SpellDao spellDao = mock(SpellDao.class);
final MagicServiceImpl service = new MagicServiceImpl(wizardDao, spellbookDao, spellDao);
verifyZeroInteractions(wizardDao, spellbookDao, spellDao);
service.findAllSpells();
verify(spellDao).findAll();
verifyNoMoreInteractions(wizardDao, spellbookDao, spellDao);
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class SingletonTest method testMultipleCallsReturnTheSameObjectInDifferentThreads.
/**
* Test singleton instance in a concurrent setting
*/
@Test
public void testMultipleCallsReturnTheSameObjectInDifferentThreads() throws Exception {
assertTimeout(ofMillis(10000), () -> {
// Create 10000 tasks and inside each callable instantiate the singleton class
final List<Callable<S>> tasks = new ArrayList<>();
for (int i = 0; i < 10000; i++) {
tasks.add(this.singletonInstanceMethod::get);
}
// Use up to 8 concurrent threads to handle the tasks
final ExecutorService executorService = Executors.newFixedThreadPool(8);
final List<Future<S>> results = executorService.invokeAll(tasks);
// wait for all of the threads to complete
final S expectedInstance = this.singletonInstanceMethod.get();
for (Future<S> res : results) {
final S instance = res.get();
assertNotNull(instance);
assertSame(expectedInstance, instance);
}
// tidy up the executor
executorService.shutdown();
});
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class RainbowFishSerializerTest method testWriteV1ReadV1.
/**
* Verify if a fish, written as version 1 can be read back as version 1
*/
@Test
public void testWriteV1ReadV1() throws Exception {
final File outputFile = this.testFolder.newFile();
RainbowFishSerializer.writeV1(V1, outputFile.getPath());
final RainbowFish fish = RainbowFishSerializer.readV1(outputFile.getPath());
assertNotSame(V1, fish);
assertEquals(V1.getName(), fish.getName());
assertEquals(V1.getAge(), fish.getAge());
assertEquals(V1.getLengthMeters(), fish.getLengthMeters());
assertEquals(V1.getWeightTons(), fish.getWeightTons());
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class BallItemTest method testClick.
@Test
public void testClick() {
final BallThread ballThread = mock(BallThread.class);
final BallItem ballItem = new BallItem();
ballItem.setTwin(ballThread);
final InOrder inOrder = inOrder(ballThread);
for (int i = 0; i < 10; i++) {
ballItem.click();
inOrder.verify(ballThread).suspendMe();
ballItem.click();
inOrder.verify(ballThread).resumeMe();
}
inOrder.verifyNoMoreInteractions();
}
Aggregations