🐛 Fix deduplication
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 17 Nov 2019 20:35:50 +0000 (21:35 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 17 Nov 2019 20:35:50 +0000 (21:35 +0100)
src/main/kotlin/net/pterodactylus/sone/notify/ListNotification.kt
src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt

index dccc430..99fd89a 100644 (file)
@@ -52,7 +52,7 @@ class ListNotification<T> : TemplateNotification {
 
        fun setElements(elements: Collection<T>) {
                realElements.clear()
 
        fun setElements(elements: Collection<T>) {
                realElements.clear()
-               realElements.addAll(elements)
+               realElements.addAll(elements.distinct())
                touch()
        }
 
                touch()
        }
 
index 1aa554c..0c81516 100644 (file)
@@ -37,6 +37,12 @@ class ListNotificationTest {
        }
 
        @Test
        }
 
        @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")
        fun `list notification retains added elements`() {
                listNotification.add("a")
                listNotification.add("b")