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

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

# Line 181 | Line 181 | public class PriorityBlockingQueueTest e
181      }
182  
183      /**
184 +     * add(null) throws NPE
185 +     */
186 +    public void testAddNull() {
187 +        try {
188 +            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
189 +            q.add(null);
190 +            shouldThrow();
191 +        } catch (NullPointerException success) { }  
192 +    }
193 +
194 +    /**
195       * Offer of comparable element succeeds
196       */
197      public void testOffer() {
# Line 225 | Line 236 | public class PriorityBlockingQueueTest e
236          }
237          catch (NullPointerException success) {}
238      }
239 +
240 +    /**
241 +     * addAll(this) throws IAE
242 +     */
243 +    public void testAddAllSelf() {
244 +        try {
245 +            PriorityBlockingQueue q = populatedQueue(SIZE);
246 +            q.addAll(q);
247 +            shouldThrow();
248 +        }
249 +        catch (IllegalArgumentException success) {}
250 +    }
251 +
252      /**
253       * addAll of a collection with null elements throws NPE
254       */
# Line 687 | Line 711 | public class PriorityBlockingQueueTest e
711              unexpectedException();
712          }    
713      }
714 +
715 +    /**
716 +     * toArray(null) throws NPE
717 +     */
718 +    public void testToArray_BadArg() {
719 +        try {
720 +            PriorityBlockingQueue q = populatedQueue(SIZE);
721 +            Object o[] = q.toArray(null);
722 +            shouldThrow();
723 +        } catch(NullPointerException success){}
724 +    }
725 +
726 +    /**
727 +     * toArray with incompatable array type throws CCE
728 +     */
729 +    public void testToArray1_BadArg() {
730 +        try {
731 +            PriorityBlockingQueue q = populatedQueue(SIZE);
732 +            Object o[] = q.toArray(new String[10] );
733 +            shouldThrow();
734 +        } catch(ArrayStoreException  success){}
735 +    }
736      
737      /**
738       * iterator iterates through all elements
# Line 789 | Line 835 | public class PriorityBlockingQueueTest e
835          }
836      }
837  
838 +    /**
839 +     * drainTo(null) throws NPE
840 +     */
841 +    public void testDrainToNull() {
842 +        PriorityBlockingQueue q = populatedQueue(SIZE);
843 +        try {
844 +            q.drainTo(null);
845 +            shouldThrow();
846 +        } catch(NullPointerException success) {
847 +        }
848 +    }
849 +
850 +    /**
851 +     * drainTo(this) throws IAE
852 +     */
853 +    public void testDrainToSelf() {
854 +        PriorityBlockingQueue q = populatedQueue(SIZE);
855 +        try {
856 +            q.drainTo(q);
857 +            shouldThrow();
858 +        } catch(IllegalArgumentException success) {
859 +        }
860 +    }
861 +
862 +    /**
863 +     * drainTo(c) empties queue into another collection c
864 +     */
865 +    public void testDrainTo() {
866 +        PriorityBlockingQueue q = populatedQueue(SIZE);
867 +        ArrayList l = new ArrayList();
868 +        q.drainTo(l);
869 +        assertEquals(q.size(), 0);
870 +        assertEquals(l.size(), SIZE);
871 +        for (int i = 0; i < SIZE; ++i)
872 +            assertEquals(l.get(i), new Integer(i));
873 +    }
874 +
875 +    /**
876 +     * drainTo empties queue
877 +     */
878 +    public void testDrainToWithActivePut() {
879 +        final PriorityBlockingQueue q = populatedQueue(SIZE);
880 +        Thread t = new Thread(new Runnable() {
881 +                public void run() {
882 +                    q.put(new Integer(SIZE+1));
883 +                }
884 +            });
885 +        try {
886 +            t.start();
887 +            ArrayList l = new ArrayList();
888 +            q.drainTo(l);
889 +            assertTrue(l.size() >= SIZE);
890 +            for (int i = 0; i < SIZE; ++i)
891 +                assertEquals(l.get(i), new Integer(i));
892 +            t.join();
893 +            assertTrue(q.size() + l.size() == SIZE+1);
894 +        } catch(Exception e){
895 +            unexpectedException();
896 +        }
897 +    }
898 +
899 +    /**
900 +     * drainTo(null, n) throws NPE
901 +     */
902 +    public void testDrainToNullN() {
903 +        PriorityBlockingQueue q = populatedQueue(SIZE);
904 +        try {
905 +            q.drainTo(null, 0);
906 +            shouldThrow();
907 +        } catch(NullPointerException success) {
908 +        }
909 +    }
910 +
911 +    /**
912 +     * drainTo(this, n) throws IAE
913 +     */
914 +    public void testDrainToSelfN() {
915 +        PriorityBlockingQueue q = populatedQueue(SIZE);
916 +        try {
917 +            q.drainTo(q, 0);
918 +            shouldThrow();
919 +        } catch(IllegalArgumentException success) {
920 +        }
921 +    }
922 +
923 +    /**
924 +     * drainTo(c, n) empties first max {n, size} elements of queue into c
925 +     */
926 +    public void testDrainToN() {
927 +        for (int i = 0; i < SIZE + 2; ++i) {
928 +            PriorityBlockingQueue q = populatedQueue(SIZE);
929 +            ArrayList l = new ArrayList();
930 +            q.drainTo(l, i);
931 +            int k = (i < SIZE)? i : SIZE;
932 +            assertEquals(q.size(), SIZE-k);
933 +            assertEquals(l.size(), k);
934 +            for (int j = 0; j < k; ++j)
935 +                assertTrue(l.contains(new Integer(j)));
936 +        }
937 +    }
938 +
939 +
940   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines