🐛 Fix empty notifications
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 18 Nov 2019 10:46:29 +0000 (11:46 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 18 Nov 2019 10:46:29 +0000 (11:46 +0100)
src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt
src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt

index 99fd89a..9ee328e 100644 (file)
@@ -41,13 +41,13 @@ class ListNotification<T> : TemplateNotification {
        @JvmOverloads
        constructor(id: String, key: String, template: Template, dismissable: Boolean = true) : super(id, currentTimeMillis(), currentTimeMillis(), dismissable, template) {
                this.key = key
        @JvmOverloads
        constructor(id: String, key: String, template: Template, dismissable: Boolean = true) : super(id, currentTimeMillis(), currentTimeMillis(), dismissable, template) {
                this.key = key
-               template.initialContext.set(key, elements)
+               template.initialContext.set(key, realElements)
        }
 
        constructor(listNotification: ListNotification<T>) : super(listNotification.id, listNotification.createdTime, listNotification.lastUpdatedTime, listNotification.isDismissable, Template()) {
                this.key = listNotification.key
                template.add(listNotification.template)
        }
 
        constructor(listNotification: ListNotification<T>) : super(listNotification.id, listNotification.createdTime, listNotification.lastUpdatedTime, listNotification.isDismissable, Template()) {
                this.key = listNotification.key
                template.add(listNotification.template)
-               template.initialContext.set(key, elements)
+               template.initialContext.set(key, realElements)
        }
 
        fun setElements(elements: Collection<T>) {
        }
 
        fun setElements(elements: Collection<T>) {
index 0c81516..4c82035 100644 (file)
@@ -21,6 +21,14 @@ class ListNotificationTest {
        }
 
        @Test
        }
 
        @Test
+       @Suppress("UNCHECKED_CAST")
+       fun `list in template context gets updated when elements are added`() {
+               listNotification.add("a")
+               listNotification.add("b")
+               assertThat(template.initialContext.get(KEY) as Iterable<String>, contains("a", "b"))
+       }
+
+       @Test
        fun `new list notification has no element`() {
                assertThat(listNotification.elements, emptyIterable())
        }
        fun `new list notification has no element`() {
                assertThat(listNotification.elements, emptyIterable())
        }