From 80a85fb800467a7041517ed1901b59d8a3f2cccd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 18 Nov 2019 11:46:29 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=90=9B=20Fix=20empty=20notifications?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt | 4 ++-- .../kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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()) } -- 2.7.4