< prev index next >
test/java/util/Arrays/StreamAndSpliterator.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -30,11 +30,13 @@
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Spliterators;
-import static org.testng.Assert.assertNotNull;
+import org.testng.Assert.ThrowingRunnable;
+
+import static org.testng.Assert.assertThrows;
public class StreamAndSpliterator {
@Test
public void testStreamNPEs() {
assertThrowsNPE(() -> Arrays.stream((int[]) null, 0, 0));
@@ -122,27 +124,13 @@
assertThrowsAIOOB(() -> Spliterators.spliterator(new long[]{}, 0, 1, 0));
assertThrowsAIOOB(() -> Spliterators.spliterator(new double[]{}, 0, 1, 0));
assertThrowsAIOOB(() -> Spliterators.spliterator(new String[]{}, 0, 1, 0));
}
- void assertThrowsNPE(Runnable r) {
- NullPointerException caught = null;
- try {
- r.run();
- }
- catch (NullPointerException e) {
- caught = e;
- }
- assertNotNull(caught, "NullPointerException not thrown");
+ void assertThrowsNPE(ThrowingRunnable r) {
+ assertThrows(NullPointerException.class, r);
}
- void assertThrowsAIOOB(Runnable r) {
- ArrayIndexOutOfBoundsException caught = null;
- try {
- r.run();
- }
- catch (ArrayIndexOutOfBoundsException e) {
- caught = e;
- }
- assertNotNull(caught, "ArrayIndexOutOfBoundsException not thrown");
+ void assertThrowsAIOOB(ThrowingRunnable r) {
+ assertThrows(ArrayIndexOutOfBoundsException.class, r);
}
}
< prev index next >