🐛 Deduplicate items added to list notification
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 17 Nov 2019 20:19:59 +0000 (21:19 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 17 Nov 2019 20:19:59 +0000 (21:19 +0100)
src/main/java/net/pterodactylus/sone/notify/ListNotification.java
src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt

index 6a7b086..0c9e504 100644 (file)
@@ -129,8 +129,10 @@ public class ListNotification<T> extends TemplateNotification {
         *            The new element
         */
        public void add(T element) {
-               elements.add(element);
-               touch();
+               if (!elements.contains(element)) {
+                       elements.add(element);
+                       touch();
+               }
        }
 
        /**
index 08d4829..1aa554c 100644 (file)
@@ -45,6 +45,14 @@ class ListNotificationTest {
        }
 
        @Test
+       fun `list notification deduplicates elements`() {
+               listNotification.add("a")
+               listNotification.add("b")
+               listNotification.add("a")
+               assertThat(listNotification.elements, contains("a", "b"))
+       }
+
+       @Test
        fun `list notification removes correct element`() {
                listNotification.setElements(listOf("a", "b", "c"))
                listNotification.remove("b")