4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import junit.framework.*; |
8 |
< |
import java.util.Arrays; |
7 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
> |
|
9 |
|
import java.util.ArrayList; |
10 |
+ |
import java.util.Arrays; |
11 |
|
import java.util.Collection; |
12 |
+ |
import java.util.Deque; |
13 |
|
import java.util.Iterator; |
14 |
|
import java.util.NoSuchElementException; |
15 |
|
import java.util.Queue; |
19 |
|
import java.util.concurrent.Executors; |
20 |
|
import java.util.concurrent.ExecutorService; |
21 |
|
import java.util.concurrent.LinkedBlockingDeque; |
22 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
22 |
> |
|
23 |
> |
import junit.framework.Test; |
24 |
|
|
25 |
|
public class LinkedBlockingDequeTest extends JSR166TestCase { |
26 |
|
|
47 |
|
} |
48 |
|
|
49 |
|
/** |
50 |
< |
* Creates a deque of given size containing consecutive |
50 |
> |
* Returns a new deque of given size containing consecutive |
51 |
|
* Integers 0 ... n. |
52 |
|
*/ |
53 |
|
private LinkedBlockingDeque<Integer> populatedDeque(int n) { |
1067 |
|
|
1068 |
|
pleaseInterrupt.countDown(); |
1069 |
|
try { |
1070 |
< |
q.pollFirst(SMALL_DELAY_MS, MILLISECONDS); |
1070 |
> |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
1071 |
|
shouldThrow(); |
1072 |
|
} catch (InterruptedException success) {} |
1073 |
|
assertFalse(Thread.interrupted()); |
1703 |
|
Queue x = populatedDeque(SIZE); |
1704 |
|
Queue y = serialClone(x); |
1705 |
|
|
1706 |
< |
assertTrue(x != y); |
1706 |
> |
assertNotSame(y, x); |
1707 |
|
assertEquals(x.size(), y.size()); |
1708 |
|
assertEquals(x.toString(), y.toString()); |
1709 |
|
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
1777 |
|
} |
1778 |
|
} |
1779 |
|
|
1780 |
+ |
/** |
1781 |
+ |
* remove(null), contains(null) always return false |
1782 |
+ |
*/ |
1783 |
+ |
public void testNeverContainsNull() { |
1784 |
+ |
Deque<?>[] qs = { |
1785 |
+ |
new LinkedBlockingDeque<Object>(), |
1786 |
+ |
populatedDeque(2), |
1787 |
+ |
}; |
1788 |
+ |
|
1789 |
+ |
for (Deque<?> q : qs) { |
1790 |
+ |
assertFalse(q.contains(null)); |
1791 |
+ |
assertFalse(q.remove(null)); |
1792 |
+ |
assertFalse(q.removeFirstOccurrence(null)); |
1793 |
+ |
assertFalse(q.removeLastOccurrence(null)); |
1794 |
+ |
} |
1795 |
+ |
} |
1796 |
+ |
|
1797 |
|
} |