BATCH-758: generified ExceptionClassifier and ExceptionClassifierSupport and subclasses plus tests

This commit is contained in:
trisberg
2008-08-04 16:32:53 +00:00
parent e19044b6a6
commit 858208fa19
13 changed files with 97 additions and 99 deletions

View File

@@ -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";
}
});

View File

@@ -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";
}
});

View File

@@ -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";
}

View File

@@ -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")));
}