diff options
author | Narayan Kamath <narayan@google.com> | 2015-04-28 11:40:00 +0100 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2015-04-30 12:00:08 +0100 |
commit | 8e9a0e92906742b17eb08d7fb83cca91965f9b8e (patch) | |
tree | 790a5161ed9c8648a8dacc94c36b5db53f8da4eb /jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java | |
parent | edf43d27e240d82106f39ae91404963c23987234 (diff) |
Update JSR166 tck tests.
The following tests have been omitted because they are
unsupported :
- Atomic8Test.java
- CompletableFutureTest.java
- ConcurrentHashMap8Test.java
- DoubleAccumulatorTest.java
- DoubleAdderTest.java
- ForkJoinPool8Test.java
- ForkJoinTask8Test.java
- LongAccumulatorTest.java
- LongAdderTest.java
- SplittableRandomTest.java
- StampedLockTest.java
- ThreadLocalRandom8Test.java
- ThreadPoolExecutor9Test.java
A package declaration has been added to all files (package jsr166;)
and the base-class JSR166Test has been changed not to rely on features
that aren't available on android / junit in the android environment.
We also avoid using junit4 style TestSuite declarations. While the CTS
test runner handles them properly usually, it trips over itself when it
encounters a failure and tries to run each test in an invidual process
and fails each test for no good reason (needs investigation on the CTS
side of things)
bug: 20628776
(cherry picked from commit 5da8b2b3cac51f0f592a5e1941bd84eade9648cd)
Change-Id: If35be0881ad8da4c604ce6683149b15c1a85f289
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java b/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java index 7924034418..d3f5b1f83b 100644 --- a/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java +++ b/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java @@ -8,7 +8,6 @@ package jsr166; -import junit.framework.*; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -16,8 +15,21 @@ import java.util.NoSuchElementException; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import junit.framework.Test; +import junit.framework.TestSuite; + public class ConcurrentLinkedQueueTest extends JSR166TestCase { + // android-note: Removed because the CTS runner does a bad job of + // retrying tests that have suite() declarations. + // + // public static void main(String[] args) { + // main(suite(), args); + // } + // public static Test suite() { + // return new TestSuite(...); + // } + /** * Returns a new queue of given size containing consecutive * Integers 0 ... n. @@ -44,7 +56,7 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase { */ public void testConstructor3() { try { - ConcurrentLinkedQueue q = new ConcurrentLinkedQueue((Collection)null); + new ConcurrentLinkedQueue((Collection)null); shouldThrow(); } catch (NullPointerException success) {} } @@ -55,7 +67,7 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase { public void testConstructor4() { try { Integer[] ints = new Integer[SIZE]; - ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints)); + new ConcurrentLinkedQueue(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} } @@ -68,7 +80,7 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase { Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE-1; ++i) ints[i] = new Integer(i); - ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints)); + new ConcurrentLinkedQueue(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} } @@ -279,13 +291,13 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase { */ public void testRemoveElement() { ConcurrentLinkedQueue q = populatedQueue(SIZE); - for (int i = 1; i < SIZE; i+=2) { + for (int i = 1; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); assertTrue(q.contains(i-1)); } - for (int i = 0; i < SIZE; i+=2) { + for (int i = 0; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); @@ -364,8 +376,8 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase { assertTrue(q.removeAll(p)); assertEquals(SIZE-i, q.size()); for (int j = 0; j < i; ++j) { - Integer I = (Integer)(p.remove()); - assertFalse(q.contains(I)); + Integer x = (Integer)(p.remove()); + assertFalse(q.contains(x)); } } } @@ -419,13 +431,19 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase { */ public void testIterator() { ConcurrentLinkedQueue q = populatedQueue(SIZE); - int i = 0; Iterator it = q.iterator(); - while (it.hasNext()) { + int i; + for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next())); - ++i; - } assertEquals(i, SIZE); + assertIteratorExhausted(it); + } + + /** + * iterator of empty collection has no elements + */ + public void testEmptyIterator() { + assertIteratorExhausted(new ConcurrentLinkedQueue().iterator()); } /** @@ -508,4 +526,18 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase { assertTrue(y.isEmpty()); } + /** + * remove(null), contains(null) always return false + */ + public void testNeverContainsNull() { + Collection<?>[] qs = { + new ConcurrentLinkedQueue<Object>(), + populatedQueue(2), + }; + + for (Collection<?> q : qs) { + assertFalse(q.contains(null)); + assertFalse(q.remove(null)); + } + } } |