Java 11 migrate remaining e (#1112)
* Moves eip-aggregator to Java 11 * Moves eip-message-channel to Java 11 * Moves eip-publish-subscribe to Java 11 * Moves eip-splitter to Java 11 * Moves eip-wire-tap to Java 11 * Moves event-aggregator to Java 11 * Moves event-asynchronous to Java 11 * Moves event-driven-architecture to Java 11 * Moves event-queue to Java 11 * Moves event-sourcing to Java 11 * Moves execute-around to Java 11 * Moves extension-objects to Java 11
This commit is contained in:
committed by
Ilkka Seppälä
parent
b09b100614
commit
fb2c026822
@ -52,11 +52,11 @@ public class App {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
EventDispatcher dispatcher = new EventDispatcher();
|
||||
var dispatcher = new EventDispatcher();
|
||||
dispatcher.registerHandler(UserCreatedEvent.class, new UserCreatedEventHandler());
|
||||
dispatcher.registerHandler(UserUpdatedEvent.class, new UserUpdatedEventHandler());
|
||||
|
||||
User user = new User("iluwatar");
|
||||
var user = new User("iluwatar");
|
||||
dispatcher.dispatch(new UserCreatedEvent(user));
|
||||
dispatcher.dispatch(new UserUpdatedEvent(user));
|
||||
}
|
||||
|
@ -44,8 +44,10 @@ public class EventDispatcher {
|
||||
* @param eventType The {@link Event} to be registered
|
||||
* @param handler The {@link Handler} that will be handling the {@link Event}
|
||||
*/
|
||||
public <E extends Event> void registerHandler(Class<E> eventType,
|
||||
Handler<E> handler) {
|
||||
public <E extends Event> void registerHandler(
|
||||
Class<E> eventType,
|
||||
Handler<E> handler
|
||||
) {
|
||||
handlers.put(eventType, handler);
|
||||
}
|
||||
|
||||
@ -56,7 +58,7 @@ public class EventDispatcher {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends Event> void dispatch(E event) {
|
||||
Handler<E> handler = (Handler<E>) handlers.get(event.getClass());
|
||||
var handler = (Handler<E>) handlers.get(event.getClass());
|
||||
if (handler != null) {
|
||||
handler.onEvent(event);
|
||||
}
|
||||
|
@ -25,15 +25,12 @@ package com.iluwatar.eda;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Tests that Event Driven Architecture example runs without errors.
|
||||
*/
|
||||
public class AppTest {
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
public void test() {
|
||||
App.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,11 @@
|
||||
|
||||
package com.iluwatar.eda.event;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.iluwatar.eda.model.User;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link UserCreatedEventTest} tests and verifies {@link AbstractEvent} behaviour.
|
||||
*/
|
||||
@ -39,8 +39,8 @@ public class UserCreatedEventTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetEventType() {
|
||||
User user = new User("iluwatar");
|
||||
UserCreatedEvent userCreatedEvent = new UserCreatedEvent(user);
|
||||
var user = new User("iluwatar");
|
||||
var userCreatedEvent = new UserCreatedEvent(user);
|
||||
assertEquals(UserCreatedEvent.class, userCreatedEvent.getType());
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
package com.iluwatar.eda.framework;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.iluwatar.eda.event.UserCreatedEvent;
|
||||
import com.iluwatar.eda.event.UserUpdatedEvent;
|
||||
import com.iluwatar.eda.handler.UserCreatedEventHandler;
|
||||
@ -30,9 +33,6 @@ import com.iluwatar.eda.handler.UserUpdatedEventHandler;
|
||||
import com.iluwatar.eda.model.User;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Event Dispatcher unit tests to assert and verify correct event dispatcher behaviour
|
||||
*/
|
||||
@ -45,16 +45,16 @@ public class EventDispatcherTest {
|
||||
@Test
|
||||
public void testEventDriverPattern() {
|
||||
|
||||
EventDispatcher dispatcher = spy(new EventDispatcher());
|
||||
UserCreatedEventHandler userCreatedEventHandler = spy(new UserCreatedEventHandler());
|
||||
UserUpdatedEventHandler userUpdatedEventHandler = spy(new UserUpdatedEventHandler());
|
||||
var dispatcher = spy(new EventDispatcher());
|
||||
var userCreatedEventHandler = spy(new UserCreatedEventHandler());
|
||||
var userUpdatedEventHandler = spy(new UserUpdatedEventHandler());
|
||||
dispatcher.registerHandler(UserCreatedEvent.class, userCreatedEventHandler);
|
||||
dispatcher.registerHandler(UserUpdatedEvent.class, userUpdatedEventHandler);
|
||||
|
||||
User user = new User("iluwatar");
|
||||
var user = new User("iluwatar");
|
||||
|
||||
UserCreatedEvent userCreatedEvent = new UserCreatedEvent(user);
|
||||
UserUpdatedEvent userUpdatedEvent = new UserUpdatedEvent(user);
|
||||
var userCreatedEvent = new UserCreatedEvent(user);
|
||||
var userUpdatedEvent = new UserUpdatedEvent(user);
|
||||
|
||||
//fire a userCreatedEvent and verify that userCreatedEventHandler has been invoked.
|
||||
dispatcher.dispatch(userCreatedEvent);
|
||||
|
Reference in New Issue
Block a user