🎨 Add helper for simulating first start
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 4 Jan 2020 15:30:29 +0000 (16:30 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 4 Jan 2020 15:30:29 +0000 (16:30 +0100)
src/test/kotlin/net/pterodactylus/sone/web/notification/LocalPostHandlerTest.kt
src/test/kotlin/net/pterodactylus/sone/web/notification/MarkPostKnownDuringFirstStartHandlerTest.kt
src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt
src/test/kotlin/net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt
src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt
src/test/kotlin/net/pterodactylus/sone/web/notification/Testing.kt

index d435101..45be33b 100644 (file)
@@ -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>(notification)))
        }
index 28a1719..6efb472 100644 (file)
@@ -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))
        }
index 5e4e5fc..a0d7bc6 100644 (file)
@@ -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)))
        }
index ff0947d..0774992 100644 (file)
@@ -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"))
        }
index ea5db56..7d96208 100644 (file)
@@ -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<MarkPostKnownDuringFirstStartHandler>()
                val post = mock<Post>()
                handler.newPostFound(NewPostFoundEvent(post))
index 12088d0..4009ea0 100644 (file)
@@ -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
+       })
+}