🚧 Use ticker from Sone module for notifications
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / notification / NotificationHandlerModuleTest.kt
index 8a4bcc9..b84b3ee 100644 (file)
@@ -34,6 +34,7 @@ import org.hamcrest.MatcherAssert.*
 import org.hamcrest.Matchers.*
 import org.mockito.Mockito.*
 import java.io.*
+import java.util.concurrent.*
 import kotlin.test.*
 
 /**
@@ -42,12 +43,14 @@ import kotlin.test.*
 class NotificationHandlerModuleTest {
 
        private val core = mock<Core>()
+       private val ticker = mock<ScheduledExecutorService>()
        private val notificationManager = NotificationManager()
        private val loaders = TestLoaders()
        private val injector: Injector = createInjector(
                        Core::class.isProvidedBy(core),
                        NotificationManager::class.isProvidedBy(notificationManager),
                        Loaders::class.isProvidedBy(loaders),
+                       ScheduledExecutorService::class.withNameIsProvidedBy(ticker, "notification"),
                        NotificationHandlerModule()
        )
 
@@ -343,4 +346,58 @@ class NotificationHandlerModuleTest {
                injector.verifySingletonInstance<FirstStartHandler>()
        }
 
+       @Test
+       fun `config-not-read notification is created as singleton`() {
+               injector.verifySingletonInstance<TemplateNotification>(named("configNotRead"))
+       }
+
+       @Test
+       fun `config-not-read notification has correct ID `() {
+               assertThat(injector.getInstance<TemplateNotification>(named("configNotRead")).id, equalTo("config-not-read-notification"))
+       }
+
+       @Test
+       fun `config-not-read notification is dismissable`() {
+               assertThat(injector.getInstance<TemplateNotification>(named("configNotRead")).isDismissable, equalTo(true))
+       }
+
+       @Test
+       fun `config-not-read notification loads correct template`() {
+               loaders.templates += "/templates/notify/configNotReadNotification.html" to "1".asTemplate()
+               val notification = injector.getInstance<TemplateNotification>(named("configNotRead"))
+               assertThat(notification.render(), equalTo("1"))
+       }
+
+       @Test
+       fun `config-not-read handler is created as singleton`() {
+               injector.verifySingletonInstance<ConfigNotReadHandler>()
+       }
+
+       @Test
+       fun `startup notification can be created`() {
+               injector.verifySingletonInstance<TemplateNotification>(named("startup"))
+       }
+
+       @Test
+       fun `startup notification has correct ID`() {
+               assertThat(injector.getInstance<TemplateNotification>(named("startup")).id, equalTo("startup-notification"))
+       }
+
+       @Test
+       fun `startup notification is dismissable`() {
+               assertThat(injector.getInstance<TemplateNotification>(named("startup")).isDismissable, equalTo(true))
+       }
+
+       @Test
+       fun `startup notification loads correct template`() {
+               loaders.templates += "/templates/notify/startupNotification.html" to "1".asTemplate()
+               val notification = injector.getInstance<TemplateNotification>(named("startup"))
+               assertThat(notification.render(), equalTo("1"))
+       }
+
+       @Test
+       fun `startup handler is created as singleton`() {
+               injector.verifySingletonInstance<StartupHandler>()
+       }
+
 }