aboutsummaryrefslogtreecommitdiffstats
path: root/yolean/src/test/java/com
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@oath.com>2018-11-25 21:17:14 +0100
committerHåkon Hallingstad <hakon@oath.com>2018-11-25 21:17:14 +0100
commit660d28ed2ac5cd98acef4fae8e7b22a92cbdbc13 (patch)
treef62f27f6b461a96229c0f84ac78e315fa9c2a9b2 /yolean/src/test/java/com
parenta01bc21d9bcbc417a9fb2591079561f59f76865e (diff)
Ignore NoSuchFileException with ifExists
Diffstat (limited to 'yolean/src/test/java/com')
-rw-r--r--yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java b/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
index 31e27fa2675..e1786528b31 100644
--- a/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
+++ b/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
@@ -5,8 +5,10 @@ import org.junit.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
+import java.nio.file.NoSuchFileException;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
/**
* @author bratseth
@@ -27,35 +29,38 @@ public class ExceptionsTestCase {
@Test
public void testUnchecks() {
try {
- Exceptions.uncheck(this::throwIO);
+ Exceptions.uncheck(this::throwNoSuchFileException);
} catch (UncheckedIOException e) {
assertEquals("root cause", e.getCause().getMessage());
}
try {
- Exceptions.uncheck(this::throwIO, "additional %s", "info");
+ Exceptions.uncheck(this::throwNoSuchFileException, "additional %s", "info");
} catch (UncheckedIOException e) {
assertEquals("additional info", e.getMessage());
}
try {
- int i = Exceptions.uncheck(this::throwIOWithReturnValue);
+ int i = Exceptions.uncheck(this::throwNoSuchFileExceptionSupplier);
} catch (UncheckedIOException e) {
assertEquals("root cause", e.getCause().getMessage());
}
try {
- int i = Exceptions.uncheck(this::throwIOWithReturnValue, "additional %s", "info");
+ int i = Exceptions.uncheck(this::throwNoSuchFileExceptionSupplier, "additional %s", "info");
} catch (UncheckedIOException e) {
assertEquals("additional info", e.getMessage());
}
+
+ Exceptions.ifExists(this::throwNoSuchFileException);
+ assertFalse(Exceptions.ifExists(this::throwNoSuchFileExceptionSupplier).isPresent());
}
- private void throwIO() throws IOException {
- throw new IOException("root cause");
+ private void throwNoSuchFileException() throws IOException {
+ throw new NoSuchFileException("root cause");
}
- private int throwIOWithReturnValue() throws IOException {
- throw new IOException("root cause");
+ private int throwNoSuchFileExceptionSupplier() throws IOException {
+ throw new NoSuchFileException("root cause");
}
}