From f22c29a66b399d50e0575f7a0ba71e6375caebf3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 17 Nov 2019 21:35:50 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=90=9B=20Fix=20deduplication?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt | 2 +- .../kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt b/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt index dccc430..99fd89a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt +++ b/src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt @@ -52,7 +52,7 @@ class ListNotification : TemplateNotification { fun setElements(elements: Collection) { realElements.clear() - realElements.addAll(elements) + realElements.addAll(elements.distinct()) touch() } diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt index 1aa554c..0c81516 100644 --- a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt @@ -37,6 +37,12 @@ class ListNotificationTest { } @Test + fun `list notification deduplicates set elements`() { + listNotification.setElements(listOf("a", "b", "a")) + assertThat(listNotification.elements, contains("a", "b")) + } + + @Test fun `list notification retains added elements`() { listNotification.add("a") listNotification.add("b") -- 2.7.4