Skip to content

Commit

Permalink
chore: formatting, remove unused buildSrc (#196)
Browse files Browse the repository at this point in the history
* chore: formatting, remove unused buildSrc
* chore: use string notation for all dependencies
  • Loading branch information
PhilippHeuer authored Feb 11, 2024
1 parent bf7c25c commit 5f86617
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 230 deletions.
7 changes: 0 additions & 7 deletions buildSrc/build.gradle.kts

This file was deleted.

18 changes: 0 additions & 18 deletions buildSrc/src/main/kotlin/globals.kt

This file was deleted.

38 changes: 0 additions & 38 deletions buildSrc/src/main/kotlin/project.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class EventManager implements IEventManager {
/**
* is Stopped?
*/
private volatile boolean isStopped = false;
private volatile boolean isStopped;

/**
* Default EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
package com.github.philippheuer.events4j.core;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.github.philippheuer.events4j.api.domain.IDisposable;
import com.github.philippheuer.events4j.core.domain.TestEventObject;
import com.github.philippheuer.events4j.simple.SimpleEventHandler;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

@Slf4j
public class EventManagerTest {
class EventManagerTest {

private static EventManager eventManager;

@BeforeAll
public static void initializeEventManager() {
static void initializeEventManager() {
eventManager = new EventManager();
eventManager.autoDiscovery();
eventManager.setDefaultEventHandler(SimpleEventHandler.class);
}

@Test
public void testAutoDiscovery() {
Assertions.assertEquals(2, eventManager.getEventHandlers().size(), "should have discovered 2 handlers");
void autoDiscovery() {
assertEquals(2, eventManager.getEventHandlers().size(), "should have discovered 2 handlers");
}

@Test
public void testGetEventHandlerByClass() {
void getEventHandlerByClass() {
SimpleEventHandler eventHandler = eventManager.getEventHandler(SimpleEventHandler.class);
Assertions.assertNotNull(eventHandler, "should fine a eventHandler for class SimpleEventHandler");
assertNotNull(eventHandler, "should fine a eventHandler for class SimpleEventHandler");
}

@Test
public void testHasEventHandlerByClass() {
Assertions.assertTrue(eventManager.hasEventHandler(SimpleEventHandler.class), "should fine a eventHandler for class SimpleEventHandler");
void hasEventHandlerByClass() {
assertTrue(eventManager.hasEventHandler(SimpleEventHandler.class), "should fine a eventHandler for class SimpleEventHandler");
}

@Test
public void testUniqueOnEvent() {
void uniqueOnEvent() {
// Register Listener
IDisposable disposableA = eventManager.onEvent("test", TestEventObject.class, System.out::println);
IDisposable disposableB = eventManager.onEvent("test", TestEventObject.class, System.out::println);

// Verify
Assertions.assertEquals(1, eventManager.getActiveSubscriptions().size());
Assertions.assertNotNull(disposableA);
Assertions.assertNull(disposableB);
assertEquals(1, eventManager.getActiveSubscriptions().size());
assertNotNull(disposableA);
assertNull(disposableB);
}

@AfterAll
public static void shutdownEventManager() {
static void shutdownEventManager() {
eventManager.close();
}

Expand Down
6 changes: 3 additions & 3 deletions handler-reactor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
testImplementation(project(":core"))

// Reactor - see https://repo1.maven.org/maven2/io/projectreactor/reactor-bom/Dysprosium-SR12/reactor-bom-Dysprosium-SR12.pom
api(group = "io.projectreactor", name = "reactor-core", version = "3.6.2")
api(group = "io.projectreactor.addons", name = "reactor-extra", version = "3.5.1")
testImplementation(group = "io.projectreactor", name = "reactor-test", version = "3.6.2")
api("io.projectreactor:reactor-core:3.6.2")
api("io.projectreactor.addons:reactor-extra:3.5.1")
testImplementation("io.projectreactor:reactor-test:3.6.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class Events4JSubscriber<E> implements Subscriber<E>, Disposable, IDispos

private Subscription subscription;

private Consumer<E> consumer;
private final Consumer<E> consumer;

private boolean isDisposed = false;
private boolean isDisposed;

public Events4JSubscriber(Consumer<E> consumer) {
this.consumer = consumer;
Expand Down Expand Up @@ -43,7 +43,7 @@ public void onComplete() {

@Override
public void dispose() {
if (isDisposed == false) {
if (!isDisposed) {
subscription.cancel();
isDisposed = true;
subscription = null;
Expand All @@ -54,4 +54,4 @@ public void dispose() {
public boolean isDisposed() {
return isDisposed;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.github.philippheuer.events4j.reactor;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.github.philippheuer.events4j.api.domain.IDisposable;
import com.github.philippheuer.events4j.api.service.IEventHandler;
import com.github.philippheuer.events4j.core.EventManager;
import com.github.philippheuer.events4j.core.domain.Event;
import com.github.philippheuer.events4j.reactor.domain.TestEvent;
import com.github.philippheuer.events4j.reactor.domain.TestEventObject;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import reactor.core.Disposable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Reactor EventHandler Test
Expand All @@ -19,18 +21,18 @@
* @version %I%, %G%
* @since 1.0
*/
public class ReactorEventHandlerTest {
class ReactorEventHandlerTest {

private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ReactorEventHandlerTest.class);
private static final Logger log = LoggerFactory.getLogger(ReactorEventHandlerTest.class);

private static EventManager eventManager;

private static int eventsProcessed = 0;
private static int eventsProcessed;

private static final Class<? extends IEventHandler> REACTOR_EVENTHANDLER = ReactorEventHandler.class;

@BeforeAll
public static void beforeAll() {
static void beforeAll() {
eventManager = new EventManager();
ReactorEventHandler reactorEventHandler = new ReactorEventHandler();
eventManager.registerEventHandler(reactorEventHandler);
Expand All @@ -41,13 +43,13 @@ public static void beforeAll() {
* Tests if events can be dispatched
*/
@Test
public void testReactorEventHandlerWithTestEventObject() throws Exception {
void reactorEventHandlerWithTestEventObject() throws Exception {
// Register Listener
IDisposable disposable = eventManager.onEvent(TestEventObject.class, event -> {
log.info("Received a event.");
eventsProcessed = eventsProcessed + 1;
});
Assertions.assertEquals(1, eventManager.getActiveSubscriptions().size());
assertEquals(1, eventManager.getActiveSubscriptions().size());

// dispatch
eventManager.publish(new TestEventObject());
Expand All @@ -57,15 +59,15 @@ public void testReactorEventHandlerWithTestEventObject() throws Exception {
disposable.dispose();

// Verify
Assertions.assertEquals(0, eventManager.getActiveSubscriptions().size());
Assertions.assertEquals(1, eventsProcessed, "one event should have been handled");
assertEquals(0, eventManager.getActiveSubscriptions().size());
assertEquals(1, eventsProcessed, "one event should have been handled");
}

/**
* Tests if events can be dispatched
*/
@Test
public void testReactorEventHandlerWithTestEvent() throws Exception {
void reactorEventHandlerWithTestEvent() throws Exception {
// Register Listener
IDisposable disposable = eventManager.getEventHandler(REACTOR_EVENTHANDLER).onEvent(Event.class, event -> {
log.info("Received event [{}] that was fired at {}.", event.getEventId(), event.getFiredAtInstant().toString());
Expand All @@ -82,11 +84,11 @@ public void testReactorEventHandlerWithTestEvent() throws Exception {
Thread.sleep(1000);

// Verify
Assertions.assertEquals(1, eventsProcessed, "only one event should have been handled, since we disposed the handler after the first publish call");
assertEquals(1, eventsProcessed, "only one event should have been handled, since we disposed the handler after the first publish call");
}

@AfterAll
public static void afterAll() throws Exception {
static void afterAll() throws Exception {
// shutdown
eventManager.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void handleAnnotationHandlers(Object event) {
for (Map.Entry<Class<?>, ConcurrentMap<Method, List<Object>>> e : methodListeners.entrySet()) {
if (e.getKey().isAssignableFrom(event.getClass())) {
ConcurrentMap<Method, List<Object>> eventClass = e.getValue();
eventClass.forEach((k, v) -> {
eventClass.forEach((k, v) ->
v.forEach(object -> {
try {
// Invoke Event
Expand All @@ -134,8 +134,7 @@ private void handleAnnotationHandlers(Object event) {
} catch (Exception ex) {
log.error("Unhandled exception caught dispatching event " + event.getClass().getSimpleName(), ex);
}
});
});
}));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class SimpleEventHandlerSubscription implements IDisposable {

@Getter
private boolean isDisposed = false;
private boolean isDisposed;

@Getter(AccessLevel.NONE)
private final SimpleEventHandler simpleEventHandler;
Expand Down
Loading

0 comments on commit 5f86617

Please sign in to comment.