You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2020/08/05 12:24:04 UTC
[commons-io] branch master updated: Simplify by using assertThrows
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 382e480 Simplify by using assertThrows
382e480 is described below
commit 382e48042f384cde9af5cdfc63e898ca46aaba1f
Author: Sebb <se...@apache.org>
AuthorDate: Wed Aug 5 13:23:55 2020 +0100
Simplify by using assertThrows
---
.../org/apache/commons/io/IOUtilsTestCase.java | 91 ++++------------------
1 file changed, 13 insertions(+), 78 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
index 4dfc9c8..c02b2e7 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -1247,32 +1247,12 @@ public class IOUtilsTestCase {
() -> IOUtils.resourceToString("non-existing-file.bin", StandardCharsets.UTF_8, ClassLoader.getSystemClassLoader()));
}
- @Test public void testResourceToString_NullResource() throws Exception {
- boolean exceptionOccurred = false;
-
- try {
- IOUtils.resourceToString(null, StandardCharsets.UTF_8);
- fail();
- } catch (final NullPointerException npe) {
- exceptionOccurred = true;
- assertNotNull(npe);
- }
-
- assertTrue(exceptionOccurred);
+ @Test public void testResourceToString_NullResource() {
+ assertThrows(NullPointerException.class, () -> IOUtils.resourceToString(null, StandardCharsets.UTF_8));
}
- @Test public void testResourceToString_NullResource_WithClassLoader() throws Exception {
- boolean exceptionOccurred = false;
-
- try {
- IOUtils.resourceToString(null, StandardCharsets.UTF_8, ClassLoader.getSystemClassLoader());
- fail();
- } catch (final NullPointerException npe) {
- exceptionOccurred = true;
- assertNotNull(npe);
- }
-
- assertTrue(exceptionOccurred);
+ @Test public void testResourceToString_NullResource_WithClassLoader() {
+ assertThrows(NullPointerException.class, () -> IOUtils.resourceToString(null, StandardCharsets.UTF_8, ClassLoader.getSystemClassLoader()));
}
@SuppressWarnings("squid:S2699") // Suppress "Add at least one assertion to this test case"
@@ -1322,32 +1302,12 @@ public class IOUtilsTestCase {
() -> IOUtils.resourceToByteArray("non-existing-file.bin", ClassLoader.getSystemClassLoader()));
}
- @Test public void testResourceToByteArray_Null() throws Exception {
- boolean exceptionOccurred = false;
-
- try {
- IOUtils.resourceToByteArray(null);
- fail();
- } catch (final NullPointerException npe) {
- exceptionOccurred = true;
- assertNotNull(npe);
- }
-
- assertTrue(exceptionOccurred);
+ @Test public void testResourceToByteArray_Null() {
+ assertThrows(NullPointerException.class, () -> IOUtils.resourceToByteArray(null));
}
- @Test public void testResourceToByteArray_Null_WithClassLoader() throws Exception {
- boolean exceptionOccurred = false;
-
- try {
- IOUtils.resourceToByteArray(null, ClassLoader.getSystemClassLoader());
- fail();
- } catch (final NullPointerException npe) {
- exceptionOccurred = true;
- assertNotNull(npe);
- }
-
- assertTrue(exceptionOccurred);
+ @Test public void testResourceToByteArray_Null_WithClassLoader() {
+ assertThrows(NullPointerException.class, () -> IOUtils.resourceToByteArray(null, ClassLoader.getSystemClassLoader()));
}
@Test public void testResourceToURL_ExistingResourceAtRootPackage() throws Exception {
@@ -1387,32 +1347,12 @@ public class IOUtilsTestCase {
() -> IOUtils.resourceToURL("non-existing-file.bin", ClassLoader.getSystemClassLoader()));
}
- @Test public void testResourceToURL_Null() throws Exception {
- boolean exceptionOccurred = false;
-
- try {
- IOUtils.resourceToURL(null);
- fail();
- } catch (final NullPointerException npe) {
- exceptionOccurred = true;
- assertNotNull(npe);
- }
-
- assertTrue(exceptionOccurred);
+ @Test public void testResourceToURL_Null() {
+ assertThrows(NullPointerException.class, () -> IOUtils.resourceToURL(null));
}
- @Test public void testResourceToURL_Null_WithClassLoader() throws Exception {
- boolean exceptionOccurred = false;
-
- try {
- IOUtils.resourceToURL(null, ClassLoader.getSystemClassLoader());
- fail();
- } catch (final NullPointerException npe) {
- exceptionOccurred = true;
- assertNotNull(npe);
- }
-
- assertTrue(exceptionOccurred);
+ @Test public void testResourceToURL_Null_WithClassLoader() {
+ assertThrows(NullPointerException.class, () -> IOUtils.resourceToURL(null, ClassLoader.getSystemClassLoader()));
}
@Test public void testAsBufferedNull() {
@@ -1559,12 +1499,7 @@ public class IOUtilsTestCase {
@Test
public void testAsWriterNull() {
- try {
- IOUtils.writer(null);
- fail("Expected NullPointerException");
- } catch (final NullPointerException npe) {
- // expected
- }
+ assertThrows(NullPointerException.class, () -> IOUtils.writer(null));
}
@Test