#113 Event Driven Architecture

Adds unit test to assert and verify pattern event get type behaviour.
Also added unit test comments.
This commit is contained in:
cfarrugia 2015-11-28 17:58:32 +01:00
parent 3ad36020aa
commit d9a1d1cef9

View File

@ -1,4 +1,5 @@
import com.iluwatar.eda.EventDispatcher; import com.iluwatar.eda.EventDispatcher;
import com.iluwatar.eda.event.Event;
import com.iluwatar.eda.event.UserCreatedEvent; import com.iluwatar.eda.event.UserCreatedEvent;
import com.iluwatar.eda.event.UserUpdatedEvent; import com.iluwatar.eda.event.UserUpdatedEvent;
import com.iluwatar.eda.handler.UserCreatedEventHandler; import com.iluwatar.eda.handler.UserCreatedEventHandler;
@ -6,15 +7,20 @@ import com.iluwatar.eda.handler.UserUpdatedEventHandler;
import com.iluwatar.eda.model.User; import com.iluwatar.eda.model.User;
import org.junit.Test; import org.junit.Test;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/**
* Event Driven Pattern unit tests to assert and verify correct pattern behaviour
*/
public class EventDrivenTest { public class EventDrivenTest {
/**
* This unit test should register events and event handlers correctly with the event dispatcher
* and events should be dispatched accordingly.
*/
@Test @Test
public void testEventDriverPattern() { public void testEventDriverPattern() {
@ -42,6 +48,16 @@ public class EventDrivenTest {
//verify that the events have been dispatched //verify that the events have been dispatched
verify(dispatcher).dispatch(userCreatedEvent); verify(dispatcher).dispatch(userCreatedEvent);
verify(dispatcher).dispatch(userUpdatedEvent); verify(dispatcher).dispatch(userUpdatedEvent);
}
/**
* This unit test should correctly return the {@link Event} class type when calling the
* {@link Event#getType() getType} method.
*/
@Test
public void testGetEventType() {
User user = new User("iluwatar");
UserCreatedEvent userCreatedEvent = new UserCreatedEvent(user);
assertEquals(UserCreatedEvent.class, userCreatedEvent.getType());
} }
} }