From a424d2ff172aa3be9eb5155e732e6f61915d7b5e Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 8 Nov 2018 12:00:23 -0700 Subject: [PATCH] [COLLECTIONS-701] SetUniqueList.add() crashes due to infinite recursion. Add tests. --- .../collections4/list/Collections701Test.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/java/org/apache/commons/collections4/list/Collections701Test.java diff --git a/src/test/java/org/apache/commons/collections4/list/Collections701Test.java b/src/test/java/org/apache/commons/collections4/list/Collections701Test.java new file mode 100644 index 000000000..f0b92f78a --- /dev/null +++ b/src/test/java/org/apache/commons/collections4/list/Collections701Test.java @@ -0,0 +1,42 @@ +package org.apache.commons.collections4.list; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Tests for COLLECTIONS-701. + */ +public class Collections701Test { + + @Test + public void testArrayList() { + final List list = new ArrayList<>(); + list.add(list); + Assert.assertEquals(1, list.size()); + Assert.assertEquals(list, list.get(0)); + } + + @Test + public void testHashSet() { + final Set set = new HashSet<>(); + set.add(set); + Assert.assertEquals(1, set.size()); + Assert.assertEquals(set, set.iterator().next()); + } + + @Test + @Ignore + public void testSetUniqueList() { + final List source = new ArrayList<>(); + final List list = SetUniqueList.setUniqueList(source); + list.add(list); + Assert.assertEquals(1, list.size()); + Assert.assertEquals(list, list.get(0)); + } +}