X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FNotificationHandlerModuleTest.kt;h=497ae1db4d82dc48c1d49241ab02a6721eb02d17;hb=8d9f18ad6233388b4b1beb4e457ad211015b90a4;hp=ca52c1fad5573f6d6a1a09444639608440330989;hpb=146335994dc415527bc4c8ec9a0981d739444ea8;p=Sone.git 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 ca52c1f..497ae1d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt @@ -25,10 +25,12 @@ import net.pterodactylus.sone.core.event.* import net.pterodactylus.sone.data.* import net.pterodactylus.sone.data.Post.* import net.pterodactylus.sone.data.impl.* +import net.pterodactylus.sone.database.* import net.pterodactylus.sone.freenet.wot.* import net.pterodactylus.sone.main.* import net.pterodactylus.sone.notify.* import net.pterodactylus.sone.test.* +import net.pterodactylus.sone.text.* import net.pterodactylus.sone.utils.* import net.pterodactylus.util.notify.* import org.hamcrest.MatcherAssert.* @@ -36,7 +38,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.* @@ -58,6 +59,8 @@ class NotificationHandlerModuleTest { Loaders::class.isProvidedBy(loaders), WebOfTrustConnector::class.isProvidedBy(webOfTrustConnector), ScheduledExecutorService::class.withNameIsProvidedBy(ticker, "notification"), + SoneTextParser::class.isProvidedByMock(), + PostReplyProvider::class.isProvidedByMock(), NotificationHandlerModule() ) @@ -73,9 +76,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)) @@ -457,4 +458,37 @@ class NotificationHandlerModuleTest { verify(ticker).schedule(ArgumentMatchers.eq(webOfTrustPinger), ArgumentMatchers.eq(15L), ArgumentMatchers.eq(SECONDS)) } + @Test + fun `sone mention detector is created as singleton`() { + assertThat(injector.getInstance(), notNullValue()) + } + + @Test + fun `sone-mentioned notification is created as singleton`() { + injector.verifySingletonInstance>(named("soneMentioned")) + } + + @Test + fun `sone-mentioned notification has correct ID`() { + assertThat(injector.getInstance>(named("soneMentioned")).id, equalTo("mention-notification")) + } + + @Test + fun `sone-mentioned notification is not dismissable`() { + assertThat(injector.getInstance>(named("soneMentioned")).isDismissable, equalTo(false)) + } + + @Test + fun `sone-mentioned notification loads correct template`() { + loaders.templates += "/templates/notify/mentionNotification.html" to "<% posts>".asTemplate() + val notification = injector.getInstance>(named("soneMentioned")) + val posts = listOf(EmptyPost("1"), EmptyPost("2")).onEach(notification::add) + assertThat(notification.render(), equalTo(posts.toString())) + } + + @Test + fun `sone-mentioned handler is created as singleton`() { + injector.verifySingletonInstance() + } + }