ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentLinkedQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentLinkedQueueTest.java (file contents):
Revision 1.34 by jsr166, Wed Dec 31 20:17:39 2014 UTC vs.
Revision 1.41 by jsr166, Sun Oct 16 20:16:36 2016 UTC

# Line 19 | Line 19 | import junit.framework.TestSuite;
19   public class ConcurrentLinkedQueueTest extends JSR166TestCase {
20  
21      public static void main(String[] args) {
22 <        junit.textui.TestRunner.run(suite());
22 >        main(suite(), args);
23      }
24  
25      public static Test suite() {
26 <        return new TestSuite(ConcurrentLinkedQueueTest.class);
26 >        class Implementation implements CollectionImplementation {
27 >            public Class<?> klazz() { return ConcurrentLinkedQueue.class; }
28 >            public Collection emptyCollection() { return new ConcurrentLinkedQueue(); }
29 >            public Object makeElement(int i) { return i; }
30 >            public boolean isConcurrent() { return true; }
31 >            public boolean permitsNulls() { return false; }
32 >        }
33 >        return newTestSuite(ConcurrentLinkedQueueTest.class,
34 >                            CollectionTest.testSuite(new Implementation()));
35      }
36  
37      /**
# Line 52 | Line 60 | public class ConcurrentLinkedQueueTest e
60       */
61      public void testConstructor3() {
62          try {
63 <            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue((Collection)null);
63 >            new ConcurrentLinkedQueue((Collection)null);
64              shouldThrow();
65          } catch (NullPointerException success) {}
66      }
# Line 62 | Line 70 | public class ConcurrentLinkedQueueTest e
70       */
71      public void testConstructor4() {
72          try {
73 <            Integer[] ints = new Integer[SIZE];
66 <            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
73 >            new ConcurrentLinkedQueue(Arrays.asList(new Integer[SIZE]));
74              shouldThrow();
75          } catch (NullPointerException success) {}
76      }
# Line 72 | Line 79 | public class ConcurrentLinkedQueueTest e
79       * Initializing from Collection with some null elements throws NPE
80       */
81      public void testConstructor5() {
82 +        Integer[] ints = new Integer[SIZE];
83 +        for (int i = 0; i < SIZE - 1; ++i)
84 +            ints[i] = new Integer(i);
85          try {
86 <            Integer[] ints = new Integer[SIZE];
77 <            for (int i = 0; i < SIZE-1; ++i)
78 <                ints[i] = new Integer(i);
79 <            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints));
86 >            new ConcurrentLinkedQueue(Arrays.asList(ints));
87              shouldThrow();
88          } catch (NullPointerException success) {}
89      }
# Line 113 | Line 120 | public class ConcurrentLinkedQueueTest e
120      public void testSize() {
121          ConcurrentLinkedQueue q = populatedQueue(SIZE);
122          for (int i = 0; i < SIZE; ++i) {
123 <            assertEquals(SIZE-i, q.size());
123 >            assertEquals(SIZE - i, q.size());
124              q.remove();
125          }
126          for (int i = 0; i < SIZE; ++i) {
# Line 126 | Line 133 | public class ConcurrentLinkedQueueTest e
133       * offer(null) throws NPE
134       */
135      public void testOfferNull() {
136 +        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
137          try {
130            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
138              q.offer(null);
139              shouldThrow();
140          } catch (NullPointerException success) {}
# Line 137 | Line 144 | public class ConcurrentLinkedQueueTest e
144       * add(null) throws NPE
145       */
146      public void testAddNull() {
147 +        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
148          try {
141            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
149              q.add(null);
150              shouldThrow();
151          } catch (NullPointerException success) {}
# Line 168 | Line 175 | public class ConcurrentLinkedQueueTest e
175       * addAll(null) throws NPE
176       */
177      public void testAddAll1() {
178 +        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
179          try {
172            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
180              q.addAll(null);
181              shouldThrow();
182          } catch (NullPointerException success) {}
# Line 179 | Line 186 | public class ConcurrentLinkedQueueTest e
186       * addAll(this) throws IAE
187       */
188      public void testAddAllSelf() {
189 +        ConcurrentLinkedQueue q = populatedQueue(SIZE);
190          try {
183            ConcurrentLinkedQueue q = populatedQueue(SIZE);
191              q.addAll(q);
192              shouldThrow();
193          } catch (IllegalArgumentException success) {}
# Line 190 | Line 197 | public class ConcurrentLinkedQueueTest e
197       * addAll of a collection with null elements throws NPE
198       */
199      public void testAddAll2() {
200 +        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
201          try {
202 <            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
195 <            Integer[] ints = new Integer[SIZE];
196 <            q.addAll(Arrays.asList(ints));
202 >            q.addAll(Arrays.asList(new Integer[SIZE]));
203              shouldThrow();
204          } catch (NullPointerException success) {}
205      }
# Line 203 | Line 209 | public class ConcurrentLinkedQueueTest e
209       * possibly adding some elements
210       */
211      public void testAddAll3() {
212 +        ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
213 +        Integer[] ints = new Integer[SIZE];
214 +        for (int i = 0; i < SIZE - 1; ++i)
215 +            ints[i] = new Integer(i);
216          try {
207            ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
208            Integer[] ints = new Integer[SIZE];
209            for (int i = 0; i < SIZE-1; ++i)
210                ints[i] = new Integer(i);
217              q.addAll(Arrays.asList(ints));
218              shouldThrow();
219          } catch (NullPointerException success) {}
# Line 291 | Line 297 | public class ConcurrentLinkedQueueTest e
297              assertTrue(q.contains(i));
298              assertTrue(q.remove(i));
299              assertFalse(q.contains(i));
300 <            assertTrue(q.contains(i-1));
300 >            assertTrue(q.contains(i - 1));
301          }
302          for (int i = 0; i < SIZE; i += 2) {
303              assertTrue(q.contains(i));
304              assertTrue(q.remove(i));
305              assertFalse(q.contains(i));
306 <            assertFalse(q.remove(i+1));
307 <            assertFalse(q.contains(i+1));
306 >            assertFalse(q.remove(i + 1));
307 >            assertFalse(q.contains(i + 1));
308          }
309          assertTrue(q.isEmpty());
310      }
# Line 357 | Line 363 | public class ConcurrentLinkedQueueTest e
363                  assertTrue(changed);
364  
365              assertTrue(q.containsAll(p));
366 <            assertEquals(SIZE-i, q.size());
366 >            assertEquals(SIZE - i, q.size());
367              p.remove();
368          }
369      }
# Line 370 | Line 376 | public class ConcurrentLinkedQueueTest e
376              ConcurrentLinkedQueue q = populatedQueue(SIZE);
377              ConcurrentLinkedQueue p = populatedQueue(i);
378              assertTrue(q.removeAll(p));
379 <            assertEquals(SIZE-i, q.size());
379 >            assertEquals(SIZE - i, q.size());
380              for (int j = 0; j < i; ++j) {
381                  Integer x = (Integer)(p.remove());
382                  assertFalse(q.contains(x));
# Line 427 | Line 433 | public class ConcurrentLinkedQueueTest e
433       */
434      public void testIterator() {
435          ConcurrentLinkedQueue q = populatedQueue(SIZE);
430        int i = 0;
436          Iterator it = q.iterator();
437 <        while (it.hasNext()) {
437 >        int i;
438 >        for (i = 0; it.hasNext(); i++)
439              assertTrue(q.contains(it.next()));
434            ++i;
435        }
440          assertEquals(i, SIZE);
441 +        assertIteratorExhausted(it);
442 +    }
443 +
444 +    /**
445 +     * iterator of empty collection has no elements
446 +     */
447 +    public void testEmptyIterator() {
448 +        assertIteratorExhausted(new ConcurrentLinkedQueue().iterator());
449      }
450  
451      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines