7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
+ |
import java.util.Arrays; |
11 |
+ |
import java.util.NoSuchElementException; |
12 |
|
import java.util.PropertyPermission; |
13 |
|
import java.util.concurrent.*; |
14 |
|
import java.util.concurrent.atomic.AtomicReference; |
1009 |
|
} |
1010 |
|
} |
1011 |
|
|
1012 |
+ |
public void checkEmpty(BlockingQueue q) { |
1013 |
+ |
try { |
1014 |
+ |
assertTrue(q.isEmpty()); |
1015 |
+ |
assertEquals(0, q.size()); |
1016 |
+ |
assertNull(q.peek()); |
1017 |
+ |
assertNull(q.poll()); |
1018 |
+ |
assertNull(q.poll(0, MILLISECONDS)); |
1019 |
+ |
assertEquals(q.toString(), "[]"); |
1020 |
+ |
assertTrue(Arrays.equals(q.toArray(), new Object[0])); |
1021 |
+ |
assertFalse(q.iterator().hasNext()); |
1022 |
+ |
try { |
1023 |
+ |
q.element(); |
1024 |
+ |
shouldThrow(); |
1025 |
+ |
} catch (NoSuchElementException success) {} |
1026 |
+ |
try { |
1027 |
+ |
q.iterator().next(); |
1028 |
+ |
shouldThrow(); |
1029 |
+ |
} catch (NoSuchElementException success) {} |
1030 |
+ |
try { |
1031 |
+ |
q.remove(); |
1032 |
+ |
shouldThrow(); |
1033 |
+ |
} catch (NoSuchElementException success) {} |
1034 |
+ |
} catch (InterruptedException ie) { |
1035 |
+ |
threadUnexpectedException(ie); |
1036 |
+ |
} |
1037 |
+ |
} |
1038 |
+ |
|
1039 |
|
} |