9 |
|
import junit.framework.*; |
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; |
27 |
|
} |
28 |
|
|
29 |
|
/** |
30 |
< |
* Create a deque of given size containing consecutive |
30 |
> |
* Returns a new deque of given size containing consecutive |
31 |
|
* Integers 0 ... n. |
32 |
|
*/ |
33 |
|
private ConcurrentLinkedDeque<Integer> populatedDeque(int n) { |
851 |
|
Queue x = populatedDeque(SIZE); |
852 |
|
Queue y = serialClone(x); |
853 |
|
|
854 |
< |
assertTrue(x != y); |
854 |
> |
assertNotSame(x, y); |
855 |
|
assertEquals(x.size(), y.size()); |
856 |
|
assertEquals(x.toString(), y.toString()); |
857 |
|
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
862 |
|
assertTrue(y.isEmpty()); |
863 |
|
} |
864 |
|
|
865 |
+ |
/** |
866 |
+ |
* contains(null) always return false. |
867 |
+ |
* remove(null) always throws NullPointerException. |
868 |
+ |
*/ |
869 |
+ |
public void testNeverContainsNull() { |
870 |
+ |
Deque<?>[] qs = { |
871 |
+ |
new ConcurrentLinkedDeque<Object>(), |
872 |
+ |
populatedDeque(2), |
873 |
+ |
}; |
874 |
+ |
|
875 |
+ |
for (Deque<?> q : qs) { |
876 |
+ |
assertFalse(q.contains(null)); |
877 |
+ |
try { |
878 |
+ |
assertFalse(q.remove(null)); |
879 |
+ |
shouldThrow(); |
880 |
+ |
} catch (NullPointerException success) {} |
881 |
+ |
try { |
882 |
+ |
assertFalse(q.removeFirstOccurrence(null)); |
883 |
+ |
shouldThrow(); |
884 |
+ |
} catch (NullPointerException success) {} |
885 |
+ |
try { |
886 |
+ |
assertFalse(q.removeLastOccurrence(null)); |
887 |
+ |
shouldThrow(); |
888 |
+ |
} catch (NullPointerException success) {} |
889 |
+ |
} |
890 |
+ |
} |
891 |
|
} |