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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.26 by jsr166, Tue Oct 19 00:41:14 2010 UTC vs.
Revision 1.33 by jsr166, Thu Nov 18 20:21:53 2010 UTC

# Line 38 | Line 38 | public class LinkedBlockingDequeTest ext
38       * Create a deque of given size containing consecutive
39       * Integers 0 ... n.
40       */
41 <    private LinkedBlockingDeque populatedDeque(int n) {
42 <        LinkedBlockingDeque q = new LinkedBlockingDeque(n);
41 >    private LinkedBlockingDeque<Integer> populatedDeque(int n) {
42 >        LinkedBlockingDeque<Integer> q =
43 >            new LinkedBlockingDeque<Integer>(n);
44          assertTrue(q.isEmpty());
45          for (int i = 0; i < n; i++)
46              assertTrue(q.offer(new Integer(i)));
# Line 682 | Line 683 | public class LinkedBlockingDequeTest ext
683      }
684  
685      /**
685     * take blocks interruptibly when empty
686     */
687    public void testTakeFromEmpty() throws InterruptedException {
688        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
689        Thread t = new ThreadShouldThrow(InterruptedException.class) {
690            public void realRun() throws InterruptedException {
691                q.take();
692            }};
693
694        t.start();
695        Thread.sleep(SHORT_DELAY_MS);
696        t.interrupt();
697        t.join();
698    }
699
700    /**
686       * Take removes existing elements until empty, then blocks interruptibly
687       */
688      public void testBlockingTake() throws InterruptedException {
# Line 1223 | Line 1208 | public class LinkedBlockingDequeTest ext
1208      public void testRemoveElement() {
1209          LinkedBlockingDeque q = populatedDeque(SIZE);
1210          for (int i = 1; i < SIZE; i+=2) {
1211 <            assertTrue(q.remove(new Integer(i)));
1211 >            assertTrue(q.contains(i));
1212 >            assertTrue(q.remove(i));
1213 >            assertFalse(q.contains(i));
1214 >            assertTrue(q.contains(i-1));
1215          }
1216          for (int i = 0; i < SIZE; i+=2) {
1217 <            assertTrue(q.remove(new Integer(i)));
1218 <            assertFalse(q.remove(new Integer(i+1)));
1217 >            assertTrue(q.contains(i));
1218 >            assertTrue(q.remove(i));
1219 >            assertFalse(q.contains(i));
1220 >            assertFalse(q.remove(i+1));
1221 >            assertFalse(q.contains(i+1));
1222          }
1223          assertTrue(q.isEmpty());
1224      }
# Line 1310 | Line 1301 | public class LinkedBlockingDequeTest ext
1301      }
1302  
1303      /**
1304 <     * toArray contains all elements
1304 >     * toArray contains all elements in FIFO order
1305       */
1306      public void testToArray() throws InterruptedException{
1307          LinkedBlockingDeque q = populatedDeque(SIZE);
1308          Object[] o = q.toArray();
1309          for (int i = 0; i < o.length; i++)
1310 <            assertEquals(o[i], q.take());
1310 >            assertSame(o[i], q.poll());
1311      }
1312  
1313      /**
1314 <     * toArray(a) contains all elements
1314 >     * toArray(a) contains all elements in FIFO order
1315       */
1316 <    public void testToArray2() throws InterruptedException {
1317 <        LinkedBlockingDeque q = populatedDeque(SIZE);
1316 >    public void testToArray2() {
1317 >        LinkedBlockingDeque<Integer> q = populatedDeque(SIZE);
1318          Integer[] ints = new Integer[SIZE];
1319 <        ints = (Integer[])q.toArray(ints);
1319 >        Integer[] array = q.toArray(ints);
1320 >        assertSame(ints, array);
1321          for (int i = 0; i < ints.length; i++)
1322 <            assertEquals(ints[i], q.take());
1322 >            assertSame(ints[i], q.remove());
1323      }
1324  
1325      /**
1326 <     * toArray(null) throws NPE
1326 >     * toArray(null) throws NullPointerException
1327       */
1328 <    public void testToArray_BadArg() {
1328 >    public void testToArray_NullArg() {
1329          LinkedBlockingDeque q = populatedDeque(SIZE);
1330          try {
1331 <            Object o[] = q.toArray(null);
1331 >            q.toArray(null);
1332              shouldThrow();
1333          } catch (NullPointerException success) {}
1334      }
1335  
1336      /**
1337 <     * toArray with incompatible array type throws CCE
1337 >     * toArray(incompatible array type) throws ArrayStoreException
1338       */
1339      public void testToArray1_BadArg() {
1340          LinkedBlockingDeque q = populatedDeque(SIZE);
1341          try {
1342 <            Object o[] = q.toArray(new String[10]);
1342 >            q.toArray(new String[10]);
1343              shouldThrow();
1344          } catch (ArrayStoreException success) {}
1345      }
# Line 1654 | Line 1646 | public class LinkedBlockingDequeTest ext
1646                  assertTrue(q.offer(new Integer(j)));
1647              ArrayList l = new ArrayList();
1648              q.drainTo(l, i);
1649 <            int k = (i < SIZE)? i : SIZE;
1649 >            int k = (i < SIZE) ? i : SIZE;
1650              assertEquals(l.size(), k);
1651              assertEquals(q.size(), SIZE-k);
1652              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines