From 4e4f20c6e94411757bef48141ea08d0132cb0e09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 11 Dec 2019 17:29:06 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Simplify=20event=20bus=20in?= =?utf8?q?teraction?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/main/SonePluginTest.kt | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) 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)) -- 2.7.4