Search in sources :

Example 6 with Test

use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.

the class UserCreatedEventTest method testGetEventType.

/**
 * This unit test should correctly return the {@link AbstractEvent} class type when calling the
 * {@link AbstractEvent#getType() getType} method.
 */
@Test
public void testGetEventType() {
    User user = new User("iluwatar");
    UserCreatedEvent userCreatedEvent = new UserCreatedEvent(user);
    assertEquals(UserCreatedEvent.class, userCreatedEvent.getType());
}
Also used : User(com.iluwatar.eda.model.User) Test(org.junit.jupiter.api.Test)

Example 7 with Test

use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.

the class EventDispatcherTest method testEventDriverPattern.

/**
 * This unit test should register events and event handlers correctly with the event dispatcher
 * and events should be dispatched accordingly.
 */
@Test
public void testEventDriverPattern() {
    EventDispatcher dispatcher = spy(new EventDispatcher());
    UserCreatedEventHandler userCreatedEventHandler = spy(new UserCreatedEventHandler());
    UserUpdatedEventHandler userUpdatedEventHandler = spy(new UserUpdatedEventHandler());
    dispatcher.registerHandler(UserCreatedEvent.class, userCreatedEventHandler);
    dispatcher.registerHandler(UserUpdatedEvent.class, userUpdatedEventHandler);
    User user = new User("iluwatar");
    UserCreatedEvent userCreatedEvent = new UserCreatedEvent(user);
    UserUpdatedEvent userUpdatedEvent = new UserUpdatedEvent(user);
    // fire a userCreatedEvent and verify that userCreatedEventHandler has been invoked.
    dispatcher.dispatch(userCreatedEvent);
    verify(userCreatedEventHandler).onEvent(userCreatedEvent);
    verify(dispatcher).dispatch(userCreatedEvent);
    // fire a userCreatedEvent and verify that userUpdatedEventHandler has been invoked.
    dispatcher.dispatch(userUpdatedEvent);
    verify(userUpdatedEventHandler).onEvent(userUpdatedEvent);
    verify(dispatcher).dispatch(userUpdatedEvent);
}
Also used : UserCreatedEvent(com.iluwatar.eda.event.UserCreatedEvent) User(com.iluwatar.eda.model.User) UserCreatedEventHandler(com.iluwatar.eda.handler.UserCreatedEventHandler) UserUpdatedEvent(com.iluwatar.eda.event.UserUpdatedEvent) UserUpdatedEventHandler(com.iluwatar.eda.handler.UserUpdatedEventHandler) Test(org.junit.jupiter.api.Test)

Example 8 with Test

use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.

the class SimpleFileWriterTest method testActualWrite.

/**
 * Test if the data written to the file writer actually gets in the file
 */
@Test
public void testActualWrite() throws Exception {
    final String testMessage = "Test message";
    final File temporaryFile = this.testFolder.newFile();
    assertTrue(temporaryFile.exists());
    new SimpleFileWriter(temporaryFile.getPath(), writer -> writer.write(testMessage));
    assertTrue(Files.lines(temporaryFile.toPath()).allMatch(testMessage::equals));
}
Also used : File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 9 with Test

use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.

the class SimpleFileWriterTest method testIoException.

/**
 * Verify if an {@link IOException} during the write ripples through
 */
@Test
public void testIoException() throws Exception {
    assertThrows(IOException.class, () -> {
        final File temporaryFile = this.testFolder.newFile();
        new SimpleFileWriter(temporaryFile.getPath(), writer -> {
            throw new IOException("");
        });
    });
}
Also used : IOException(java.io.IOException) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 10 with Test

use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.

the class SimpleFileWriterTest method testWriterNotNull.

/**
 * Verify if the given writer is not 'null'
 */
@Test
public void testWriterNotNull() throws Exception {
    final File temporaryFile = this.testFolder.newFile();
    new SimpleFileWriter(temporaryFile.getPath(), Assertions::assertNotNull);
}
Also used : File(java.io.File) Assertions(org.junit.jupiter.api.Assertions) 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