✨ Post event when debug activated
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 28 Jul 2019 14:18:17 +0000 (16:18 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 28 Jul 2019 19:03:47 +0000 (21:03 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/kotlin/net/pterodactylus/sone/core/event/DebugActivatedEvent.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt

index 99527bc..71df45b 100644 (file)
@@ -49,19 +49,7 @@ import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidImageFound;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidParentAlbumFound;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostFound;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostReplyFound;
-import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
-import net.pterodactylus.sone.core.event.InsertionDelayChangedEvent;
-import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
-import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
-import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
-import net.pterodactylus.sone.core.event.NewPostFoundEvent;
-import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
-import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
-import net.pterodactylus.sone.core.event.PostRemovedEvent;
-import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
-import net.pterodactylus.sone.core.event.SoneLockedEvent;
-import net.pterodactylus.sone.core.event.SoneRemovedEvent;
-import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
+import net.pterodactylus.sone.core.event.*;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
@@ -237,6 +225,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
 
        public void setDebug() {
                debug.set(true);
+               eventBus.post(new DebugActivatedEvent());
        }
 
        /**
diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/DebugActivatedEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/DebugActivatedEvent.kt
new file mode 100644 (file)
index 0000000..c73ebe1
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * Sone - DebugActivatedEvent.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
+
+class DebugActivatedEvent
index 1b2b363..f7ac026 100644 (file)
@@ -12,8 +12,8 @@ import net.pterodactylus.util.config.*
 import org.hamcrest.*
 import org.hamcrest.MatcherAssert.*
 import org.hamcrest.Matchers.*
-import org.mockito.ArgumentMatchers.eq
-import org.mockito.Mockito.*
+import org.mockito.Mockito.inOrder
+import org.mockito.Mockito.verify
 import org.mockito.hamcrest.MockitoHamcrest.*
 import kotlin.test.*
 
@@ -149,7 +149,15 @@ class CoreTest {
                assertThat(core.debug, equalTo(true))
        }
 
-       private fun createCore(): Core {
+       @Test
+       fun `setting debug flag posts event to event bus`() {
+               val eventBus = mock<EventBus>()
+               val core = createCore(eventBus)
+               core.setDebug()
+               verify(eventBus).post(argThat(instanceOf(DebugActivatedEvent::class.java)))
+       }
+
+       private fun createCore(eventBus: EventBus = mock()): Core {
                val configuration = mock<Configuration>()
                val freenetInterface = mock<FreenetInterface>()
                val identityManager = mock<IdentityManager>()
@@ -157,7 +165,6 @@ class CoreTest {
                val imageInserter = mock<ImageInserter>()
                val updateChecker = mock<UpdateChecker>()
                val webOfTrustUpdater = mock<WebOfTrustUpdater>()
-               val eventBus = mock<EventBus>()
                val database = mock<Database>()
                return Core(configuration, freenetInterface, identityManager, soneDownloader, imageInserter, updateChecker, webOfTrustUpdater, eventBus, database)
        }