X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fmain%2FSonePluginTest.kt;h=5795285cd959852c3060fec6c3b5cab57a32596a;hb=d33e7e73ccdc7a1ed8b32b13bbe12f84aa076e6b;hp=677823c6e26352f5077350f9a13f4402392d7b7f;hpb=8281d81a4412af542753a4fc56b2c1a8c52000d4;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt index 677823c..5795285 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,18 +126,60 @@ 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)) } } + private class ConfigNotReadListener(private val configNotReadReceiver: AtomicBoolean) { + @Subscribe + fun configNotRead(configNotRead: ConfigNotRead) { + configNotReadReceiver.set(true) + } + } + + @Test + fun `config-not-read event is sent to event bus when new config is true`() { + File("sone.properties").deleteAfter { + writeText("Invalid") + val configNotReadReceived = AtomicBoolean() + runSonePluginWithRealInjector { + val eventBus = it.getInstance(EventBus::class.java) + eventBus.register(ConfigNotReadListener(configNotReadReceived)) + } + sonePlugin.runPlugin(pluginRespirator) + assertThat(configNotReadReceived.get(), equalTo(true)) + } + } + + @Test + fun `config-not-read event is not sent to event bus when first start is true`() { + File("sone.properties").delete() + val configNotReadReceived = AtomicBoolean() + runSonePluginWithRealInjector { + val eventBus = it.getInstance(EventBus::class.java) + eventBus.register(ConfigNotReadListener(configNotReadReceived)) + } + sonePlugin.runPlugin(pluginRespirator) + assertThat(configNotReadReceived.get(), equalTo(false)) + } + + @Test + fun `config-not-read event is not sent to event bus when new config is false`() { + File("sone.properties").deleteAfter { + writeText("# comment") + val configNotReadReceived = AtomicBoolean() + runSonePluginWithRealInjector { + val eventBus = it.getInstance(EventBus::class.java) + eventBus.register(ConfigNotReadListener(configNotReadReceived)) + } + sonePlugin.runPlugin(pluginRespirator) + assertThat(configNotReadReceived.get(), equalTo(false)) + } + } + private fun getInjected(clazz: Class, annotation: Annotation? = null): T? = injected[TypeLiteral.get(clazz) to annotation] as? T