From: David ‘Bombe’ Roden Date: Mon, 18 Nov 2019 10:46:29 +0000 (+0100) Subject: 🐛 Fix empty notifications X-Git-Tag: v81^2~42 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=80a85fb800467a7041517ed1901b59d8a3f2cccd 🐛 Fix empty notifications --- diff --git a/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt b/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt index 99fd89a..9ee328e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt +++ b/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt @@ -41,13 +41,13 @@ class ListNotification : TemplateNotification { @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) : 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) { diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt index 0c81516..4c82035 100644 --- a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt @@ -21,6 +21,14 @@ class ListNotificationTest { } @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, contains("a", "b")) + } + + @Test fun `new list notification has no element`() { assertThat(listNotification.elements, emptyIterable()) }