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

Comparing jsr166/src/test/tck/LinkedTransferQueueTest.java (file contents):
Revision 1.52 by jsr166, Thu May 30 03:28:55 2013 UTC vs.
Revision 1.61 by jsr166, Sat May 23 00:53:08 2015 UTC

# Line 5 | Line 5
5   * Other contributors include John Vint
6   */
7  
8 < import junit.framework.*;
9 < import java.util.Arrays;
8 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
9 >
10   import java.util.ArrayList;
11 + import java.util.Arrays;
12   import java.util.Collection;
13   import java.util.Iterator;
14   import java.util.List;
# Line 18 | Line 19 | import java.util.concurrent.CountDownLat
19   import java.util.concurrent.Executors;
20   import java.util.concurrent.ExecutorService;
21   import java.util.concurrent.LinkedTransferQueue;
22 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
23 < import static java.util.concurrent.TimeUnit.NANOSECONDS;
22 >
23 > import junit.framework.Test;
24  
25   @SuppressWarnings({"unchecked", "rawtypes"})
26   public class LinkedTransferQueueTest extends JSR166TestCase {
# Line 31 | Line 32 | public class LinkedTransferQueueTest ext
32      }
33  
34      public static void main(String[] args) {
35 <        junit.textui.TestRunner.run(suite());
35 >        main(suite(), args);
36      }
37  
38      public static Test suite() {
# Line 77 | Line 78 | public class LinkedTransferQueueTest ext
78       */
79      public void testConstructor4() {
80          Integer[] ints = new Integer[SIZE];
81 <        for (int i = 0; i < SIZE-1; ++i)
81 >        for (int i = 0; i < SIZE - 1; ++i)
82              ints[i] = i;
83          Collection<Integer> elements = Arrays.asList(ints);
84          try {
# Line 114 | Line 115 | public class LinkedTransferQueueTest ext
115       * remainingCapacity() always returns Integer.MAX_VALUE
116       */
117      public void testRemainingCapacity() {
118 <        LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
118 >        BlockingQueue q = populatedQueue(SIZE);
119          for (int i = 0; i < SIZE; ++i) {
120              assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
121              assertEquals(SIZE - i, q.size());
122 <            q.remove();
122 >            assertEquals(i, q.remove());
123          }
124          for (int i = 0; i < SIZE; ++i) {
125              assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
126              assertEquals(i, q.size());
127 <            q.add(i);
127 >            assertTrue(q.add(i));
128          }
129      }
130  
# Line 131 | Line 132 | public class LinkedTransferQueueTest ext
132       * addAll(this) throws IllegalArgumentException
133       */
134      public void testAddAllSelf() {
135 +        LinkedTransferQueue q = populatedQueue(SIZE);
136          try {
135            LinkedTransferQueue q = populatedQueue(SIZE);
137              q.addAll(q);
138              shouldThrow();
139          } catch (IllegalArgumentException success) {}
# Line 143 | Line 144 | public class LinkedTransferQueueTest ext
144       * NullPointerException after possibly adding some elements
145       */
146      public void testAddAll3() {
147 +        LinkedTransferQueue q = new LinkedTransferQueue();
148 +        Integer[] ints = new Integer[SIZE];
149 +        for (int i = 0; i < SIZE - 1; ++i)
150 +            ints[i] = i;
151          try {
147            LinkedTransferQueue q = new LinkedTransferQueue();
148            Integer[] ints = new Integer[SIZE];
149            for (int i = 0; i < SIZE - 1; ++i) {
150                ints[i] = i;
151            }
152              q.addAll(Arrays.asList(ints));
153              shouldThrow();
154          } catch (NullPointerException success) {}
# Line 499 | Line 499 | public class LinkedTransferQueueTest ext
499      public void testIterator() throws InterruptedException {
500          LinkedTransferQueue q = populatedQueue(SIZE);
501          Iterator it = q.iterator();
502 <        int i = 0;
503 <        while (it.hasNext()) {
504 <            assertEquals(it.next(), i++);
505 <        }
502 >        int i;
503 >        for (i = 0; it.hasNext(); i++)
504 >            assertTrue(q.contains(it.next()));
505 >        assertEquals(i, SIZE);
506 >        assertIteratorExhausted(it);
507 >
508 >        it = q.iterator();
509 >        for (i = 0; it.hasNext(); i++)
510 >            assertEquals(it.next(), q.take());
511          assertEquals(i, SIZE);
512 +        assertIteratorExhausted(it);
513 +    }
514 +
515 +    /**
516 +     * iterator of empty collection has no elements
517 +     */
518 +    public void testEmptyIterator() {
519 +        assertIteratorExhausted(new LinkedTransferQueue().iterator());
520      }
521  
522      /**
# Line 696 | Line 709 | public class LinkedTransferQueueTest ext
709              assertEquals(SIZE - k, q.size());
710              for (int j = 0; j < k; ++j)
711                  assertEquals(j, l.get(j));
712 <            while (q.poll() != null)
700 <                ;
712 >            do {} while (q.poll() != null);
713          }
714      }
715  
# Line 849 | Line 861 | public class LinkedTransferQueueTest ext
861       * tryTransfer(null) throws NullPointerException
862       */
863      public void testTryTransfer1() {
864 +        final LinkedTransferQueue q = new LinkedTransferQueue();
865          try {
853            final LinkedTransferQueue q = new LinkedTransferQueue();
866              q.tryTransfer(null);
867              shouldThrow();
868          } catch (NullPointerException success) {}
# Line 1013 | Line 1025 | public class LinkedTransferQueueTest ext
1025          assertFalse(q.isEmpty());
1026          return q;
1027      }
1028 +
1029 +    /**
1030 +     * remove(null), contains(null) always return false
1031 +     */
1032 +    public void testNeverContainsNull() {
1033 +        Collection<?>[] qs = {
1034 +            new LinkedTransferQueue<Object>(),
1035 +            populatedQueue(2),
1036 +        };
1037 +
1038 +        for (Collection<?> q : qs) {
1039 +            assertFalse(q.contains(null));
1040 +            assertFalse(q.remove(null));
1041 +        }
1042 +    }
1043   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines