From: David ‘Bombe’ Roden Date: Sun, 17 Nov 2019 20:35:50 +0000 (+0100) Subject: 🐛 Fix deduplication X-Git-Tag: v81^2~46 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=f22c29a66b399d50e0575f7a0ba71e6375caebf3 🐛 Fix deduplication --- 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")