BAEL-3840 Adjust examples based on editor feedback
This commit is contained in:
parent
83539b1b3e
commit
d1ed8af579
|
@ -3,7 +3,7 @@ package com.baeldung.suppressed;
|
|||
public class ExceptionalResource implements AutoCloseable {
|
||||
|
||||
public void processSomething() {
|
||||
throw new NullPointerException("Thrown from processSomething()");
|
||||
throw new IllegalArgumentException("Thrown from processSomething()");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.suppressed;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SuppressedExceptionsDemo {
|
||||
|
@ -9,8 +10,8 @@ public class SuppressedExceptionsDemo {
|
|||
FileInputStream fileIn = null;
|
||||
try {
|
||||
fileIn = new FileInputStream(filePath);
|
||||
} catch (IOException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
fileIn.close();
|
||||
}
|
||||
|
@ -30,6 +31,7 @@ public class SuppressedExceptionsDemo {
|
|||
if (firstException != null) {
|
||||
npe.addSuppressed(firstException);
|
||||
}
|
||||
throw npe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public class SuppressedExceptionsUnitTest {
|
|||
try {
|
||||
SuppressedExceptionsDemo.demoAddSuppressedException("/non-existent-path/non-existent-file.txt");
|
||||
} catch (Exception e) {
|
||||
assertThat(e, instanceOf(NullPointerException.class));
|
||||
assertEquals(1, e.getSuppressed().length);
|
||||
assertThat(e.getSuppressed()[0], instanceOf(FileNotFoundException.class));
|
||||
}
|
||||
|
@ -31,8 +32,10 @@ public class SuppressedExceptionsUnitTest {
|
|||
try {
|
||||
SuppressedExceptionsDemo.demoExceptionalResource();
|
||||
} catch (Exception e) {
|
||||
assertThat(e, instanceOf(IllegalArgumentException.class));
|
||||
assertEquals("Thrown from processSomething()", e.getMessage());
|
||||
assertEquals(1, e.getSuppressed().length);
|
||||
assertThat(e.getSuppressed()[0], instanceOf(NullPointerException.class));
|
||||
assertEquals("Thrown from close()", e.getSuppressed()[0].getMessage());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue