From f91739108759aea33b0442933ae064c783a1f89d Mon Sep 17 00:00:00 2001 From: therealbush Date: Fri, 1 Apr 2022 19:26:05 -1000 Subject: almost done, just need to make thread safe, test, and document --- src/test/kotlin/Test.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/test/kotlin') diff --git a/src/test/kotlin/Test.kt b/src/test/kotlin/Test.kt index c166cb2..2bdb445 100644 --- a/src/test/kotlin/Test.kt +++ b/src/test/kotlin/Test.kt @@ -19,7 +19,7 @@ import kotlin.random.Random */ @TestInstance(Lifecycle.PER_CLASS) class Test { - lateinit var eventBus: EventBus + private lateinit var eventBus: EventBus private val logger = LogManager.getLogger() //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -64,7 +64,7 @@ class Test { Assertions.assertEquals(random, primitiveTestValue) } - var primitiveTestValue = 0 + private var primitiveTestValue = 0 val primitiveListener = listener { primitiveTestValue = it @@ -73,11 +73,11 @@ class Test { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Tests unsubscribing of "free" listeners which don't belong to a subscriber. todo allow keys to be resubscribed and test top level listeners + // Tests unsubscribing of listeners which don't belong to a subscriber. @Test fun freeListenerTest() { - // Register "free" listener, and keep the returned key - val key = eventBus.register(listener { + // Register listener and keep the value + val listener = eventBus.register(listener { freeListenerTestValue = it }) val valueOne = "i love bush's eventbus <3" @@ -86,14 +86,14 @@ class Test { eventBus.post(valueOne) Assertions.assertEquals(valueOne, freeListenerTestValue) // Remove the listener - eventBus.unsubscribe(key) + eventBus.unregister(listener) // No effect eventBus.post(valueTwo) // Value will not change Assertions.assertEquals(valueOne, freeListenerTestValue) } - var freeListenerTestValue: String? = null + private var freeListenerTestValue: String? = null //////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit