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

Comparing jsr166/src/test/tck/Collection8Test.java (file contents):
Revision 1.13 by jsr166, Sat Nov 5 19:56:46 2016 UTC vs.
Revision 1.17 by jsr166, Sun Nov 6 18:51:53 2016 UTC

# Line 5 | Line 5
5   * http://creativecommons.org/publicdomain/zero/1.0/
6   */
7  
8 + import static java.util.concurrent.TimeUnit.HOURS;
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10  
11   import java.util.ArrayList;
# Line 17 | Line 18 | import java.util.List;
18   import java.util.NoSuchElementException;
19   import java.util.Queue;
20   import java.util.Spliterator;
21 + import java.util.concurrent.BlockingDeque;
22 + import java.util.concurrent.BlockingQueue;
23   import java.util.concurrent.CountDownLatch;
24   import java.util.concurrent.Executors;
25   import java.util.concurrent.ExecutorService;
# Line 57 | Line 60 | public class Collection8Test extends JSR
60      }
61  
62      /** Checks properties of empty collections. */
63 <    public void testEmptyMeansEmpty() {
63 >    public void testEmptyMeansEmpty() throws InterruptedException {
64          Collection c = impl.emptyCollection();
65          emptyMeansEmpty(c);
66  
# Line 69 | Line 72 | public class Collection8Test extends JSR
72              emptyMeansEmpty(clone);
73      }
74  
75 <    void emptyMeansEmpty(Collection c) {
75 >    void emptyMeansEmpty(Collection c) throws InterruptedException {
76          assertTrue(c.isEmpty());
77          assertEquals(0, c.size());
78          assertEquals("[]", c.toString());
# Line 119 | Line 122 | public class Collection8Test extends JSR
122              assertFalse(d.removeFirstOccurrence(bomb()));
123              assertFalse(d.removeLastOccurrence(bomb()));
124          }
125 +        if (c instanceof BlockingQueue) {
126 +            BlockingQueue q = (BlockingQueue) c;
127 +            assertNull(q.poll(0L, MILLISECONDS));
128 +        }
129 +        if (c instanceof BlockingDeque) {
130 +            BlockingDeque q = (BlockingDeque) c;
131 +            assertNull(q.pollFirst(0L, MILLISECONDS));
132 +            assertNull(q.pollLast(0L, MILLISECONDS));
133 +        }
134      }
135  
136 <    public void testNullPointerExceptions() {
136 >    public void testNullPointerExceptions() throws InterruptedException {
137          Collection c = impl.emptyCollection();
138          assertThrows(
139              NullPointerException.class,
# Line 141 | Line 153 | public class Collection8Test extends JSR
153                  NullPointerException.class,
154                  () -> c.add(null));
155          }
156 <        if (!impl.permitsNulls()
145 <            && Queue.class.isAssignableFrom(impl.klazz())) {
156 >        if (!impl.permitsNulls() && c instanceof Queue) {
157              Queue q = (Queue) c;
158              assertThrows(
159                  NullPointerException.class,
160                  () -> q.offer(null));
161          }
162 <        if (!impl.permitsNulls()
152 <            && Deque.class.isAssignableFrom(impl.klazz())) {
162 >        if (!impl.permitsNulls() && c instanceof Deque) {
163              Deque d = (Deque) c;
164              assertThrows(
165                  NullPointerException.class,
# Line 160 | Line 170 | public class Collection8Test extends JSR
170                  () -> d.push(null),
171                  () -> d.descendingIterator().forEachRemaining(null));
172          }
173 +        if (c instanceof BlockingQueue) {
174 +            BlockingQueue q = (BlockingQueue) c;
175 +            assertThrows(
176 +                NullPointerException.class,
177 +                () -> {
178 +                    try { q.offer(null, 1L, HOURS); }
179 +                    catch (InterruptedException ex) {
180 +                        throw new AssertionError(ex);
181 +                    }},
182 +                () -> {
183 +                    try { q.put(null); }
184 +                    catch (InterruptedException ex) {
185 +                        throw new AssertionError(ex);
186 +                    }});
187 +        }
188 +        if (c instanceof BlockingDeque) {
189 +            BlockingDeque q = (BlockingDeque) c;
190 +            assertThrows(
191 +                NullPointerException.class,
192 +                () -> {
193 +                    try { q.offerFirst(null, 1L, HOURS); }
194 +                    catch (InterruptedException ex) {
195 +                        throw new AssertionError(ex);
196 +                    }},
197 +                () -> {
198 +                    try { q.offerLast(null, 1L, HOURS); }
199 +                    catch (InterruptedException ex) {
200 +                        throw new AssertionError(ex);
201 +                    }},
202 +                () -> {
203 +                    try { q.putFirst(null); }
204 +                    catch (InterruptedException ex) {
205 +                        throw new AssertionError(ex);
206 +                    }},
207 +                () -> {
208 +                    try { q.putLast(null); }
209 +                    catch (InterruptedException ex) {
210 +                        throw new AssertionError(ex);
211 +                    }});
212 +        }
213      }
214  
215      public void testNoSuchElementExceptions() {
# Line 168 | Line 218 | public class Collection8Test extends JSR
218              NoSuchElementException.class,
219              () -> c.iterator().next());
220  
221 <        if (Queue.class.isAssignableFrom(impl.klazz())) {
221 >        if (c instanceof Queue) {
222              Queue q = (Queue) c;
223              assertThrows(
224                  NoSuchElementException.class,
225                  () -> q.element(),
226                  () -> q.remove());
227          }
228 <        if (Deque.class.isAssignableFrom(impl.klazz())) {
228 >        if (c instanceof Deque) {
229              Deque d = (Deque) c;
230              assertThrows(
231                  NoSuchElementException.class,
# Line 207 | Line 257 | public class Collection8Test extends JSR
257              }
258          };
259          try {
210            assertFalse(survivors.contains(null));
260              try {
261                  boolean modified = c.removeIf(randomPredicate);
262                  if (!modified) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines