registerToadlets();
/* notification templates. */
- Template startupNotificationTemplate = loaders.loadTemplate("/templates/notify/startupNotification.html");
-
- final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
- notificationManager.addNotification(startupNotification);
-
- ticker.schedule(new Runnable() {
-
- @Override
- public void run() {
- startupNotification.dismiss();
- }
- }, 2, TimeUnit.MINUTES);
-
Template wotMissingNotificationTemplate = loaders.loadTemplate("/templates/notify/wotMissingNotification.html");
final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
ticker.scheduleAtFixedRate(new Runnable() {
newVersionHandler: NewVersionHandler,
imageInsertHandler: ImageInsertHandler,
firstStartHandler: FirstStartHandler,
- configNotReadHandler: ConfigNotReadHandler
+ configNotReadHandler: ConfigNotReadHandler,
+ startupHandler: StartupHandler
)
bind<ImageInsertHandler>().asSingleton()
bind<FirstStartHandler>().asSingleton()
bind<ConfigNotReadHandler>().asSingleton()
+ bind<StartupHandler>().asSingleton()
}
@Provides
fun getConfigNotReadNotification(loaders: Loaders) =
TemplateNotification("config-not-read-notification", loaders.loadTemplate("/templates/notify/configNotReadNotification.html"))
+ @Provides
+ @Singleton
+ @Named("startup")
+ fun getStartupNotification(loaders: Loaders) =
+ TemplateNotification("startup-notification", loaders.loadTemplate("/templates/notify/startupNotification.html"))
+
private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)
import net.pterodactylus.util.notify.*
import java.util.concurrent.*
import java.util.concurrent.TimeUnit.*
+import javax.inject.*
/**
* Handler for the [Startup] event notification.
*/
-class StartupHandler(private val notificationManager: NotificationManager, private val notification: TemplateNotification, val ticker: ScheduledExecutorService) {
+class StartupHandler @Inject constructor(
+ private val notificationManager: NotificationManager,
+ @Named("startup") private val notification: TemplateNotification,
+ private val ticker: ScheduledExecutorService) {
@Subscribe
fun startup(startup: Startup) {
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>()
+ }
+
}