--- jsr166/src/test/tck/ConcurrentLinkedDequeTest.java 2015/02/22 04:34:44 1.18 +++ jsr166/src/test/tck/ConcurrentLinkedDequeTest.java 2016/10/16 20:16:36 1.23 @@ -21,11 +21,19 @@ import junit.framework.TestSuite; public class ConcurrentLinkedDequeTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { - return new TestSuite(ConcurrentLinkedDequeTest.class); + class Implementation implements CollectionImplementation { + public Class klazz() { return ConcurrentLinkedDeque.class; } + public Collection emptyCollection() { return new ConcurrentLinkedDeque(); } + public Object makeElement(int i) { return i; } + public boolean isConcurrent() { return true; } + public boolean permitsNulls() { return false; } + } + return newTestSuite(ConcurrentLinkedDequeTest.class, + CollectionTest.testSuite(new Implementation())); } /** @@ -65,8 +73,7 @@ public class ConcurrentLinkedDequeTest e */ public void testConstructor4() { try { - Integer[] ints = new Integer[SIZE]; - new ConcurrentLinkedDeque(Arrays.asList(ints)); + new ConcurrentLinkedDeque(Arrays.asList(new Integer[SIZE])); shouldThrow(); } catch (NullPointerException success) {} } @@ -75,10 +82,10 @@ public class ConcurrentLinkedDequeTest e * Initializing from Collection with some null elements throws NPE */ public void testConstructor5() { + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = new Integer(i); try { - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i); new ConcurrentLinkedDeque(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -116,7 +123,7 @@ public class ConcurrentLinkedDequeTest e public void testSize() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); q.remove(); } for (int i = 0; i < SIZE; ++i) { @@ -129,8 +136,8 @@ public class ConcurrentLinkedDequeTest e * push(null) throws NPE */ public void testPushNull() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.push(null); shouldThrow(); } catch (NullPointerException success) {} @@ -164,8 +171,8 @@ public class ConcurrentLinkedDequeTest e * offer(null) throws NPE */ public void testOfferNull() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.offer(null); shouldThrow(); } catch (NullPointerException success) {} @@ -175,8 +182,8 @@ public class ConcurrentLinkedDequeTest e * offerFirst(null) throws NPE */ public void testOfferFirstNull() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.offerFirst(null); shouldThrow(); } catch (NullPointerException success) {} @@ -186,8 +193,8 @@ public class ConcurrentLinkedDequeTest e * offerLast(null) throws NPE */ public void testOfferLastNull() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.offerLast(null); shouldThrow(); } catch (NullPointerException success) {} @@ -230,8 +237,8 @@ public class ConcurrentLinkedDequeTest e * add(null) throws NPE */ public void testAddNull() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.add(null); shouldThrow(); } catch (NullPointerException success) {} @@ -241,8 +248,8 @@ public class ConcurrentLinkedDequeTest e * addFirst(null) throws NPE */ public void testAddFirstNull() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.addFirst(null); shouldThrow(); } catch (NullPointerException success) {} @@ -252,8 +259,8 @@ public class ConcurrentLinkedDequeTest e * addLast(null) throws NPE */ public void testAddLastNull() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.addLast(null); shouldThrow(); } catch (NullPointerException success) {} @@ -296,8 +303,8 @@ public class ConcurrentLinkedDequeTest e * addAll(null) throws NPE */ public void testAddAll1() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); q.addAll(null); shouldThrow(); } catch (NullPointerException success) {} @@ -307,8 +314,8 @@ public class ConcurrentLinkedDequeTest e * addAll(this) throws IAE */ public void testAddAllSelf() { + ConcurrentLinkedDeque q = populatedDeque(SIZE); try { - ConcurrentLinkedDeque q = populatedDeque(SIZE); q.addAll(q); shouldThrow(); } catch (IllegalArgumentException success) {} @@ -318,10 +325,9 @@ public class ConcurrentLinkedDequeTest e * addAll of a collection with null elements throws NPE */ public void testAddAll2() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); - Integer[] ints = new Integer[SIZE]; - q.addAll(Arrays.asList(ints)); + q.addAll(Arrays.asList(new Integer[SIZE])); shouldThrow(); } catch (NullPointerException success) {} } @@ -331,11 +337,11 @@ public class ConcurrentLinkedDequeTest e * possibly adding some elements */ public void testAddAll3() { + ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = new Integer(i); try { - ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -372,7 +378,7 @@ public class ConcurrentLinkedDequeTest e */ public void testPollLast() { ConcurrentLinkedDeque q = populatedDeque(SIZE); - for (int i = SIZE-1; i >= 0; --i) { + for (int i = SIZE - 1; i >= 0; --i) { assertEquals(i, q.pollLast()); } assertNull(q.pollLast()); @@ -441,14 +447,14 @@ public class ConcurrentLinkedDequeTest e assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); - assertTrue(q.contains(i-1)); + assertTrue(q.contains(i - 1)); } for (int i = 0; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); - assertFalse(q.remove(i+1)); - assertFalse(q.contains(i+1)); + assertFalse(q.remove(i + 1)); + assertFalse(q.contains(i + 1)); } assertTrue(q.isEmpty()); } @@ -472,7 +478,7 @@ public class ConcurrentLinkedDequeTest e */ public void testPeekLast() { ConcurrentLinkedDeque q = populatedDeque(SIZE); - for (int i = SIZE-1; i >= 0; --i) { + for (int i = SIZE - 1; i >= 0; --i) { assertEquals(i, q.peekLast()); assertEquals(i, q.pollLast()); assertTrue(q.peekLast() == null || @@ -501,7 +507,7 @@ public class ConcurrentLinkedDequeTest e */ public void testLastElement() { ConcurrentLinkedDeque q = populatedDeque(SIZE); - for (int i = SIZE-1; i >= 0; --i) { + for (int i = SIZE - 1; i >= 0; --i) { assertEquals(i, q.getLast()); assertEquals(i, q.pollLast()); } @@ -552,7 +558,7 @@ public class ConcurrentLinkedDequeTest e } for (int i = 0; i < SIZE; i += 2) { assertTrue(q.removeFirstOccurrence(new Integer(i))); - assertFalse(q.removeFirstOccurrence(new Integer(i+1))); + assertFalse(q.removeFirstOccurrence(new Integer(i + 1))); } assertTrue(q.isEmpty()); } @@ -567,7 +573,7 @@ public class ConcurrentLinkedDequeTest e } for (int i = 0; i < SIZE; i += 2) { assertTrue(q.removeLastOccurrence(new Integer(i))); - assertFalse(q.removeLastOccurrence(new Integer(i+1))); + assertFalse(q.removeLastOccurrence(new Integer(i + 1))); } assertTrue(q.isEmpty()); } @@ -626,7 +632,7 @@ public class ConcurrentLinkedDequeTest e assertTrue(changed); assertTrue(q.containsAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); p.remove(); } } @@ -639,7 +645,7 @@ public class ConcurrentLinkedDequeTest e ConcurrentLinkedDeque q = populatedDeque(SIZE); ConcurrentLinkedDeque p = populatedDeque(i); assertTrue(q.removeAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.remove()); assertFalse(q.contains(x)); @@ -755,18 +761,18 @@ public class ConcurrentLinkedDequeTest e final Random rng = new Random(); for (int iters = 0; iters < 100; ++iters) { int max = rng.nextInt(5) + 2; - int split = rng.nextInt(max-1) + 1; + int split = rng.nextInt(max - 1) + 1; for (int j = 1; j <= max; ++j) q.add(new Integer(j)); Iterator it = q.iterator(); for (int j = 1; j <= split; ++j) assertEquals(it.next(), new Integer(j)); it.remove(); - assertEquals(it.next(), new Integer(split+1)); + assertEquals(it.next(), new Integer(split + 1)); for (int j = 1; j <= split; ++j) q.remove(new Integer(j)); it = q.iterator(); - for (int j = split+1; j <= max; ++j) { + for (int j = split + 1; j <= max; ++j) { assertEquals(it.next(), new Integer(j)); it.remove(); } @@ -823,18 +829,18 @@ public class ConcurrentLinkedDequeTest e final Random rng = new Random(); for (int iters = 0; iters < 100; ++iters) { int max = rng.nextInt(5) + 2; - int split = rng.nextInt(max-1) + 1; + int split = rng.nextInt(max - 1) + 1; for (int j = max; j >= 1; --j) q.add(new Integer(j)); Iterator it = q.descendingIterator(); for (int j = 1; j <= split; ++j) assertEquals(it.next(), new Integer(j)); it.remove(); - assertEquals(it.next(), new Integer(split+1)); + assertEquals(it.next(), new Integer(split + 1)); for (int j = 1; j <= split; ++j) q.remove(new Integer(j)); it = q.descendingIterator(); - for (int j = split+1; j <= max; ++j) { + for (int j = split + 1; j <= max; ++j) { assertEquals(it.next(), new Integer(j)); it.remove(); }