[cvs] / jsr166 / src / test / tck / ArrayBlockingQueueTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/ArrayBlockingQueueTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.47, Fri May 27 20:07:24 2011 UTC revision 1.48, Mon May 30 22:43:20 2011 UTC
# Line 7  Line 7 
7   */   */
8    
9  import junit.framework.*;  import junit.framework.*;
10  import java.util.*;  import java.util.Arrays;
11  import java.util.concurrent.*;  import java.util.ArrayList;
12    import java.util.Collection;
13    import java.util.Iterator;
14    import java.util.NoSuchElementException;
15    import java.util.concurrent.ArrayBlockingQueue;
16    import java.util.concurrent.BlockingQueue;
17    import java.util.concurrent.CountDownLatch;
18    import java.util.concurrent.Executors;
19    import java.util.concurrent.ExecutorService;
20  import static java.util.concurrent.TimeUnit.MILLISECONDS;  import static java.util.concurrent.TimeUnit.MILLISECONDS;
21  import java.io.*;  import java.io.*;
22    
# Line 63  Line 71 
71       */       */
72      public void testConstructor2() {      public void testConstructor2() {
73          try {          try {
74              ArrayBlockingQueue q = new ArrayBlockingQueue(0);              new ArrayBlockingQueue(0);
75              shouldThrow();              shouldThrow();
76          } catch (IllegalArgumentException success) {}          } catch (IllegalArgumentException success) {}
77      }      }
# Line 73  Line 81 
81       */       */
82      public void testConstructor3() {      public void testConstructor3() {
83          try {          try {
84              ArrayBlockingQueue q = new ArrayBlockingQueue(1, true, null);              new ArrayBlockingQueue(1, true, null);
85              shouldThrow();              shouldThrow();
86          } catch (NullPointerException success) {}          } catch (NullPointerException success) {}
87      }      }
# Line 82  Line 90 
90       * Initializing from Collection of null elements throws NPE       * Initializing from Collection of null elements throws NPE
91       */       */
92      public void testConstructor4() {      public void testConstructor4() {
93            Collection<Integer> elements = Arrays.asList(new Integer[SIZE]);
94          try {          try {
95              Integer[] ints = new Integer[SIZE];              new ArrayBlockingQueue(SIZE, false, elements);
             ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE, false, Arrays.asList(ints));  
96              shouldThrow();              shouldThrow();
97          } catch (NullPointerException success) {}          } catch (NullPointerException success) {}
98      }      }
# Line 93  Line 101 
101       * Initializing from Collection with some null elements throws NPE       * Initializing from Collection with some null elements throws NPE
102       */       */
103      public void testConstructor5() {      public void testConstructor5() {
         try {  
104              Integer[] ints = new Integer[SIZE];              Integer[] ints = new Integer[SIZE];
105              for (int i = 0; i < SIZE-1; ++i)              for (int i = 0; i < SIZE-1; ++i)
106                  ints[i] = new Integer(i);              ints[i] = i;
107              ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE, false, Arrays.asList(ints));          Collection<Integer> elements = Arrays.asList(ints);
108            try {
109                new ArrayBlockingQueue(SIZE, false, Arrays.asList(ints));
110              shouldThrow();              shouldThrow();
111          } catch (NullPointerException success) {}          } catch (NullPointerException success) {}
112      }      }
# Line 106  Line 115 
115       * Initializing from too large collection throws IAE       * Initializing from too large collection throws IAE
116       */       */
117      public void testConstructor6() {      public void testConstructor6() {
         try {  
118              Integer[] ints = new Integer[SIZE];              Integer[] ints = new Integer[SIZE];
119              for (int i = 0; i < SIZE; ++i)              for (int i = 0; i < SIZE; ++i)
120                  ints[i] = new Integer(i);              ints[i] = i;
121              ArrayBlockingQueue q = new ArrayBlockingQueue(1, false, Arrays.asList(ints));          Collection<Integer> elements = Arrays.asList(ints);
122            try {
123                new ArrayBlockingQueue(SIZE - 1, false, elements);
124              shouldThrow();              shouldThrow();
125          } catch (IllegalArgumentException success) {}          } catch (IllegalArgumentException success) {}
126      }      }
# Line 121  Line 131 
131      public void testConstructor7() {      public void testConstructor7() {
132          Integer[] ints = new Integer[SIZE];          Integer[] ints = new Integer[SIZE];
133          for (int i = 0; i < SIZE; ++i)          for (int i = 0; i < SIZE; ++i)
134              ints[i] = new Integer(i);              ints[i] = i;
135          ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE, true, Arrays.asList(ints));          Collection<Integer> elements = Arrays.asList(ints);
136            ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE, true, elements);
137          for (int i = 0; i < SIZE; ++i)          for (int i = 0; i < SIZE; ++i)
138              assertEquals(ints[i], q.poll());              assertEquals(ints[i], q.poll());
139      }      }
# Line 160  Line 171 
171      }      }
172    
173      /**      /**
      * offer(null) throws NPE  
      */  
     public void testOfferNull() {  
         try {  
             ArrayBlockingQueue q = new ArrayBlockingQueue(1);  
             q.offer(null);  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
      * add(null) throws NPE  
      */  
     public void testAddNull() {  
         try {  
             ArrayBlockingQueue q = new ArrayBlockingQueue(1);  
             q.add(null);  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
174       * Offer succeeds if not full; fails if full       * Offer succeeds if not full; fails if full
175       */       */
176      public void testOffer() {      public void testOffer() {
# Line 206  Line 195 
195      }      }
196    
197      /**      /**
      * addAll(null) throws NPE  
      */  
     public void testAddAll1() {  
         try {  
             ArrayBlockingQueue q = new ArrayBlockingQueue(1);  
             q.addAll(null);  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
198       * addAll(this) throws IAE       * addAll(this) throws IAE
199       */       */
200      public void testAddAllSelf() {      public void testAddAllSelf() {
# Line 228  Line 206 
206      }      }
207    
208      /**      /**
      * addAll of a collection with null elements throws NPE  
      */  
     public void testAddAll2() {  
         try {  
             ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);  
             Integer[] ints = new Integer[SIZE];  
             q.addAll(Arrays.asList(ints));  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
209       * addAll of a collection with any null elements throws NPE after       * addAll of a collection with any null elements throws NPE after
210       * possibly adding some elements       * possibly adding some elements
211       */       */
# Line 284  Line 250 
250      }      }
251    
252      /**      /**
      * put(null) throws NPE  
      */  
     public void testPutNull() throws InterruptedException {  
         try {  
             ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);  
             q.put(null);  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
253       * all elements successfully put are contained       * all elements successfully put are contained
254       */       */
255      public void testPut() throws InterruptedException {      public void testPut() throws InterruptedException {
# Line 674  Line 629 
629      }      }
630    
631      /**      /**
      * toArray(null) throws NullPointerException  
      */  
     public void testToArray_NullArg() {  
         ArrayBlockingQueue q = populatedQueue(SIZE);  
         try {  
             q.toArray(null);  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
632       * toArray(incompatible array type) throws ArrayStoreException       * toArray(incompatible array type) throws ArrayStoreException
633       */       */
634      public void testToArray1_BadArg() {      public void testToArray1_BadArg() {
# Line 840  Line 784 
784      }      }
785    
786      /**      /**
      * drainTo(null) throws NPE  
      */  
     public void testDrainToNull() {  
         ArrayBlockingQueue q = populatedQueue(SIZE);  
         try {  
             q.drainTo(null);  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
      * drainTo(this) throws IAE  
      */  
     public void testDrainToSelf() {  
         ArrayBlockingQueue q = populatedQueue(SIZE);  
         try {  
             q.drainTo(q);  
             shouldThrow();  
         } catch (IllegalArgumentException success) {}  
     }  
   
     /**  
787       * drainTo(c) empties queue into another collection c       * drainTo(c) empties queue into another collection c
788       */       */
789      public void testDrainTo() {      public void testDrainTo() {
# Line 906  Line 828 
828      }      }
829    
830      /**      /**
      * drainTo(null, n) throws NPE  
      */  
     public void testDrainToNullN() {  
         ArrayBlockingQueue q = populatedQueue(SIZE);  
         try {  
             q.drainTo(null, 0);  
             shouldThrow();  
         } catch (NullPointerException success) {}  
     }  
   
     /**  
      * drainTo(this, n) throws IAE  
      */  
     public void testDrainToSelfN() {  
         ArrayBlockingQueue q = populatedQueue(SIZE);  
         try {  
             q.drainTo(q, 0);  
             shouldThrow();  
         } catch (IllegalArgumentException success) {}  
     }  
   
     /**  
831       * drainTo(c, n) empties first min(n, size) elements of queue into c       * drainTo(c, n) empties first min(n, size) elements of queue into c
832       */       */
833      public void testDrainToN() {      public void testDrainToN() {

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8