Search in sources :

Example 36 with Test

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

Example 37 with Test

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

Example 38 with Test

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();
    });
}
Also used : ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) Test(org.junit.jupiter.api.Test)

Example 39 with Test

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());
}
Also used : File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 40 with Test

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();
}
Also used : InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)265 BigInteger (java.math.BigInteger)50 JsonObject (io.vertx.core.json.JsonObject)20 NemAnnounceResult (com.github.rosklyar.client.transaction.domain.NemAnnounceResult)15 PublicAccount (io.nem.sdk.model.account.PublicAccount)14 AnalysisResult (io.github.vocabhunter.analysis.model.AnalysisResult)12 Address (io.nem.sdk.model.account.Address)10 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)10 ExecutorService (java.util.concurrent.ExecutorService)9 UnconfirmedTransactions (com.github.rosklyar.client.account.domain.transaction.UnconfirmedTransactions)7 MosaicId (com.github.rosklyar.client.transaction.domain.mosaic.MosaicId)7 Transactions (com.github.rosklyar.client.account.domain.transaction.Transactions)6 PsiClass (com.intellij.psi.PsiClass)6 Mosaic (io.nem.sdk.model.mosaic.Mosaic)6 MosaicId (io.nem.sdk.model.mosaic.MosaicId)6 Disabled (org.junit.jupiter.api.Disabled)6 DisplayName (org.junit.jupiter.api.DisplayName)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 InOrder (org.mockito.InOrder)6 SpellDao (com.iluwatar.servicelayer.spell.SpellDao)5