From: David ‘Bombe’ Roden Date: Sat, 4 Jan 2020 15:30:29 +0000 (+0100) Subject: 🎨 Add helper for simulating first start X-Git-Tag: v81^2~5^2~20 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c0adc24e57980b042f8232a01ad3bed40b4b0942;p=Sone.git 🎨 Add helper for simulating first start --- 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 + }) +}