From 15975fffc055e2acfa129ce5821d2aa0cc045717 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:19:59 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=90=9B=20Deduplicate=20items=20added=20to?= =?utf8?q?=20list=20notification?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/notify/ListNotification.java | 6 ++++-- .../kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java index 6a7b086..0c9e504 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java @@ -129,8 +129,10 @@ public class ListNotification extends TemplateNotification { * The new element */ public void add(T element) { - elements.add(element); - touch(); + if (!elements.contains(element)) { + elements.add(element); + touch(); + } } /** diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt index 08d4829..1aa554c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationTest.kt @@ -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") -- 2.7.4