aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authortherealbush <therealbush@users.noreply.github.com>2022-04-14 00:31:16 -0700
committertherealbush <therealbush@users.noreply.github.com>2022-04-14 00:31:16 -0700
commitb49065b50edd48d0f335e17bcf6868dc2f916ad5 (patch)
treea9ad233135919970f3a6f36a1369ef701a9ff677 /src/test/java
parentb196c7c2fe06d84e862648a8bf25058f72c6c0b1 (diff)
downloadeventbus-kotlin-b49065b50edd48d0f335e17bcf6868dc2f916ad5.tar.gz
eventbus-kotlin-b49065b50edd48d0f335e17bcf6868dc2f916ad5.tar.bz2
eventbus-kotlin-b49065b50edd48d0f335e17bcf6868dc2f916ad5.zip
soon (lol)
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/JavaTest.java62
-rw-r--r--src/test/java/TestJava.java80
2 files changed, 62 insertions, 80 deletions
diff --git a/src/test/java/JavaTest.java b/src/test/java/JavaTest.java
new file mode 100644
index 0000000..0b942b6
--- /dev/null
+++ b/src/test/java/JavaTest.java
@@ -0,0 +1,62 @@
+import me.bush.illnamethislater.Listener;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestInstance.Lifecycle;
+import me.bush.illnamethislater.EventBus;
+import org.apache.logging.log4j.LogManager;
+import org.junit.jupiter.api.Test;
+
+import static me.bush.illnamethislater.ListenerKt.listener;
+
+/**
+ * I was getting NCDFE when trying to load this class
+ * from the other test and I don't care enough to fix it.
+ *
+ * @author bush
+ * @since 1.0.0
+ */
+@TestInstance(Lifecycle.PER_CLASS)
+public class JavaTest {
+ private EventBus eventBus;
+ private final Logger logger = LogManager.getLogger();
+
+ @BeforeAll
+ public void setup() {
+ Configurator.setRootLevel(Level.ALL);
+ logger.info("Running Java tests");
+ eventBus = new EventBus();
+ eventBus.subscribe(this);
+ }
+
+ @Test
+ public void javaSubscriberTest() {
+ eventBus.subscribe(this);
+ SimpleEvent event = new SimpleEvent();
+ eventBus.post(event);
+ Assertions.assertEquals(event.getCount(), 4);
+ }
+
+ public Listener someInstanceListenerField = listener(SimpleEvent.class, event -> {
+ event.setCount(event.getCount() + 1);
+ });
+
+ public Listener someInstanceListenerMethod() {
+ return listener(SimpleEvent.class, event -> {
+ event.setCount(event.getCount() + 1);
+ });
+ }
+
+ public static Listener someStaticListenerMethod() {
+ return listener(SimpleEvent.class, event -> {
+ event.setCount(event.getCount() + 1);
+ });
+ }
+
+ public static Listener someStaticListenerField = listener(SimpleEvent.class, event -> {
+ event.setCount(event.getCount() + 1);
+ });
+}
diff --git a/src/test/java/TestJava.java b/src/test/java/TestJava.java
deleted file mode 100644
index c6c77a8..0000000
--- a/src/test/java/TestJava.java
+++ /dev/null
@@ -1,80 +0,0 @@
-import me.bush.illnamethislater.Listener;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.config.Configurator;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.TestInstance;
-import org.junit.jupiter.api.TestInstance.Lifecycle;
-import me.bush.illnamethislater.EventBus;
-import org.apache.logging.log4j.LogManager;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Test;
-
-import static me.bush.illnamethislater.ListenerKt.listener;
-
-/**
- * I was getting noclassdeffound when trying to load this Java
- * class in the other test and I don't care enough to fix it.
- *
- * @author bush
- * @since 1.0.0
- */
-@TestInstance(Lifecycle.PER_CLASS)
-public class TestJava {
- private static boolean thisShouldChange;
- private boolean thisShouldChangeToo;
- private EventBus eventBus;
- private final Logger logger = LogManager.getLogger();
-
- @BeforeAll
- public void setup() {
- Configurator.setRootLevel(Level.ALL);
-
- // Test that init works
- logger.info("Initializing");
- eventBus = new EventBus();
-
- // Ensure no npe
- logger.info("Logging empty debug info");
- eventBus.debugInfo();
-
- // Test that basic subscribing reflection works
- logger.info("Subscribing");
- eventBus.subscribe(this);
-
- logger.info("Testing Events");
- }
-
- @AfterAll
- public void unsubscribe() {
- logger.info("Unsubscribing");
- eventBus.unsubscribe(this);
- eventBus.debugInfo();
- }
-
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- @Test
- public void javaSubscriberTest() {
- eventBus.subscribe(this);
- eventBus.post(new MyEvent());
- Assertions.assertTrue(TestJava.thisShouldChange);
- Assertions.assertTrue(this.thisShouldChangeToo);
- // TODO: 4/2/2022 fix calling from java
- }
-
- public Listener listener = listener(MyEvent.class, 200, event -> {
- Assertions.assertEquals(event.getSomeString(), "donda");
- event.setSomeString("donda 2");
- this.thisShouldChangeToo = true;
- });
-
- public static Listener someStaticListener() {
- return listener(MyEvent.class, 100, event -> {
- Assertions.assertEquals(event.getSomeString(), "donda 2");
- thisShouldChange = true;
- });
- }
-}