49 |
|
impl); |
50 |
|
} |
51 |
|
|
52 |
+ |
Object bomb() { |
53 |
+ |
return new Object() { |
54 |
+ |
public boolean equals(Object x) { throw new AssertionError(); } |
55 |
+ |
public int hashCode() { throw new AssertionError(); } |
56 |
+ |
}; |
57 |
+ |
} |
58 |
+ |
|
59 |
|
/** Checks properties of empty collections. */ |
60 |
|
public void testEmptyMeansEmpty() { |
61 |
|
Collection c = impl.emptyCollection(); |
62 |
+ |
emptyMeansEmpty(c); |
63 |
+ |
|
64 |
+ |
if (c instanceof java.io.Serializable) |
65 |
+ |
emptyMeansEmpty(serialClone(c)); |
66 |
+ |
|
67 |
+ |
Collection clone = cloneableClone(c); |
68 |
+ |
if (clone != null) |
69 |
+ |
emptyMeansEmpty(clone); |
70 |
+ |
} |
71 |
+ |
|
72 |
+ |
void emptyMeansEmpty(Collection c) { |
73 |
|
assertTrue(c.isEmpty()); |
74 |
|
assertEquals(0, c.size()); |
75 |
|
assertEquals("[]", c.toString()); |
99 |
|
c.iterator().forEachRemaining(alwaysThrows); |
100 |
|
c.spliterator().forEachRemaining(alwaysThrows); |
101 |
|
assertFalse(c.spliterator().tryAdvance(alwaysThrows)); |
102 |
< |
if (Queue.class.isAssignableFrom(impl.klazz())) { |
102 |
> |
if (c.spliterator().hasCharacteristics(Spliterator.SIZED)) |
103 |
> |
assertEquals(0, c.spliterator().estimateSize()); |
104 |
> |
assertFalse(c.contains(bomb())); |
105 |
> |
assertFalse(c.remove(bomb())); |
106 |
> |
if (c instanceof Queue) { |
107 |
|
Queue q = (Queue) c; |
108 |
|
assertNull(q.peek()); |
109 |
|
assertNull(q.poll()); |
110 |
|
} |
111 |
< |
if (Deque.class.isAssignableFrom(impl.klazz())) { |
111 |
> |
if (c instanceof Deque) { |
112 |
|
Deque d = (Deque) c; |
113 |
|
assertNull(d.peekFirst()); |
114 |
|
assertNull(d.peekLast()); |
115 |
|
assertNull(d.pollFirst()); |
116 |
|
assertNull(d.pollLast()); |
117 |
|
assertIteratorExhausted(d.descendingIterator()); |
118 |
+ |
d.descendingIterator().forEachRemaining(alwaysThrows); |
119 |
+ |
assertFalse(d.removeFirstOccurrence(bomb())); |
120 |
+ |
assertFalse(d.removeLastOccurrence(bomb())); |
121 |
|
} |
122 |
|
} |
123 |
|
|