X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FNewSoneHandlerTest.kt;h=07749928b57db38d93eba08315157fc69e52dfe0;hb=c0adc24e57980b042f8232a01ad3bed40b4b0942;hp=0f7b182c09606f40814459154ddb35dcb16d458b;hpb=188857148a7b035bfc6033b1fd40d774bd1fac65;p=Sone.git 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 0f7b182..0774992 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NewSoneHandlerTest.kt @@ -19,13 +19,13 @@ 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.* import net.pterodactylus.util.template.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* -import java.io.* import kotlin.test.* class NewSoneHandlerTest { @@ -33,7 +33,8 @@ class NewSoneHandlerTest { @Suppress("UnstableApiUsage") private val eventBus = EventBus() private val notificationManager = NotificationManager() - private val handler = NewSoneHandler(notificationManager, Template()) + private val notification = ListNotification("", "", Template()) + private val handler = NewSoneHandler(notificationManager, notification) init { eventBus.register(handler) @@ -42,27 +43,36 @@ 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)) } @Test fun `handler adds sone to notification`() { eventBus.post(NewSoneFoundEvent(sone)) - val notification = notificationManager.notifications.single() as ListNotification<*> - assertThat(notification.elements, contains(sone)) + assertThat(notification.elements, contains(sone)) } @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)) - 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")