[COLLECTIONS-701] SetUniqueList.add() crashes due to infinite recursion.

Add tests.
This commit is contained in:
Gary Gregory 2018-11-08 12:00:23 -07:00
parent d8fd531766
commit a424d2ff17
1 changed files with 42 additions and 0 deletions

View File

@ -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<Object> list = new ArrayList<>();
list.add(list);
Assert.assertEquals(1, list.size());
Assert.assertEquals(list, list.get(0));
}
@Test
public void testHashSet() {
final Set<Object> set = new HashSet<>();
set.add(set);
Assert.assertEquals(1, set.size());
Assert.assertEquals(set, set.iterator().next());
}
@Test
@Ignore
public void testSetUniqueList() {
final List<Object> source = new ArrayList<>();
final List<Object> list = SetUniqueList.setUniqueList(source);
list.add(list);
Assert.assertEquals(1, list.size());
Assert.assertEquals(list, list.get(0));
}
}