/* start the web interface! */
webInterface.start();
- webInterface.setNewConfig(injector.getInstance(Key.get(Boolean.class, Names.named("NewConfig"))));
/* first start? */
if (injector.getInstance(Key.get(Boolean.class, Names.named("FirstStart")))) {
injector.getInstance(EventBus.class).post(new FirstStart());
+ } else {
+ /* new config? */
+ if (injector.getInstance(Key.get(Boolean.class, Names.named("NewConfig")))) {
+ injector.getInstance(EventBus.class).post(new ConfigNotRead());
+ }
}
}
--- /dev/null
+/**
+ * Sone - ConfigNotRead.kt - Copyright Ā© 2019 David āBombeā Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+/**
+ * Event that signals that Sone could not read an existing configuration
+ * successfully, and a new configuration was created. This is different from
+ * [FirstStart] in that `FirstStart` signals that there *was* no existing
+ * configuration to be read.
+ */
+class ConfigNotRead
}
}
+ 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 <T> getInjected(clazz: Class<T>, annotation: Annotation? = null): T? =
injected[TypeLiteral.get(clazz) to annotation] as? T