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.9 by dl, Mon Dec 29 19:05:40 2003 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 152 | Line 153 | public class PriorityBlockingQueueTest e
153      }
154  
155      /**
156 <     * remainingCapacity does not change when elementa added or removed,
156 >     * remainingCapacity does not change when elements added or removed,
157       * but size does
158       */
159      public void testRemainingCapacity() {
# Line 181 | Line 182 | public class PriorityBlockingQueueTest e
182      }
183  
184      /**
185 +     * add(null) throws NPE
186 +     */
187 +    public void testAddNull() {
188 +        try {
189 +            PriorityBlockingQueue q = new PriorityBlockingQueue(1);
190 +            q.add(null);
191 +            shouldThrow();
192 +        } catch (NullPointerException success) { }  
193 +    }
194 +
195 +    /**
196       * Offer of comparable element succeeds
197       */
198      public void testOffer() {
# Line 225 | Line 237 | public class PriorityBlockingQueueTest e
237          }
238          catch (NullPointerException success) {}
239      }
240 +
241 +    /**
242 +     * addAll(this) throws IAE
243 +     */
244 +    public void testAddAllSelf() {
245 +        try {
246 +            PriorityBlockingQueue q = populatedQueue(SIZE);
247 +            q.addAll(q);
248 +            shouldThrow();
249 +        }
250 +        catch (IllegalArgumentException success) {}
251 +    }
252 +
253      /**
254       * addAll of a collection with null elements throws NPE
255       */
# Line 687 | Line 712 | public class PriorityBlockingQueueTest e
712              unexpectedException();
713          }    
714      }
715 +
716 +    /**
717 +     * toArray(null) throws NPE
718 +     */
719 +    public void testToArray_BadArg() {
720 +        try {
721 +            PriorityBlockingQueue q = populatedQueue(SIZE);
722 +            Object o[] = q.toArray(null);
723 +            shouldThrow();
724 +        } catch(NullPointerException success){}
725 +    }
726 +
727 +    /**
728 +     * toArray with incompatible array type throws CCE
729 +     */
730 +    public void testToArray1_BadArg() {
731 +        try {
732 +            PriorityBlockingQueue q = populatedQueue(SIZE);
733 +            Object o[] = q.toArray(new String[10] );
734 +            shouldThrow();
735 +        } catch(ArrayStoreException  success){}
736 +    }
737      
738      /**
739       * iterator iterates through all elements
# Line 789 | Line 836 | public class PriorityBlockingQueueTest e
836          }
837      }
838  
839 +    /**
840 +     * drainTo(null) throws NPE
841 +     */
842 +    public void testDrainToNull() {
843 +        PriorityBlockingQueue q = populatedQueue(SIZE);
844 +        try {
845 +            q.drainTo(null);
846 +            shouldThrow();
847 +        } catch(NullPointerException success) {
848 +        }
849 +    }
850 +
851 +    /**
852 +     * drainTo(this) throws IAE
853 +     */
854 +    public void testDrainToSelf() {
855 +        PriorityBlockingQueue q = populatedQueue(SIZE);
856 +        try {
857 +            q.drainTo(q);
858 +            shouldThrow();
859 +        } catch(IllegalArgumentException success) {
860 +        }
861 +    }
862 +
863 +    /**
864 +     * drainTo(c) empties queue into another collection c
865 +     */
866 +    public void testDrainTo() {
867 +        PriorityBlockingQueue q = populatedQueue(SIZE);
868 +        ArrayList l = new ArrayList();
869 +        q.drainTo(l);
870 +        assertEquals(q.size(), 0);
871 +        assertEquals(l.size(), SIZE);
872 +        for (int i = 0; i < SIZE; ++i)
873 +            assertEquals(l.get(i), new Integer(i));
874 +    }
875 +
876 +    /**
877 +     * drainTo empties queue
878 +     */
879 +    public void testDrainToWithActivePut() {
880 +        final PriorityBlockingQueue q = populatedQueue(SIZE);
881 +        Thread t = new Thread(new Runnable() {
882 +                public void run() {
883 +                    q.put(new Integer(SIZE+1));
884 +                }
885 +            });
886 +        try {
887 +            t.start();
888 +            ArrayList l = new ArrayList();
889 +            q.drainTo(l);
890 +            assertTrue(l.size() >= SIZE);
891 +            for (int i = 0; i < SIZE; ++i)
892 +                assertEquals(l.get(i), new Integer(i));
893 +            t.join();
894 +            assertTrue(q.size() + l.size() == SIZE+1);
895 +        } catch(Exception e){
896 +            unexpectedException();
897 +        }
898 +    }
899 +
900 +    /**
901 +     * drainTo(null, n) throws NPE
902 +     */
903 +    public void testDrainToNullN() {
904 +        PriorityBlockingQueue q = populatedQueue(SIZE);
905 +        try {
906 +            q.drainTo(null, 0);
907 +            shouldThrow();
908 +        } catch(NullPointerException success) {
909 +        }
910 +    }
911 +
912 +    /**
913 +     * drainTo(this, n) throws IAE
914 +     */
915 +    public void testDrainToSelfN() {
916 +        PriorityBlockingQueue q = populatedQueue(SIZE);
917 +        try {
918 +            q.drainTo(q, 0);
919 +            shouldThrow();
920 +        } catch(IllegalArgumentException success) {
921 +        }
922 +    }
923 +
924 +    /**
925 +     * drainTo(c, n) empties first max {n, size} elements of queue into c
926 +     */
927 +    public void testDrainToN() {
928 +        for (int i = 0; i < SIZE + 2; ++i) {
929 +            PriorityBlockingQueue q = populatedQueue(SIZE);
930 +            ArrayList l = new ArrayList();
931 +            q.drainTo(l, i);
932 +            int k = (i < SIZE)? i : SIZE;
933 +            assertEquals(q.size(), SIZE-k);
934 +            assertEquals(l.size(), k);
935 +            for (int j = 0; j < k; ++j)
936 +                assertTrue(l.contains(new Integer(j)));
937 +        }
938 +    }
939 +
940 +
941   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines