diff --git a/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java b/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java index a326f76..2f374e4 100644 --- a/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java +++ b/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java @@ -110,7 +110,7 @@ public class BinaryExceptionClassifier extends SubclassClassifier> set = Collections + .> singleton(IllegalStateException.class); + BinaryExceptionClassifier binaryExceptionClassifier = new BinaryExceptionClassifier(set); + binaryExceptionClassifier.setTraverseCauses(true); + assertTrue(binaryExceptionClassifier.classify(new RuntimeException(new FooException("Foo")))); + } + + @Test + public void testClassifySubclassMatchInCauseFalse() { + Map, Boolean> map = new HashMap, Boolean>(); + map.put(IllegalStateException.class, true); + map.put(BarException.class, false); + BinaryExceptionClassifier binaryExceptionClassifier = new BinaryExceptionClassifier(map, true); + binaryExceptionClassifier.setTraverseCauses(true); + assertTrue(binaryExceptionClassifier.classify(new RuntimeException(new FooException("Foo", new BarException())))); + assertTrue(((Map) new DirectFieldAccessor(binaryExceptionClassifier).getPropertyValue("classified")) + .containsKey(FooException.class)); + } + @Test public void testTypesProvidedInConstructor() { classifier = new BinaryExceptionClassifier(Collections @@ -86,4 +111,26 @@ public class BinaryExceptionClassifierTests { classifier.setTraverseCauses(true); assertFalse(classifier.classify(new RuntimeException(new RuntimeException(new IllegalStateException("Foo"))))); } + + @SuppressWarnings("serial") + private class FooException extends IllegalStateException { + + private FooException(String s) { + super(s); + } + + private FooException(String s, Throwable t) { + super(s, t); + } + + } + + @SuppressWarnings("serial") + private class BarException extends RuntimeException { + + private BarException() { + super(); + } + + } }