diff options
author | therealbush <therealbush@users.noreply.github.com> | 2022-04-14 00:31:47 -0700 |
---|---|---|
committer | therealbush <therealbush@users.noreply.github.com> | 2022-04-14 00:31:47 -0700 |
commit | 33665d28f5aeb16b40f832b1a2bd4d81656b74fa (patch) | |
tree | 0d6e8302cf5176639b65e2d6d10a94b9d4657aed | |
parent | b49065b50edd48d0f335e17bcf6868dc2f916ad5 (diff) | |
download | eventbus-kotlin-33665d28f5aeb16b40f832b1a2bd4d81656b74fa.tar.gz eventbus-kotlin-33665d28f5aeb16b40f832b1a2bd4d81656b74fa.tar.bz2 eventbus-kotlin-33665d28f5aeb16b40f832b1a2bd4d81656b74fa.zip |
format
-rw-r--r-- | src/main/kotlin/me/bush/illnamethislater/EventBus.kt | 3 | ||||
-rw-r--r-- | src/main/kotlin/me/bush/illnamethislater/ListenerGroup.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/me/bush/illnamethislater/ReflectUtil.kt | 8 | ||||
-rw-r--r-- | src/test/java/JavaTest.java | 34 | ||||
-rw-r--r-- | src/test/kotlin/KotlinTest.kt | 39 |
5 files changed, 35 insertions, 51 deletions
diff --git a/src/main/kotlin/me/bush/illnamethislater/EventBus.kt b/src/main/kotlin/me/bush/illnamethislater/EventBus.kt index 7affa4a..ddc72ef 100644 --- a/src/main/kotlin/me/bush/illnamethislater/EventBus.kt +++ b/src/main/kotlin/me/bush/illnamethislater/EventBus.kt @@ -1,9 +1,6 @@ package me.bush.illnamethislater -import kotlinx.coroutines.delay import kotlin.reflect.KClass -import kotlin.reflect.full.companionObject -import kotlin.reflect.full.companionObjectInstance import kotlin.reflect.full.hasAnnotation /** diff --git a/src/main/kotlin/me/bush/illnamethislater/ListenerGroup.kt b/src/main/kotlin/me/bush/illnamethislater/ListenerGroup.kt index b8116cb..24a1ba3 100644 --- a/src/main/kotlin/me/bush/illnamethislater/ListenerGroup.kt +++ b/src/main/kotlin/me/bush/illnamethislater/ListenerGroup.kt @@ -1,6 +1,6 @@ package me.bush.illnamethislater -import kotlinx.coroutines.* +import kotlinx.coroutines.launch import java.util.concurrent.CopyOnWriteArrayList import kotlin.reflect.KClass diff --git a/src/main/kotlin/me/bush/illnamethislater/ReflectUtil.kt b/src/main/kotlin/me/bush/illnamethislater/ReflectUtil.kt index 2b16379..7f3618c 100644 --- a/src/main/kotlin/me/bush/illnamethislater/ReflectUtil.kt +++ b/src/main/kotlin/me/bush/illnamethislater/ReflectUtil.kt @@ -1,15 +1,13 @@ package me.bush.illnamethislater -import java.lang.reflect.Modifier -import kotlin.reflect.* +import kotlin.reflect.KCallable +import kotlin.reflect.KClass import kotlin.reflect.full.allSuperclasses import kotlin.reflect.full.declaredMembers import kotlin.reflect.full.valueParameters import kotlin.reflect.full.withNullability import kotlin.reflect.jvm.isAccessible -import kotlin.reflect.jvm.javaField -import kotlin.reflect.jvm.javaGetter -import kotlin.reflect.jvm.javaMethod +import kotlin.reflect.typeOf // by bush, unchanged since 1.0.0 diff --git a/src/test/java/JavaTest.java b/src/test/java/JavaTest.java index 0b942b6..8518315 100644 --- a/src/test/java/JavaTest.java +++ b/src/test/java/JavaTest.java @@ -1,14 +1,14 @@ +import me.bush.illnamethislater.EventBus; import me.bush.illnamethislater.Listener; import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; 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.Test; 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; @@ -21,8 +21,20 @@ import static me.bush.illnamethislater.ListenerKt.listener; */ @TestInstance(Lifecycle.PER_CLASS) public class JavaTest { - private EventBus eventBus; + public static Listener someStaticListenerField = listener(SimpleEvent.class, event -> { + event.setCount(event.getCount() + 1); + }); private final Logger logger = LogManager.getLogger(); + public Listener someInstanceListenerField = listener(SimpleEvent.class, event -> { + event.setCount(event.getCount() + 1); + }); + private EventBus eventBus; + + public static Listener someStaticListenerMethod() { + return listener(SimpleEvent.class, event -> { + event.setCount(event.getCount() + 1); + }); + } @BeforeAll public void setup() { @@ -40,23 +52,9 @@ public class JavaTest { 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/kotlin/KotlinTest.kt b/src/test/kotlin/KotlinTest.kt index 6ad3273..3670703 100644 --- a/src/test/kotlin/KotlinTest.kt +++ b/src/test/kotlin/KotlinTest.kt @@ -7,19 +7,9 @@ import org.apache.logging.log4j.LogManager 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.Test -import org.opentest4j.AssertionFailedError -import sun.misc.Unsafe -import kotlin.jvm.internal.PropertyReference0Impl +import org.junit.jupiter.api.TestInstance import kotlin.random.Random -import kotlin.reflect.KCallable -import kotlin.reflect.KProperty -import kotlin.reflect.full.* -import kotlin.reflect.javaType -import kotlin.reflect.jvm.isAccessible -import kotlin.reflect.jvm.javaField -import kotlin.reflect.jvm.javaGetter /** * I don't know how to do these.... @@ -33,7 +23,7 @@ class KotlinTest { private val logger = LogManager.getLogger("Kotlin Test") @BeforeAll - fun `setup logger and initialize eventbus` () { + fun `setup logger and initialize eventbus`() { // Log level defaults to only error Configurator.setRootLevel(Level.ALL) eventBus = EventBus( @@ -51,7 +41,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test listener priority and ability to cancel events or receive cancelled events` () { + fun `test listener priority and ability to cancel events or receive cancelled events`() { eventBus.subscribe(this) val event = SimpleEvent() eventBus.post(event) @@ -90,7 +80,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test subscribing on a kotlin singleton object` () { + fun `test subscribing on a kotlin singleton object`() { eventBus.subscribe(ObjectTest) val event = SimpleEvent() eventBus.post(event) @@ -102,7 +92,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test primitive types and listeners which don't belong to a class` () { + fun `test primitive types and listeners which don't belong to a class`() { val random = Random.nextInt() var changed = 0 val listener = listener<Int> { @@ -118,7 +108,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test that we can detect if an external event is cancelled` () { + fun `test that we can detect if an external event is cancelled`() { eventBus.subscribe(this) val event = ExternalEvent() eventBus.post(event) @@ -139,7 +129,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test parallel event posting` () { + fun `test parallel event posting`() { runBlocking { sus() } @@ -157,7 +147,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `call every method on multiple threads concurrently to ensure no CME is thrown` () { + fun `call every method on multiple threads concurrently to ensure no CME is thrown`() { } @@ -165,7 +155,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test that inheritance doesn't affect events or listeners` () { + fun `test that inheritance doesn't affect events or listeners`() { val superTest = listener<SimpleEvent> { Assertions.fail("This should not be called") } @@ -186,7 +176,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test that require annotation mode works` () { + fun `test that require annotation mode works`() { val eventBus = EventBus(Config(annotationRequired = true)) eventBus.subscribe(this) eventBus.post(Unit) @@ -208,7 +198,7 @@ class KotlinTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Test - fun `test subscribing on a companion object` () { + fun `test subscribing on a companion object`() { eventBus.subscribe(KotlinTest) val string = "i love bush's eventbus <3" eventBus.post(string) @@ -232,9 +222,10 @@ object ObjectTest { } @EventListener - private val listener2 get() = listener<SimpleEvent> { - it.count++ - } + private val listener2 + get() = listener<SimpleEvent> { + it.count++ + } private fun listener3() = listener<SimpleEvent> { it.count++ |