< prev index next >
test/java/util/stream/bootlib/java.base/java/util/SpliteratorTestHelper.java
Print this page
*** 24,35 ****
import java.util.function.*;
import java.util.stream.LambdaTestHelpers;
import static org.testng.Assert.*;
- import static org.testng.Assert.assertEquals;
- import static org.testng.Assert.fail;
/**
* Assertion methods for spliterators, to be called from other tests
*/
public class SpliteratorTestHelper {
--- 24,33 ----
*** 222,247 ****
S sp = s.get();
// Have to check instances and use casts to avoid tripwire messages and
// directly test the primitive methods
if (sp instanceof Spliterator.OfInt) {
Spliterator.OfInt psp = (Spliterator.OfInt) sp;
! executeAndCatch(NullPointerException.class, () -> psp.forEachRemaining((IntConsumer) null));
! executeAndCatch(NullPointerException.class, () -> psp.tryAdvance((IntConsumer) null));
}
else if (sp instanceof Spliterator.OfLong) {
Spliterator.OfLong psp = (Spliterator.OfLong) sp;
! executeAndCatch(NullPointerException.class, () -> psp.forEachRemaining((LongConsumer) null));
! executeAndCatch(NullPointerException.class, () -> psp.tryAdvance((LongConsumer) null));
}
else if (sp instanceof Spliterator.OfDouble) {
Spliterator.OfDouble psp = (Spliterator.OfDouble) sp;
! executeAndCatch(NullPointerException.class, () -> psp.forEachRemaining((DoubleConsumer) null));
! executeAndCatch(NullPointerException.class, () -> psp.tryAdvance((DoubleConsumer) null));
}
else {
! executeAndCatch(NullPointerException.class, () -> sp.forEachRemaining(null));
! executeAndCatch(NullPointerException.class, () -> sp.tryAdvance(null));
}
}
private static <T, S extends Spliterator<T>> void testForEach(
Collection<T> exp,
--- 220,245 ----
S sp = s.get();
// Have to check instances and use casts to avoid tripwire messages and
// directly test the primitive methods
if (sp instanceof Spliterator.OfInt) {
Spliterator.OfInt psp = (Spliterator.OfInt) sp;
! assertThrowsNPE(() -> psp.forEachRemaining((IntConsumer) null));
! assertThrowsNPE(() -> psp.tryAdvance((IntConsumer) null));
}
else if (sp instanceof Spliterator.OfLong) {
Spliterator.OfLong psp = (Spliterator.OfLong) sp;
! assertThrowsNPE(() -> psp.forEachRemaining((LongConsumer) null));
! assertThrowsNPE(() -> psp.tryAdvance((LongConsumer) null));
}
else if (sp instanceof Spliterator.OfDouble) {
Spliterator.OfDouble psp = (Spliterator.OfDouble) sp;
! assertThrowsNPE(() -> psp.forEachRemaining((DoubleConsumer) null));
! assertThrowsNPE(() -> psp.tryAdvance((DoubleConsumer) null));
}
else {
! assertThrowsNPE(() -> sp.forEachRemaining(null));
! assertThrowsNPE(() -> sp.tryAdvance(null));
}
}
private static <T, S extends Spliterator<T>> void testForEach(
Collection<T> exp,
*** 651,675 ****
else {
LambdaTestHelpers.assertContentsUnordered(actual, expected);
}
}
! public static void executeAndCatch(Class<? extends Exception> expected, Runnable r) {
! Exception caught = null;
! try {
! r.run();
! }
! catch (Exception e) {
! caught = e;
! }
!
! assertNotNull(caught,
! String.format("No Exception was thrown, expected an Exception of %s to be thrown",
! expected.getName()));
! assertTrue(expected.isInstance(caught),
! String.format("Exception thrown %s not an instance of %s",
! caught.getClass().getName(), expected.getName()));
}
public static<U> void mixedTraverseAndSplit(Consumer<U> b, Spliterator<U> splTop) {
Spliterator<U> spl1, spl2, spl3;
splTop.tryAdvance(b);
--- 649,660 ----
else {
LambdaTestHelpers.assertContentsUnordered(actual, expected);
}
}
! public static void assertThrowsNPE(ThrowingRunnable r) {
! assertThrows(NullPointerException.class, r);
}
public static<U> void mixedTraverseAndSplit(Consumer<U> b, Spliterator<U> splTop) {
Spliterator<U> spl1, spl2, spl3;
splTop.tryAdvance(b);
< prev index next >