summaryrefslogtreecommitdiffstats
path: root/yolean/src/test
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@oath.com>2018-12-07 15:33:17 +0100
committerValerij Fredriksen <valerijf@oath.com>2018-12-07 15:33:17 +0100
commit5f848c88c26cb41c01e3338a46f383a61d89a969 (patch)
tree3fbcc6acfe996edb0a1241c29b5d435a5b0ee70c /yolean/src/test
parentce1b30a518593155aad5e233ef40f068e23a93de (diff)
Add Exceptions.findCause()
Diffstat (limited to 'yolean/src/test')
-rw-r--r--yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java b/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
index 390018efdf7..cd06d14bb55 100644
--- a/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
+++ b/yolean/src/test/java/com/yahoo/yolean/ExceptionsTestCase.java
@@ -6,6 +6,7 @@ import org.junit.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.NoSuchFileException;
+import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -17,6 +18,19 @@ import static org.junit.Assert.assertNull;
public class ExceptionsTestCase {
@Test
+ public void testFindCause() {
+ IllegalArgumentException e1 = new IllegalArgumentException();
+ IllegalStateException e2 = new IllegalStateException(e1);
+ RuntimeException e3 = new RuntimeException(e2);
+
+ assertEquals(Optional.of(e3), Exceptions.findCause(e3, RuntimeException.class));
+ assertEquals(Optional.of(e1), Exceptions.findCause(e3, IllegalArgumentException.class));
+ assertEquals(Optional.empty(), Exceptions.findCause(e3, NumberFormatException.class));
+
+ assertEquals(Optional.of(e2), Exceptions.findCause(e2, RuntimeException.class));
+ }
+
+ @Test
public void testToMessageStrings() {
assertEquals("Blah",Exceptions.toMessageString(new Exception("Blah")));
assertEquals("Blah", Exceptions.toMessageString(new Exception(new Exception("Blah"))));