From: David ‘Bombe’ Roden Date: Wed, 11 Dec 2019 16:29:06 +0000 (+0100) Subject: ♻️ Simplify event bus interaction X-Git-Tag: v81^2~5^2~51 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=4e4f20c6e94411757bef48141ea08d0132cb0e09 ♻️ Simplify event bus interaction --- diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt index 677823c..9e5158b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt @@ -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))