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

Comparing jsr166/src/test/tck/DelayQueueTest.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:40 2003 UTC

# Line 232 | Line 232 | public class DelayQueueTest extends JSR1
232      }
233  
234      /**
235 +     * add(null) throws NPE
236 +     */
237 +    public void testAddNull() {
238 +        try {
239 +            DelayQueue q = new DelayQueue();
240 +            q.add(null);
241 +            shouldThrow();
242 +        } catch (NullPointerException success) { }  
243 +    }
244 +
245 +    /**
246       * offer non-null succeeds
247       */
248      public void testOffer() {
# Line 262 | Line 273 | public class DelayQueueTest extends JSR1
273          }
274          catch (NullPointerException success) {}
275      }
276 +
277 +
278 +    /**
279 +     * addAll(this) throws IAE
280 +     */
281 +    public void testAddAllSelf() {
282 +        try {
283 +            DelayQueue q = populatedQueue(SIZE);
284 +            q.addAll(q);
285 +            shouldThrow();
286 +        }
287 +        catch (IllegalArgumentException success) {}
288 +    }
289 +
290      /**
291       * addAll of a collection with null elements throws NPE
292       */
# Line 724 | Line 749 | public class DelayQueueTest extends JSR1
749              unexpectedException();
750          }    
751      }
752 +
753 +
754 +    /**
755 +     * toArray(null) throws NPE
756 +     */
757 +    public void testToArray_BadArg() {
758 +        try {
759 +            DelayQueue q = populatedQueue(SIZE);
760 +            Object o[] = q.toArray(null);
761 +            shouldThrow();
762 +        } catch(NullPointerException success){}
763 +    }
764 +
765 +    /**
766 +     * toArray with incompatable array type throws CCE
767 +     */
768 +    public void testToArray1_BadArg() {
769 +        try {
770 +            DelayQueue q = populatedQueue(SIZE);
771 +            Object o[] = q.toArray(new String[10] );
772 +            shouldThrow();
773 +        } catch(ArrayStoreException  success){}
774 +    }
775      
776      /**
777       * iterator iterates through all elements
# Line 832 | Line 880 | public class DelayQueueTest extends JSR1
880          }
881      }
882  
883 +
884 +    /**
885 +     * drainTo(null) throws NPE
886 +     */
887 +    public void testDrainToNull() {
888 +        DelayQueue q = populatedQueue(SIZE);
889 +        try {
890 +            q.drainTo(null);
891 +            shouldThrow();
892 +        } catch(NullPointerException success) {
893 +        }
894 +    }
895 +
896 +    /**
897 +     * drainTo(this) throws IAE
898 +     */
899 +    public void testDrainToSelf() {
900 +        DelayQueue q = populatedQueue(SIZE);
901 +        try {
902 +            q.drainTo(q);
903 +            shouldThrow();
904 +        } catch(IllegalArgumentException success) {
905 +        }
906 +    }
907 +
908 +    /**
909 +     * drainTo(c) empties queue into another collection c
910 +     */
911 +    public void testDrainTo() {
912 +        DelayQueue q = populatedQueue(SIZE);
913 +        ArrayList l = new ArrayList();
914 +        q.drainTo(l);
915 +        assertEquals(q.size(), 0);
916 +        assertEquals(l.size(), SIZE);
917 +    }
918 +
919 +    /**
920 +     * drainTo empties queue
921 +     */
922 +    public void testDrainToWithActivePut() {
923 +        final DelayQueue q = populatedQueue(SIZE);
924 +        Thread t = new Thread(new Runnable() {
925 +                public void run() {
926 +                    q.put(new PDelay(SIZE+1));
927 +                }
928 +            });
929 +        try {
930 +            t.start();
931 +            ArrayList l = new ArrayList();
932 +            q.drainTo(l);
933 +            assertTrue(l.size() >= SIZE);
934 +            t.join();
935 +            assertTrue(q.size() + l.size() == SIZE+1);
936 +        } catch(Exception e){
937 +            unexpectedException();
938 +        }
939 +    }
940 +
941 +    /**
942 +     * drainTo(null, n) throws NPE
943 +     */
944 +    public void testDrainToNullN() {
945 +        DelayQueue q = populatedQueue(SIZE);
946 +        try {
947 +            q.drainTo(null, 0);
948 +            shouldThrow();
949 +        } catch(NullPointerException success) {
950 +        }
951 +    }
952 +
953 +    /**
954 +     * drainTo(this, n) throws IAE
955 +     */
956 +    public void testDrainToSelfN() {
957 +        DelayQueue q = populatedQueue(SIZE);
958 +        try {
959 +            q.drainTo(q, 0);
960 +            shouldThrow();
961 +        } catch(IllegalArgumentException success) {
962 +        }
963 +    }
964 +
965 +    /**
966 +     * drainTo(c, n) empties first max {n, size} elements of queue into c
967 +     */
968 +    public void testDrainToN() {
969 +        for (int i = 0; i < SIZE + 2; ++i) {
970 +            DelayQueue q = populatedQueue(SIZE);
971 +            ArrayList l = new ArrayList();
972 +            q.drainTo(l, i);
973 +            int k = (i < SIZE)? i : SIZE;
974 +            assertEquals(q.size(), SIZE-k);
975 +            assertEquals(l.size(), k);
976 +        }
977 +    }
978 +
979 +
980   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines