93 |
|
|
94 |
|
void emptyMeansEmpty(Collection c) throws InterruptedException { |
95 |
|
assertTrue(c.isEmpty()); |
96 |
< |
assertEquals(0, c.size()); |
97 |
< |
assertEquals("[]", c.toString()); |
96 |
> |
mustEqual(0, c.size()); |
97 |
> |
mustEqual("[]", c.toString()); |
98 |
|
if (c instanceof List<?>) { |
99 |
|
List x = (List) c; |
100 |
< |
assertEquals(1, x.hashCode()); |
101 |
< |
assertEquals(x, Collections.emptyList()); |
102 |
< |
assertEquals(Collections.emptyList(), x); |
103 |
< |
assertEquals(-1, x.indexOf(impl.makeElement(86))); |
104 |
< |
assertEquals(-1, x.lastIndexOf(impl.makeElement(99))); |
100 |
> |
mustEqual(1, x.hashCode()); |
101 |
> |
mustEqual(x, Collections.emptyList()); |
102 |
> |
mustEqual(Collections.emptyList(), x); |
103 |
> |
mustEqual(-1, x.indexOf(impl.makeElement(86))); |
104 |
> |
mustEqual(-1, x.lastIndexOf(impl.makeElement(99))); |
105 |
|
assertThrows( |
106 |
|
IndexOutOfBoundsException.class, |
107 |
|
() -> x.get(0), |
108 |
|
() -> x.set(0, impl.makeElement(42))); |
109 |
|
} |
110 |
|
else if (c instanceof Set<?>) { |
111 |
< |
assertEquals(0, c.hashCode()); |
112 |
< |
assertEquals(c, Collections.emptySet()); |
113 |
< |
assertEquals(Collections.emptySet(), c); |
111 |
> |
mustEqual(0, c.hashCode()); |
112 |
> |
mustEqual(c, Collections.emptySet()); |
113 |
> |
mustEqual(Collections.emptySet(), c); |
114 |
|
} |
115 |
|
{ |
116 |
|
Object[] a = c.toArray(); |
117 |
< |
assertEquals(0, a.length); |
117 |
> |
mustEqual(0, a.length); |
118 |
|
assertSame(Object[].class, a.getClass()); |
119 |
|
} |
120 |
|
{ |
122 |
|
assertSame(a, c.toArray(a)); |
123 |
|
} |
124 |
|
{ |
125 |
< |
Integer[] a = new Integer[0]; |
125 |
> |
Item[] a = new Item[0]; |
126 |
|
assertSame(a, c.toArray(a)); |
127 |
|
} |
128 |
|
{ |
129 |
< |
Integer[] a = { 1, 2, 3}; |
129 |
> |
Item[] a = { one, two, three}; |
130 |
|
assertSame(a, c.toArray(a)); |
131 |
|
assertNull(a[0]); |
132 |
< |
assertSame(2, a[1]); |
133 |
< |
assertSame(3, a[2]); |
132 |
> |
mustEqual(2, a[1]); |
133 |
> |
mustEqual(3, a[2]); |
134 |
|
} |
135 |
|
assertIteratorExhausted(c.iterator()); |
136 |
|
Consumer alwaysThrows = e -> { throw new AssertionError(); }; |
139 |
|
c.spliterator().forEachRemaining(alwaysThrows); |
140 |
|
assertFalse(c.spliterator().tryAdvance(alwaysThrows)); |
141 |
|
if (c.spliterator().hasCharacteristics(Spliterator.SIZED)) |
142 |
< |
assertEquals(0, c.spliterator().estimateSize()); |
142 |
> |
mustEqual(0, c.spliterator().estimateSize()); |
143 |
|
assertFalse(c.contains(bomb())); |
144 |
|
assertFalse(c.remove(bomb())); |
145 |
|
if (c instanceof Queue) { |
171 |
|
|
172 |
|
public void testNullPointerExceptions() throws InterruptedException { |
173 |
|
Collection c = impl.emptyCollection(); |
174 |
+ |
Collection nullCollection = null; |
175 |
|
assertThrows( |
176 |
|
NullPointerException.class, |
177 |
< |
() -> c.addAll(null), |
178 |
< |
() -> c.containsAll(null), |
179 |
< |
() -> c.retainAll(null), |
180 |
< |
() -> c.removeAll(null), |
177 |
> |
() -> c.addAll(nullCollection), |
178 |
> |
() -> c.containsAll(nullCollection), |
179 |
> |
() -> c.retainAll(nullCollection), |
180 |
> |
() -> c.removeAll(nullCollection), |
181 |
|
() -> c.removeIf(null), |
182 |
|
() -> c.forEach(null), |
183 |
|
() -> c.iterator().forEachRemaining(null), |
293 |
|
try { |
294 |
|
boolean modified = c.removeIf(randomPredicate); |
295 |
|
assertNull(threwAt.get()); |
296 |
< |
assertEquals(modified, accepts.size() > 0); |
297 |
< |
assertEquals(modified, rejects.size() != n); |
298 |
< |
assertEquals(accepts.size() + rejects.size(), n); |
296 |
> |
mustEqual(modified, accepts.size() > 0); |
297 |
> |
mustEqual(modified, rejects.size() != n); |
298 |
> |
mustEqual(accepts.size() + rejects.size(), n); |
299 |
|
if (ordered) { |
300 |
< |
assertEquals(rejects, |
300 |
> |
mustEqual(rejects, |
301 |
|
Arrays.asList(c.toArray())); |
302 |
|
} else { |
303 |
< |
assertEquals(new HashSet(rejects), |
303 |
> |
mustEqual(new HashSet(rejects), |
304 |
|
new HashSet(Arrays.asList(c.toArray()))); |
305 |
|
} |
306 |
|
} catch (ArithmeticException ok) { |
324 |
|
assertTrue(c.containsAll(survivors)); |
325 |
|
assertTrue(survivors.containsAll(rejects)); |
326 |
|
if (threwAt.get() == null) { |
327 |
< |
assertEquals(n - accepts.size(), c.size()); |
327 |
> |
mustEqual(n - accepts.size(), c.size()); |
328 |
|
for (Object x : accepts) assertFalse(c.contains(x)); |
329 |
|
} else { |
330 |
|
// Two acceptable behaviors: entire removeIf call is one |
487 |
|
if (c instanceof List || c instanceof Deque) |
488 |
|
assertTrue(ordered); |
489 |
|
HashSet cset = new HashSet(c); |
490 |
< |
assertEquals(cset, new HashSet(parallelStreamForEached)); |
490 |
> |
mustEqual(cset, new HashSet(parallelStreamForEached)); |
491 |
|
if (ordered) { |
492 |
< |
assertEquals(iterated, iteratedForEachRemaining); |
493 |
< |
assertEquals(iterated, tryAdvanced); |
494 |
< |
assertEquals(iterated, spliterated); |
495 |
< |
assertEquals(iterated, splitonced); |
496 |
< |
assertEquals(iterated, forEached); |
497 |
< |
assertEquals(iterated, streamForEached); |
498 |
< |
assertEquals(iterated, removeIfed); |
492 |
> |
mustEqual(iterated, iteratedForEachRemaining); |
493 |
> |
mustEqual(iterated, tryAdvanced); |
494 |
> |
mustEqual(iterated, spliterated); |
495 |
> |
mustEqual(iterated, splitonced); |
496 |
> |
mustEqual(iterated, forEached); |
497 |
> |
mustEqual(iterated, streamForEached); |
498 |
> |
mustEqual(iterated, removeIfed); |
499 |
|
} else { |
500 |
< |
assertEquals(cset, new HashSet(iterated)); |
501 |
< |
assertEquals(cset, new HashSet(iteratedForEachRemaining)); |
502 |
< |
assertEquals(cset, new HashSet(tryAdvanced)); |
503 |
< |
assertEquals(cset, new HashSet(spliterated)); |
504 |
< |
assertEquals(cset, new HashSet(splitonced)); |
505 |
< |
assertEquals(cset, new HashSet(forEached)); |
506 |
< |
assertEquals(cset, new HashSet(streamForEached)); |
507 |
< |
assertEquals(cset, new HashSet(removeIfed)); |
500 |
> |
mustEqual(cset, new HashSet(iterated)); |
501 |
> |
mustEqual(cset, new HashSet(iteratedForEachRemaining)); |
502 |
> |
mustEqual(cset, new HashSet(tryAdvanced)); |
503 |
> |
mustEqual(cset, new HashSet(spliterated)); |
504 |
> |
mustEqual(cset, new HashSet(splitonced)); |
505 |
> |
mustEqual(cset, new HashSet(forEached)); |
506 |
> |
mustEqual(cset, new HashSet(streamForEached)); |
507 |
> |
mustEqual(cset, new HashSet(removeIfed)); |
508 |
|
} |
509 |
|
if (c instanceof Deque) { |
510 |
|
Deque d = (Deque) c; |
516 |
|
e -> descendingForEachRemaining.add(e)); |
517 |
|
Collections.reverse(descending); |
518 |
|
Collections.reverse(descendingForEachRemaining); |
519 |
< |
assertEquals(iterated, descending); |
520 |
< |
assertEquals(iterated, descendingForEachRemaining); |
519 |
> |
mustEqual(iterated, descending); |
520 |
> |
mustEqual(iterated, descendingForEachRemaining); |
521 |
|
} |
522 |
|
} |
523 |
|
|
555 |
|
r2 = ConcurrentModificationException.class; |
556 |
|
assertFalse(impl.isConcurrent()); |
557 |
|
} |
558 |
< |
assertEquals(r1, r2); |
558 |
> |
mustEqual(r1, r2); |
559 |
|
} |
560 |
|
|
561 |
|
/** |
577 |
|
Iterator it = c.iterator(); |
578 |
|
if (ordered) { |
579 |
|
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
580 |
< |
assertEquals(impl.makeElement(0), it.next()); |
580 |
> |
mustEqual(impl.makeElement(0), it.next()); |
581 |
|
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
582 |
< |
assertEquals(impl.makeElement(1), it.next()); |
582 |
> |
mustEqual(impl.makeElement(1), it.next()); |
583 |
|
} else { |
584 |
|
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
585 |
|
assertTrue(copy.contains(it.next())); |
599 |
|
catch (UnsupportedOperationException ok) { |
600 |
|
break testCollection; |
601 |
|
} |
602 |
< |
assertEquals(n - 1, c.size()); |
602 |
> |
mustEqual(n - 1, c.size()); |
603 |
|
if (ordered) { |
604 |
|
for (int i = 0; i < n - 1; i++) |
605 |
|
assertTrue(c.contains(impl.makeElement(i))); |
615 |
|
for (int i = 0; i < n; i++) d.add(impl.makeElement(i)); |
616 |
|
Iterator it = d.descendingIterator(); |
617 |
|
assertTrue(it.hasNext()); |
618 |
< |
assertEquals(impl.makeElement(n - 1), it.next()); |
618 |
> |
mustEqual(impl.makeElement(n - 1), it.next()); |
619 |
|
assertTrue(it.hasNext()); |
620 |
< |
assertEquals(impl.makeElement(n - 2), it.next()); |
620 |
> |
mustEqual(impl.makeElement(n - 2), it.next()); |
621 |
|
it.forEachRemaining(e -> assertTrue(c.contains(e))); |
622 |
|
if (testImplementationDetails) { |
623 |
|
it.remove(); |
624 |
< |
assertEquals(n - 1, d.size()); |
624 |
> |
mustEqual(n - 1, d.size()); |
625 |
|
for (int i = 1; i < n; i++) |
626 |
|
assertTrue(d.contains(impl.makeElement(i))); |
627 |
|
assertFalse(d.contains(impl.makeElement(0))); |
643 |
|
|
644 |
|
assertTrue(c.add(x)); |
645 |
|
c.stream().forEach(spy); |
646 |
< |
assertEquals(Collections.singletonList(x), found); |
646 |
> |
mustEqual(Collections.singletonList(x), found); |
647 |
|
found.clear(); |
648 |
|
|
649 |
|
assertTrue(c.add(y)); |
650 |
|
c.stream().forEach(spy); |
651 |
< |
assertEquals(2, found.size()); |
651 |
> |
mustEqual(2, found.size()); |
652 |
|
assertTrue(found.contains(x)); |
653 |
|
assertTrue(found.contains(y)); |
654 |
|
found.clear(); |
700 |
|
|
701 |
|
assertTrue(c.add(x)); |
702 |
|
c.forEach(spy); |
703 |
< |
assertEquals(Collections.singletonList(x), found); |
703 |
> |
mustEqual(Collections.singletonList(x), found); |
704 |
|
found.clear(); |
705 |
|
|
706 |
|
assertTrue(c.add(y)); |
707 |
|
c.forEach(spy); |
708 |
< |
assertEquals(2, found.size()); |
708 |
> |
mustEqual(2, found.size()); |
709 |
|
assertTrue(found.contains(x)); |
710 |
|
assertTrue(found.contains(y)); |
711 |
|
found.clear(); |
879 |
|
c.add(one); |
880 |
|
split.forEachRemaining( |
881 |
|
e -> { assertSame(e, one); count.getAndIncrement(); }); |
882 |
< |
assertEquals(1L, count.get()); |
882 |
> |
mustEqual(1L, count.get()); |
883 |
|
assertFalse(split.tryAdvance(e -> { throw new AssertionError(); })); |
884 |
|
assertTrue(c.contains(one)); |
885 |
|
} |
906 |
|
Collection c = impl.emptyCollection(); |
907 |
|
for (int n = rnd.nextInt(4); n--> 0; ) |
908 |
|
c.add(impl.makeElement(rnd.nextInt())); |
909 |
< |
assertEquals(c, c); |
909 |
> |
mustEqual(c, c); |
910 |
|
if (c instanceof List) |
911 |
|
assertCollectionsEquals(c, new ArrayList(c)); |
912 |
|
else if (c instanceof Set) |
942 |
|
int size = list.size(), half = size / 2; |
943 |
|
Iterator it = list.iterator(); |
944 |
|
for (int i = 0; i < half; i++) |
945 |
< |
assertEquals(it.next(), copy.get(i)); |
945 |
> |
mustEqual(it.next(), copy.get(i)); |
946 |
|
list.replaceAll(n -> n); |
947 |
|
// ConcurrentModificationException must not be thrown here. |
948 |
|
for (int i = half; i < size; i++) |
949 |
< |
assertEquals(it.next(), copy.get(i)); |
949 |
> |
mustEqual(it.next(), copy.get(i)); |
950 |
|
} |
951 |
|
|
952 |
|
// public void testCollection8DebugFail() { |