From 7ab07c330617f5396807cee518a119451a694683 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 28 Jul 2019 16:18:17 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=A8=20Post=20event=20when=20debug=20activa?= =?utf8?q?ted?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/Core.java | 15 ++------------- .../sone/core/event/DebugActivatedEvent.kt | 20 ++++++++++++++++++++ .../kotlin/net/pterodactylus/sone/core/CoreTest.kt | 15 +++++++++++---- 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/DebugActivatedEvent.kt diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 99527bc..71df45b 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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 index 0000000..c73ebe1 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/event/DebugActivatedEvent.kt @@ -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 . + */ + +package net.pterodactylus.sone.core.event + +class DebugActivatedEvent diff --git a/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt index 1b2b363..f7ac026 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt @@ -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() + val core = createCore(eventBus) + core.setDebug() + verify(eventBus).post(argThat(instanceOf(DebugActivatedEvent::class.java))) + } + + private fun createCore(eventBus: EventBus = mock()): Core { val configuration = mock() val freenetInterface = mock() val identityManager = mock() @@ -157,7 +165,6 @@ class CoreTest { val imageInserter = mock() val updateChecker = mock() val webOfTrustUpdater = mock() - val eventBus = mock() val database = mock() return Core(configuration, freenetInterface, identityManager, soneDownloader, imageInserter, updateChecker, webOfTrustUpdater, eventBus, database) } -- 2.7.4