--- jsr166/src/test/tck/LinkedListTest.java 2016/10/17 00:56:11 1.42 +++ jsr166/src/test/tck/LinkedListTest.java 2018/05/28 21:19:50 1.48 @@ -10,10 +10,11 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.NoSuchElementException; +import java.util.concurrent.ThreadLocalRandom; import junit.framework.Test; -import junit.framework.TestSuite; public class LinkedListTest extends JSR166TestCase { public static void main(String[] args) { @@ -23,21 +24,33 @@ public class LinkedListTest extends JSR1 public static Test suite() { class Implementation implements CollectionImplementation { public Class klazz() { return LinkedList.class; } - public Collection emptyCollection() { return new LinkedList(); } + public List emptyCollection() { return new LinkedList(); } public Object makeElement(int i) { return i; } public boolean isConcurrent() { return false; } public boolean permitsNulls() { return true; } } - return newTestSuite(LinkedListTest.class, - CollectionTest.testSuite(new Implementation())); + class SubListImplementation extends Implementation { + public List emptyCollection() { + List list = super.emptyCollection(); + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + if (rnd.nextBoolean()) + list.add(makeElement(rnd.nextInt())); + int i = rnd.nextInt(list.size() + 1); + return list.subList(i, i); + } + } + return newTestSuite( + LinkedListTest.class, + CollectionTest.testSuite(new Implementation()), + CollectionTest.testSuite(new SubListImplementation())); } /** * Returns a new queue of given size containing consecutive * Integers 0 ... n - 1. */ - private LinkedList populatedQueue(int n) { - LinkedList q = new LinkedList(); + private static LinkedList populatedQueue(int n) { + LinkedList q = new LinkedList<>(); assertTrue(q.isEmpty()); for (int i = 0; i < n; ++i) assertTrue(q.offer(new Integer(i))); @@ -345,9 +358,11 @@ public class LinkedListTest extends JSR1 */ public void testToArray() { LinkedList q = populatedQueue(SIZE); - Object[] o = q.toArray(); - for (int i = 0; i < o.length; i++) - assertSame(o[i], q.poll()); + Object[] a = q.toArray(); + assertSame(Object[].class, a.getClass()); + for (Object o : a) + assertSame(o, q.poll()); + assertTrue(q.isEmpty()); } /** @@ -358,8 +373,9 @@ public class LinkedListTest extends JSR1 Integer[] ints = new Integer[SIZE]; Integer[] array = q.toArray(ints); assertSame(ints, array); - for (int i = 0; i < ints.length; i++) - assertSame(ints[i], q.poll()); + for (Integer o : ints) + assertSame(o, q.poll()); + assertTrue(q.isEmpty()); } /**