From c0adc24e57980b042f8232a01ad3bed40b4b0942 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 4 Jan 2020 16:30:29 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=8E=A8=20Add=20helper=20for=20simulating?= =?utf8?q?=20first=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/sone/web/notification/LocalPostHandlerTest.kt | 5 +---- .../web/notification/MarkPostKnownDuringFirstStartHandlerTest.kt | 5 +---- .../sone/web/notification/NewRemotePostHandlerTest.kt | 5 +---- .../net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt | 5 +---- .../sone/web/notification/NotificationHandlerModuleTest.kt | 5 +---- .../kotlin/net/pterodactylus/sone/web/notification/Testing.kt | 8 ++++++++ 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandlerTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandlerTest.kt index d435101..45be33b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandlerTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandlerTest.kt @@ -26,7 +26,6 @@ import net.pterodactylus.util.notify.* import net.pterodactylus.util.template.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* -import java.io.* import kotlin.test.* /** @@ -62,9 +61,7 @@ class LocalPostHandlerTest { @Test fun `handler does not add notification during first start`() { - notificationManager.addNotification(object : AbstractNotification("first-start-notification") { - override fun render(writer: Writer?) = Unit - }) + notificationManager.firstStart() eventBus.post(NewPostFoundEvent(remotePost)) assertThat(notificationManager.notifications, not(hasItem(notification))) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/MarkPostKnownDuringFirstStartHandlerTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/MarkPostKnownDuringFirstStartHandlerTest.kt index 28a1719..6efb472 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/MarkPostKnownDuringFirstStartHandlerTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/MarkPostKnownDuringFirstStartHandlerTest.kt @@ -23,7 +23,6 @@ import net.pterodactylus.sone.data.* import net.pterodactylus.util.notify.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* -import java.io.* import java.util.function.Consumer import kotlin.test.* @@ -50,9 +49,7 @@ class MarkPostKnownDuringFirstStartHandlerTest { @Test fun `new post is marked as known during first start`() { - notificationManager.addNotification(object : AbstractNotification("first-start-notification") { - override fun render(writer: Writer?) = Unit - }) + notificationManager.firstStart() eventBus.post(NewPostFoundEvent(post)) assertThat(markedPosts, contains(post)) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt index 5e4e5fc..a0d7bc6 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt @@ -27,7 +27,6 @@ import net.pterodactylus.util.notify.* import net.pterodactylus.util.template.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* -import java.io.* import kotlin.test.* /** @@ -71,9 +70,7 @@ class NewRemotePostHandlerTest { @Test fun `handler does not add notification to notification manager during first start`() { - notificationManager.addNotification(object : AbstractNotification("first-start-notification") { - override fun render(writer: Writer?) = Unit - }) + notificationManager.firstStart() eventBus.post(NewPostFoundEvent(remotePost)) assertThat(notificationManager.notifications, not(hasItem(notification))) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt index ff0947d..0774992 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt @@ -26,7 +26,6 @@ import net.pterodactylus.util.notify.* import net.pterodactylus.util.template.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* -import java.io.* import kotlin.test.* class NewSoneHandlerTest { @@ -55,9 +54,7 @@ class NewSoneHandlerTest { @Test fun `handler does not add notification on new sone event if first-start notification is present`() { - notificationManager.addNotification(object : AbstractNotification("first-start-notification") { - override fun render(writer: Writer) = Unit - }) + notificationManager.firstStart() eventBus.post(NewSoneFoundEvent(sone)) assertThat(notificationManager.notifications.single().id, equalTo("first-start-notification")) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt index ea5db56..7d96208 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt @@ -37,7 +37,6 @@ import org.hamcrest.Matchers import org.hamcrest.Matchers.* import org.mockito.* import org.mockito.Mockito.* -import java.io.* import java.util.concurrent.* import java.util.concurrent.TimeUnit.* import java.util.function.* @@ -75,9 +74,7 @@ class NotificationHandlerModuleTest { @Test fun `mark-post-known-during-first-start handler is created with correct action`() { - notificationManager.addNotification(object : AbstractNotification("first-start-notification") { - override fun render(writer: Writer?) = Unit - }) + notificationManager.firstStart() val handler = injector.getInstance() val post = mock() handler.newPostFound(NewPostFoundEvent(post)) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/Testing.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/Testing.kt index 12088d0..4009ea0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/Testing.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/Testing.kt @@ -17,6 +17,8 @@ package net.pterodactylus.sone.web.notification +import net.pterodactylus.util.notify.* +import java.io.* import java.util.concurrent.* /** Information about a scheduled runnable. */ @@ -35,3 +37,9 @@ class TestScheduledThreadPoolExecutor : ScheduledThreadPoolExecutor(1) { .also { scheduleds += Scheduled(command, delay, unit, it) } } + +fun NotificationManager.firstStart() { + addNotification(object : AbstractNotification("first-start-notification") { + override fun render(writer: Writer?) = Unit + }) +} -- 2.7.4