🎨 Move new-sone template creation into module
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / notification / NewSoneHandlerTest.kt
index 0f7b182..ff0947d 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.notification
 
 import com.google.common.eventbus.*
 import net.pterodactylus.sone.core.event.*
+import net.pterodactylus.sone.data.*
 import net.pterodactylus.sone.data.impl.*
 import net.pterodactylus.sone.notify.*
 import net.pterodactylus.util.notify.*
@@ -33,7 +34,8 @@ class NewSoneHandlerTest {
        @Suppress("UnstableApiUsage")
        private val eventBus = EventBus()
        private val notificationManager = NotificationManager()
-       private val handler = NewSoneHandler(notificationManager, Template())
+       private val notification = ListNotification<Sone>("", "", Template())
+       private val handler = NewSoneHandler(notificationManager, notification)
 
        init {
                eventBus.register(handler)
@@ -42,15 +44,13 @@ class NewSoneHandlerTest {
        @Test
        fun `handler adds notification if new sone event is fired`() {
                eventBus.post(NewSoneFoundEvent(sone))
-               val notification = notificationManager.notifications.single() as ListNotification<*>
-               assertThat(notification.id, equalTo("new-sone-notification"))
+               assertThat(notificationManager.notifications, contains<Notification>(notification))
        }
 
        @Test
        fun `handler adds sone to notification`() {
                eventBus.post(NewSoneFoundEvent(sone))
-               val notification = notificationManager.notifications.single() as ListNotification<*>
-               assertThat(notification.elements, contains<Any>(sone))
+               assertThat(notification.elements, contains(sone))
        }
 
        @Test
@@ -59,10 +59,23 @@ class NewSoneHandlerTest {
                        override fun render(writer: Writer) = Unit
                })
                eventBus.post(NewSoneFoundEvent(sone))
-               val notification = notificationManager.notifications.single()
-               assertThat(notification.id, equalTo("first-start-notification"))
+               assertThat(notificationManager.notifications.single().id, equalTo("first-start-notification"))
+       }
+
+       @Test
+       fun `handler removes sone from notification if sone is marked as known`() {
+               notification.add(sone)
+               eventBus.post(MarkSoneKnownEvent(sone))
+               assertThat(notification.elements, emptyIterable())
+       }
+
+       @Test
+       fun `handler removes sone from notification if sone is removed`() {
+               notification.add(sone)
+               eventBus.post(SoneRemovedEvent(sone))
+               assertThat(notification.elements, emptyIterable())
        }
 
 }
 
-private val sone = IdOnlySone("sone-id")
+private val sone: Sone = IdOnlySone("sone-id")