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

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.5 by dl, Thu Sep 25 11:02:41 2003 UTC vs.
Revision 1.6 by dl, Sun Oct 5 23:00:39 2003 UTC

# Line 162 | Line 162 | public class ArrayBlockingQueueTest exte
162      }
163  
164      /**
165 +     *  add(null) throws NPE
166 +     */
167 +    public void testAddNull() {
168 +        try {
169 +            ArrayBlockingQueue q = new ArrayBlockingQueue(1);
170 +            q.add(null);
171 +            shouldThrow();
172 +        } catch (NullPointerException success) { }  
173 +    }
174 +
175 +    /**
176       * Offer succeeds if not full; fails if full
177       */
178      public void testOffer() {
# Line 196 | Line 207 | public class ArrayBlockingQueueTest exte
207          }
208          catch (NullPointerException success) {}
209      }
210 +
211 +    /**
212 +     * addAll(this) throws IAE
213 +     */
214 +    public void testAddAllSelf() {
215 +        try {
216 +            ArrayBlockingQueue q = populatedQueue(SIZE);
217 +            q.addAll(q);
218 +            shouldThrow();
219 +        }
220 +        catch (IllegalArgumentException success) {}
221 +    }
222 +
223 +
224      /**
225       *  addAll of a collection with null elements throws NPE
226       */
# Line 705 | Line 730 | public class ArrayBlockingQueueTest exte
730              unexpectedException();
731          }    
732      }
733 +
734 +    /**
735 +     * toArray(null) throws NPE
736 +     */
737 +    public void testToArray_BadArg() {
738 +        try {
739 +            ArrayBlockingQueue q = populatedQueue(SIZE);
740 +            Object o[] = q.toArray(null);
741 +            shouldThrow();
742 +        } catch(NullPointerException success){}
743 +    }
744 +
745 +    /**
746 +     * toArray with incompatable array type throws CCE
747 +     */
748 +    public void testToArray1_BadArg() {
749 +        try {
750 +            ArrayBlockingQueue q = populatedQueue(SIZE);
751 +            Object o[] = q.toArray(new String[10] );
752 +            shouldThrow();
753 +        } catch(ArrayStoreException  success){}
754 +    }
755 +
756      
757      /**
758       * iterator iterates through all elements
# Line 886 | Line 934 | public class ArrayBlockingQueueTest exte
934          }
935      }
936  
937 +    /**
938 +     * drainTo(null) throws NPE
939 +     */
940 +    public void testDrainToNull() {
941 +        ArrayBlockingQueue q = populatedQueue(SIZE);
942 +        try {
943 +            q.drainTo(null);
944 +            shouldThrow();
945 +        } catch(NullPointerException success) {
946 +        }
947 +    }
948 +
949 +    /**
950 +     * drainTo(this) throws IAE
951 +     */
952 +    public void testDrainToSelf() {
953 +        ArrayBlockingQueue q = populatedQueue(SIZE);
954 +        try {
955 +            q.drainTo(q);
956 +            shouldThrow();
957 +        } catch(IllegalArgumentException success) {
958 +        }
959 +    }
960 +
961 +    /**
962 +     * drainTo(c) empties queue into another collection c
963 +     */
964 +    public void testDrainTo() {
965 +        ArrayBlockingQueue q = populatedQueue(SIZE);
966 +        ArrayList l = new ArrayList();
967 +        q.drainTo(l);
968 +        assertEquals(q.size(), 0);
969 +        assertEquals(l.size(), SIZE);
970 +        for (int i = 0; i < SIZE; ++i)
971 +            assertEquals(l.get(i), new Integer(i));
972 +    }
973 +
974 +    /**
975 +     * drainTo empties full queue, unblocking a waiting put.
976 +     */
977 +    public void testDrainToWithActivePut() {
978 +        final ArrayBlockingQueue q = populatedQueue(SIZE);
979 +        Thread t = new Thread(new Runnable() {
980 +                public void run() {
981 +                    try {
982 +                        q.put(new Integer(SIZE+1));
983 +                    } catch (InterruptedException ie){
984 +                        threadUnexpectedException();
985 +                    }
986 +                }
987 +            });
988 +        try {
989 +            t.start();
990 +            ArrayList l = new ArrayList();
991 +            q.drainTo(l);
992 +            assertTrue(l.size() >= SIZE);
993 +            for (int i = 0; i < SIZE; ++i)
994 +                assertEquals(l.get(i), new Integer(i));
995 +            t.join();
996 +            assertTrue(q.size() + l.size() == SIZE+1);
997 +        } catch(Exception e){
998 +            unexpectedException();
999 +        }
1000 +    }
1001 +
1002 +    /**
1003 +     * drainTo(null, n) throws NPE
1004 +     */
1005 +    public void testDrainToNullN() {
1006 +        ArrayBlockingQueue q = populatedQueue(SIZE);
1007 +        try {
1008 +            q.drainTo(null, 0);
1009 +            shouldThrow();
1010 +        } catch(NullPointerException success) {
1011 +        }
1012 +    }
1013 +
1014 +    /**
1015 +     * drainTo(this, n) throws IAE
1016 +     */
1017 +    public void testDrainToSelfN() {
1018 +        ArrayBlockingQueue q = populatedQueue(SIZE);
1019 +        try {
1020 +            q.drainTo(q, 0);
1021 +            shouldThrow();
1022 +        } catch(IllegalArgumentException success) {
1023 +        }
1024 +    }
1025 +
1026 +    /**
1027 +     * drainTo(c, n) empties first max {n, size} elements of queue into c
1028 +     */
1029 +    public void testDrainToN() {
1030 +        for (int i = 0; i < SIZE + 2; ++i) {
1031 +            ArrayBlockingQueue q = populatedQueue(SIZE);
1032 +            ArrayList l = new ArrayList();
1033 +            q.drainTo(l, i);
1034 +            int k = (i < SIZE)? i : SIZE;
1035 +            assertEquals(q.size(), SIZE-k);
1036 +            assertEquals(l.size(), k);
1037 +            for (int j = 0; j < k; ++j)
1038 +                assertEquals(l.get(j), new Integer(j));
1039 +        }
1040 +    }
1041 +
1042  
1043   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines