BATCH-758: generified ExceptionClassifier and ExceptionClassifierSupport and subclasses plus tests
This commit is contained in:
@@ -63,7 +63,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testNotRethrownErrorLevel() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return LogOrRethrowExceptionHandler.ERROR;
|
||||
}
|
||||
});
|
||||
@@ -74,7 +74,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testNotRethrownWarnLevel() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return LogOrRethrowExceptionHandler.WARN;
|
||||
}
|
||||
});
|
||||
@@ -85,7 +85,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testNotRethrownDebugLevel() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return LogOrRethrowExceptionHandler.DEBUG;
|
||||
}
|
||||
});
|
||||
@@ -96,7 +96,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testUnclassifiedException() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return "DEFAULT";
|
||||
}
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testNotRethrownWithThreshold() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return "RuntimeException";
|
||||
}
|
||||
});
|
||||
@@ -65,7 +65,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testRethrowOnThreshold() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return "RuntimeException";
|
||||
}
|
||||
});
|
||||
@@ -84,7 +84,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testNotUseParent() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return "RuntimeException";
|
||||
}
|
||||
});
|
||||
@@ -103,7 +103,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase {
|
||||
|
||||
public void testUseParent() throws Throwable {
|
||||
handler.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
return "RuntimeException";
|
||||
}
|
||||
});
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase {
|
||||
assertTrue(policy.canRetry(context));
|
||||
|
||||
policy.setExceptionClassifier(new ExceptionClassifierSupport() {
|
||||
public Object classify(Throwable throwable) {
|
||||
public String classify(Throwable throwable) {
|
||||
if (throwable != null) {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
package org.springframework.batch.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.springframework.batch.support.SubclassExceptionClassifier;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SubclassExceptionClassifierTests extends TestCase {
|
||||
@@ -35,36 +32,24 @@ public class SubclassExceptionClassifierTests extends TestCase {
|
||||
assertEquals(classifier.classify(new IllegalStateException("Foo")), classifier.getDefault());
|
||||
}
|
||||
|
||||
public void testIllegalMapWithNonClass() {
|
||||
try {
|
||||
classifier.setTypeMap(Collections.singletonMap("bar", "foo"));
|
||||
fail("Expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testIllegalMapWithClass() {
|
||||
try {
|
||||
classifier.setTypeMap(Collections.singletonMap(String.class, "foo"));
|
||||
fail("Expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testClassifyExactMatch() {
|
||||
classifier.setTypeMap(Collections.singletonMap(IllegalStateException.class, "foo"));
|
||||
classifier.setTypeMap(new LinkedHashMap<Class<?>, String>() {{
|
||||
put(IllegalStateException.class, "foo");
|
||||
}});
|
||||
assertEquals("foo", classifier.classify(new IllegalStateException("Foo")));
|
||||
}
|
||||
|
||||
public void testClassifySubclassMatch() {
|
||||
classifier.setTypeMap(Collections.singletonMap(RuntimeException.class, "foo"));
|
||||
classifier.setTypeMap(new LinkedHashMap<Class<?>, String>() {{
|
||||
put(RuntimeException.class, "foo");
|
||||
}});
|
||||
assertEquals("foo", classifier.classify(new IllegalStateException("Foo")));
|
||||
}
|
||||
|
||||
public void testClassifySuperclassDoesNotMatch() {
|
||||
classifier.setTypeMap(Collections.singletonMap(IllegalStateException.class, "foo"));
|
||||
classifier.setTypeMap(new LinkedHashMap<Class<?>, String>() {{
|
||||
put(IllegalStateException.class, "foo");
|
||||
}});
|
||||
assertEquals(classifier.getDefault(), classifier.classify(new RuntimeException("Foo")));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user