♻️ Simplify event bus interaction
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 11 Dec 2019 16:29:06 +0000 (17:29 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 11 Dec 2019 18:47:24 +0000 (19:47 +0100)
src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt

index 677823c..9e5158b 100644 (file)
@@ -100,18 +100,20 @@ class SonePluginTest {
                assertThat(getInjected(NotificationHandler::class.java), notNullValue())
        }
 
+       private class FirstStartListener(private val firstStartReceived: AtomicBoolean) {
+               @Subscribe
+               fun firstStart(firstStart: FirstStart) {
+                       firstStartReceived.set(true)
+               }
+       }
+
        @Test
        fun `first-start event is sent to event bus when first start is true`() {
                File("sone.properties").delete()
                val firstStartReceived = AtomicBoolean()
                runSonePluginWithRealInjector {
                        val eventBus = it.getInstance(EventBus::class.java)
-                       eventBus.register(object : Any() {
-                               @Subscribe
-                               fun firstStart(firstStart: FirstStart) {
-                                       firstStartReceived.set(true)
-                               }
-                       })
+                       eventBus.register(FirstStartListener(firstStartReceived))
                }
                sonePlugin.runPlugin(pluginRespirator)
                assertThat(firstStartReceived.get(), equalTo(true))
@@ -124,12 +126,7 @@ class SonePluginTest {
                        val firstStartReceived = AtomicBoolean()
                        runSonePluginWithRealInjector {
                                val eventBus = it.getInstance(EventBus::class.java)
-                               eventBus.register(object : Any() {
-                                       @Subscribe
-                                       fun firstStart(firstStart: FirstStart) {
-                                               firstStartReceived.set(true)
-                                       }
-                               })
+                               eventBus.register(FirstStartListener(firstStartReceived))
                        }
                        sonePlugin.runPlugin(pluginRespirator)
                        assertThat(firstStartReceived.get(), equalTo(false))