Remove JUnit TestCase references

This commit is contained in:
Dave Syer
2013-04-05 14:35:06 +01:00
parent e9fa48236f
commit d9ee15606e
19 changed files with 182 additions and 47 deletions

View File

@@ -59,7 +59,6 @@ public class BackToBackPatternClassifierTests {
@Test
public void testSetRouterDelegate() {
classifier.setRouterDelegate(new Object() {
@SuppressWarnings("unused")
@Classifier
public String convert(String value) {
return "bucket";

View File

@@ -16,44 +16,54 @@
package org.springframework.classify;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.Collections;
import junit.framework.TestCase;
import org.junit.Test;
public class BinaryExceptionClassifierTests extends TestCase {
public class BinaryExceptionClassifierTests {
BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(false);
@Test
public void testClassifyNullIsDefault() {
assertFalse(classifier.classify(null));
}
@Test
public void testFalseIsDefault() {
assertFalse(classifier.getDefault());
}
@Test
public void testDefaultProvided() {
classifier = new BinaryExceptionClassifier(true);
assertTrue(classifier.getDefault());
}
@Test
public void testClassifyRandomException() {
assertFalse(classifier.classify(new IllegalStateException("foo")));
}
@Test
public void testClassifyExactMatch() {
Collection<Class<? extends Throwable>> set = Collections
.<Class<? extends Throwable>> singleton(IllegalStateException.class);
assertTrue(new BinaryExceptionClassifier(set).classify(new IllegalStateException("Foo")));
}
@Test
public void testTypesProvidedInConstructor() {
classifier = new BinaryExceptionClassifier(Collections
.<Class<? extends Throwable>> singleton(IllegalStateException.class));
assertTrue(classifier.classify(new IllegalStateException("Foo")));
}
@Test
public void testTypesProvidedInConstructorWithNonDefault() {
classifier = new BinaryExceptionClassifier(Collections
.<Class<? extends Throwable>> singleton(IllegalStateException.class), false);

View File

@@ -31,7 +31,6 @@ public class ClassifierAdapterTests {
@Test
public void testClassifierAdapterObject() {
adapter = new ClassifierAdapter<String, Integer>(new Object() {
@SuppressWarnings("unused")
@Classifier
public Integer getValue(String key) {
return Integer.parseInt(key);
@@ -93,7 +92,6 @@ public class ClassifierAdapterTests {
@Test
public void testClassifyWithSetter() {
adapter.setDelegate(new Object() {
@SuppressWarnings("unused")
@Classifier
public Integer getValue(String key) {
return Integer.parseInt(key);
@@ -105,7 +103,6 @@ public class ClassifierAdapterTests {
@Test(expected=IllegalArgumentException.class)
public void testClassifyWithWrongType() {
adapter.setDelegate(new Object() {
@SuppressWarnings("unused")
@Classifier
public String getValue(Integer key) {
return key.toString();

View File

@@ -16,17 +16,19 @@
package org.springframework.classify;
import org.springframework.classify.ClassifierSupport;
import static org.junit.Assert.assertEquals;
import junit.framework.TestCase;
import org.junit.Test;
public class ClassifierSupportTests extends TestCase {
public class ClassifierSupportTests {
@Test
public void testClassifyNullIsDefault() {
ClassifierSupport<String,String> classifier = new ClassifierSupport<String,String>("foo");
assertEquals(classifier.classify(null), "foo");
}
@Test
public void testClassifyRandomException() {
ClassifierSupport<Throwable,String> classifier = new ClassifierSupport<Throwable,String>("foo");
assertEquals(classifier.classify(new IllegalStateException("Foo")), classifier.classify(null));

View File

@@ -16,15 +16,19 @@
package org.springframework.retry;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
public abstract class AbstractExceptionTests extends TestCase {
import org.junit.Test;
public abstract class AbstractExceptionTests {
@Test
public void testExceptionString() throws Exception {
Exception exception = getException("foo");
assertEquals("foo", exception.getMessage());
}
@Test
public void testExceptionStringThrowable() throws Exception {
Exception exception = getException("foo", new IllegalStateException());
assertEquals("foo", exception.getMessage().substring(0, 3));

View File

@@ -16,16 +16,20 @@
package org.springframework.retry.backoff;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* @author Rob Harrop
* @author Dave Syer
*/
public class ExponentialBackOffPolicyTests extends TestCase {
public class ExponentialBackOffPolicyTests {
private DummySleeper sleeper = new DummySleeper();
@Test
public void testSetMaxInterval() throws Exception {
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
strategy.setMaxInterval(1000);
@@ -35,6 +39,7 @@ public class ExponentialBackOffPolicyTests extends TestCase {
assertTrue(strategy.toString().indexOf("maxInterval=1") >= 0);
}
@Test
public void testSetInitialInterval() throws Exception {
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
strategy.setInitialInterval(10000);
@@ -43,6 +48,7 @@ public class ExponentialBackOffPolicyTests extends TestCase {
assertTrue(strategy.toString().indexOf("initialInterval=1,") >= 0);
}
@Test
public void testSetMultiplier() throws Exception {
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
strategy.setMultiplier(3.);
@@ -51,6 +57,7 @@ public class ExponentialBackOffPolicyTests extends TestCase {
assertTrue(strategy.toString().indexOf("multiplier=1.") >= 0);
}
@Test
public void testSingleBackOff() throws Exception {
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
strategy.setSleeper(sleeper);
@@ -59,6 +66,7 @@ public class ExponentialBackOffPolicyTests extends TestCase {
assertEquals(ExponentialBackOffPolicy.DEFAULT_INITIAL_INTERVAL, sleeper.getLastBackOff());
}
@Test
public void testMaximumBackOff() throws Exception {
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
strategy.setMaxInterval(50);
@@ -68,6 +76,7 @@ public class ExponentialBackOffPolicyTests extends TestCase {
assertEquals(50, sleeper.getLastBackOff());
}
@Test
public void testMultiBackOff() throws Exception {
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
long seed = 40;

View File

@@ -16,15 +16,22 @@
package org.springframework.retry.backoff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetrySimulation;
import org.springframework.retry.support.RetrySimulator;
public class ExponentialRandomBackOffPolicyTests extends TestCase {
/**
* @author Dave Syer
* @author Jon Travis
*
*/
public class ExponentialRandomBackOffPolicyTests {
static final int NUM_TRIALS = 10000;
static final int MAX_RETRIES = 6;
@@ -42,7 +49,8 @@ public class ExponentialRandomBackOffPolicyTests extends TestCase {
return retryPolicy;
}
public void testSingleBackoff() throws Exception {
@Test
public void testSingleBackoff() throws Exception {
ExponentialBackOffPolicy backOffPolicy = makeBackoffPolicy();
RetrySimulator simulator = new RetrySimulator(backOffPolicy, makeRetryPolicy());
RetrySimulation simulation = simulator.executeSimulation(1);
@@ -58,6 +66,7 @@ public class ExponentialRandomBackOffPolicyTests extends TestCase {
}
}
@Test
public void testMultiBackOff() throws Exception {
ExponentialBackOffPolicy backOffPolicy = makeBackoffPolicy();
RetrySimulator simulator = new RetrySimulator(backOffPolicy, makeRetryPolicy());

View File

@@ -16,17 +16,20 @@
package org.springframework.retry.backoff;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* @author Rob Harrop
* @author Dave Syer
* @since 2.1
*/
public class FixedBackOffPolicyTests extends TestCase {
public class FixedBackOffPolicyTests {
private DummySleeper sleeper = new DummySleeper();
@Test
public void testSetBackoffPeriodNegative() throws Exception {
FixedBackOffPolicy strategy = new FixedBackOffPolicy();
strategy.setBackOffPeriod(-1000L);
@@ -37,6 +40,7 @@ public class FixedBackOffPolicyTests extends TestCase {
assertEquals(1, sleeper.getLastBackOff());
}
@Test
public void testSingleBackOff() throws Exception {
int backOffPeriod = 50;
FixedBackOffPolicy strategy = new FixedBackOffPolicy();
@@ -47,6 +51,7 @@ public class FixedBackOffPolicyTests extends TestCase {
assertEquals(backOffPeriod, sleeper.getLastBackOff());
}
@Test
public void testManyBackOffCalls() throws Exception {
int backOffPeriod = 50;
FixedBackOffPolicy strategy = new FixedBackOffPolicy();

View File

@@ -16,13 +16,16 @@
package org.springframework.retry.backoff;
import junit.framework.TestCase;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* @author Dave Syer
*/
public class ObjectWaitSleeperTests extends TestCase {
public class ObjectWaitSleeperTests {
@Test
public void testSingleBackOff() throws Exception {
long backOffPeriod = 50;
ObjectWaitSleeper strategy = new ObjectWaitSleeper();

View File

@@ -15,15 +15,19 @@
*/
package org.springframework.retry.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.target.SingletonTargetSource;
@@ -37,7 +41,7 @@ import org.springframework.retry.support.RetryTemplate;
* @author Dave Syer
*
*/
public class StatefulRetryOperationsInterceptorTests extends TestCase {
public class StatefulRetryOperationsInterceptorTests {
private StatefulRetryOperationsInterceptor interceptor;
@@ -49,6 +53,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
private static int count;
@Before
public void setUp() throws Exception {
interceptor = new StatefulRetryOperationsInterceptor();
service = (Service) ProxyFactory.getProxy(Service.class, new SingletonTargetSource(new ServiceImpl()));
@@ -57,6 +62,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
count = 0;
}
@Test
public void testDefaultInterceptorSunnyDay() throws Exception {
((Advised) service).addAdvice(interceptor);
try {
@@ -70,6 +76,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
assertEquals(1, count);
}
@Test
public void testDefaultTransformerInterceptorSunnyDay() throws Exception {
((Advised) transformer).addAdvice(interceptor);
try {
@@ -83,6 +90,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
assertEquals(1, count);
}
@Test
public void testDefaultInterceptorAlwaysRetry() throws Exception {
retryTemplate.setRetryPolicy(new AlwaysRetryPolicy());
interceptor.setRetryOperations(retryTemplate);
@@ -98,6 +106,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
assertEquals(1, count);
}
@Test
public void testInterceptorChainWithRetry() throws Exception {
((Advised) service).addAdvice(interceptor);
final List<String> list = new ArrayList<String>();
@@ -124,6 +133,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
assertEquals(2, list.size());
}
@Test
public void testTransformerWithSuccessfulRetry() throws Exception {
((Advised) transformer).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);
@@ -143,6 +153,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
assertEquals(1, result.size());
}
@Test
public void testRetryExceptionAfterTooManyAttemptsWithNoRecovery() throws Exception {
((Advised) service).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);
@@ -168,6 +179,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
assertEquals(1, count);
}
@Test
public void testRecoveryAfterTooManyAttempts() throws Exception {
((Advised) service).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);
@@ -191,6 +203,7 @@ public class StatefulRetryOperationsInterceptorTests extends TestCase {
assertEquals(2, count);
}
@Test
public void testTransformerRecoveryAfterTooManyAttempts() throws Exception {
((Advised) transformer).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);

View File

@@ -16,10 +16,14 @@
package org.springframework.retry.listener;
import junit.framework.TestCase;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class RetryListenerSupportTests extends TestCase {
import org.junit.Test;
public class RetryListenerSupportTests {
@Test
public void testClose() {
RetryListenerSupport support = new RetryListenerSupport();
try {
@@ -30,6 +34,7 @@ public class RetryListenerSupportTests extends TestCase {
}
}
@Test
public void testOnError() {
RetryListenerSupport support = new RetryListenerSupport();
try {
@@ -40,6 +45,7 @@ public class RetryListenerSupportTests extends TestCase {
}
}
@Test
public void testOpen() {
RetryListenerSupport support = new RetryListenerSupport();
assertTrue(support.open(null, null));

View File

@@ -16,11 +16,14 @@
package org.springframework.retry.listener;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;
@@ -28,7 +31,7 @@ import org.springframework.retry.TerminatedRetryException;
import org.springframework.retry.policy.NeverRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
public class RetryListenerTests extends TestCase {
public class RetryListenerTests {
RetryTemplate template = new RetryTemplate();
@@ -36,6 +39,7 @@ public class RetryListenerTests extends TestCase {
List<String> list = new ArrayList<String>();
@Test
public void testOpenInterceptors() throws Exception {
template.setListeners(new RetryListener[] { new RetryListenerSupport() {
public <T> boolean open(RetryContext context, RetryCallback<T> callback) {
@@ -60,6 +64,7 @@ public class RetryListenerTests extends TestCase {
assertEquals("1:1", list.get(0));
}
@Test
public void testOpenCanVetoRetry() throws Exception {
template.registerListener(new RetryListenerSupport() {
public <T> boolean open(RetryContext context, RetryCallback<T> callback) {
@@ -84,6 +89,7 @@ public class RetryListenerTests extends TestCase {
assertEquals("1", list.get(0));
}
@Test
public void testCloseInterceptors() throws Exception {
template.setListeners(new RetryListener[] { new RetryListenerSupport() {
public <T> void close(RetryContext context, RetryCallback<T> callback, Throwable t) {
@@ -107,6 +113,7 @@ public class RetryListenerTests extends TestCase {
assertEquals("2:1", list.get(0));
}
@Test
public void testOnError() throws Exception {
template.setRetryPolicy(new NeverRetryPolicy());
template.setListeners(new RetryListener[] { new RetryListenerSupport() {
@@ -138,6 +145,7 @@ public class RetryListenerTests extends TestCase {
}
@Test
public void testCloseInterceptorsAfterRetry() throws Exception {
template.registerListener(new RetryListenerSupport() {
public <T> void close(RetryContext context, RetryCallback<T> callback, Throwable t) {

View File

@@ -16,12 +16,18 @@
package org.springframework.retry.policy;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.retry.RetryContext;
public class AlwaysRetryPolicyTests extends TestCase {
public class AlwaysRetryPolicyTests {
@Test
public void testSimpleOperations() throws Exception {
AlwaysRetryPolicy policy = new AlwaysRetryPolicy();
RetryContext context = policy.open(null);
@@ -33,6 +39,7 @@ public class AlwaysRetryPolicyTests extends TestCase {
assertTrue(policy.canRetry(context));
}
@Test
public void testRetryCount() throws Exception {
AlwaysRetryPolicy policy = new AlwaysRetryPolicy();
RetryContext context = policy.open(null);
@@ -44,6 +51,7 @@ public class AlwaysRetryPolicyTests extends TestCase {
assertEquals("foo", context.getLastThrowable().getMessage());
}
@Test
public void testParent() throws Exception {
AlwaysRetryPolicy policy = new AlwaysRetryPolicy();
RetryContext context = policy.open(null);

View File

@@ -16,16 +16,24 @@
package org.springframework.retry.policy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryPolicy;
public class CompositeRetryPolicyTests extends TestCase {
public class CompositeRetryPolicyTests {
@Test
public void testEmptyPolicies() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
RetryContext context = policy.open(null);
@@ -33,6 +41,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertTrue(policy.canRetry(context));
}
@Test
public void testTrivialPolicies() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() });
@@ -41,6 +50,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertTrue(policy.canRetry(context));
}
@Test
public void testNonTrivialPolicies() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() {
@@ -53,6 +63,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertFalse(policy.canRetry(context));
}
@Test
public void testNonTrivialPoliciesWithThrowable() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() {
@@ -73,6 +84,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertFalse("Should be still able to retry", policy.canRetry(context));
}
@Test
public void testNonTrivialPoliciesClose() throws Exception {
final List<String> list = new ArrayList<String>();
CompositeRetryPolicy policy = new CompositeRetryPolicy();
@@ -91,6 +103,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertEquals(2, list.size());
}
@Test
public void testExceptionOnPoliciesClose() throws Exception {
final List<String> list = new ArrayList<String>();
CompositeRetryPolicy policy = new CompositeRetryPolicy();
@@ -115,6 +128,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertEquals(2, list.size());
}
@Test
public void testRetryCount() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() });
@@ -127,6 +141,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertEquals("foo", context.getLastThrowable().getMessage());
}
@Test
public void testParent() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
RetryContext context = policy.open(null);
@@ -135,6 +150,7 @@ public class CompositeRetryPolicyTests extends TestCase {
assertSame(context, child.getParent());
}
@Test
public void testOptimistic() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
policy.setOptimistic(true);

View File

@@ -16,23 +16,32 @@
package org.springframework.retry.policy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.HashMap;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.classify.Classifier;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryPolicy;
public class ExceptionClassifierRetryPolicyTests extends TestCase {
public class ExceptionClassifierRetryPolicyTests {
private ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy();
@Test
public void testDefaultPolicies() throws Exception {
RetryContext context = policy.open(null);
assertNotNull(context);
}
@Test
public void testTrivialPolicies() throws Exception {
policy.setPolicyMap(Collections.<Class<? extends Throwable>, RetryPolicy> singletonMap(Exception.class,
new MockRetryPolicySupport()));
@@ -41,12 +50,14 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase {
assertTrue(policy.canRetry(context));
}
@Test
public void testNullPolicies() throws Exception {
policy.setPolicyMap(new HashMap<Class<? extends Throwable>, RetryPolicy>());
RetryContext context = policy.open(null);
assertNotNull(context);
}
@Test
public void testNullContext() throws Exception {
policy.setPolicyMap(Collections.<Class<? extends Throwable>, RetryPolicy> singletonMap(Exception.class,
new NeverRetryPolicy()));
@@ -57,6 +68,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase {
assertTrue(policy.canRetry(context));
}
@Test
public void testClassifierOperates() throws Exception {
RetryContext context = policy.open(null);
@@ -91,6 +103,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase {
int count = 0;
@Test
public void testClose() throws Exception {
policy.setExceptionClassifier(new Classifier<Throwable, RetryPolicy>() {
public RetryPolicy classify(Throwable throwable) {
@@ -114,6 +127,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase {
assertEquals(1, count); // now classified
}
@Test
public void testRetryCount() throws Exception {
ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy();
RetryContext context = policy.open(null);
@@ -125,6 +139,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase {
assertEquals("foo", context.getLastThrowable().getMessage());
}
@Test
public void testParent() throws Exception {
ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy();
RetryContext context = policy.open(null);

View File

@@ -16,19 +16,22 @@
package org.springframework.retry.policy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.retry.RecoveryCallback;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.support.DefaultRetryState;
import org.springframework.retry.support.RetryTemplate;
public class FatalExceptionRetryPolicyTests extends TestCase {
public class FatalExceptionRetryPolicyTests {
@Test
public void testFatalExceptionWithoutState() throws Exception {
MockRetryCallback callback = new MockRetryCallback();
callback.setExceptionToThrow(new IllegalArgumentException());
@@ -62,6 +65,7 @@ public class FatalExceptionRetryPolicyTests extends TestCase {
assertEquals("bar", result);
}
@Test
public void testFatalExceptionWithState() throws Exception {
MockRetryCallback callback = new MockRetryCallback();
callback.setExceptionToThrow(new IllegalArgumentException());

View File

@@ -16,12 +16,19 @@
package org.springframework.retry.policy;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.retry.RetryContext;
public class NeverRetryPolicyTests extends TestCase {
public class NeverRetryPolicyTests {
@Test
public void testSimpleOperations() throws Exception {
NeverRetryPolicy policy = new NeverRetryPolicy();
RetryContext context = policy.open(null);
@@ -35,6 +42,7 @@ public class NeverRetryPolicyTests extends TestCase {
assertFalse(policy.canRetry(context));
}
@Test
public void testRetryCount() throws Exception {
NeverRetryPolicy policy = new NeverRetryPolicy();
RetryContext context = policy.open(null);
@@ -46,6 +54,7 @@ public class NeverRetryPolicyTests extends TestCase {
assertEquals("foo", context.getLastThrowable().getMessage());
}
@Test
public void testParent() throws Exception {
NeverRetryPolicy policy = new NeverRetryPolicy();
RetryContext context = policy.open(null);

View File

@@ -16,12 +16,19 @@
package org.springframework.retry.policy;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.retry.RetryContext;
public class TimeoutRetryPolicyTests extends TestCase {
public class TimeoutRetryPolicyTests {
@Test
public void testTimeoutPreventsRetry() throws Exception {
TimeoutRetryPolicy policy = new TimeoutRetryPolicy();
policy.setTimeout(100);
@@ -33,6 +40,7 @@ public class TimeoutRetryPolicyTests extends TestCase {
policy.close(context);
}
@Test
public void testRetryCount() throws Exception {
TimeoutRetryPolicy policy = new TimeoutRetryPolicy();
RetryContext context = policy.open(null);
@@ -44,6 +52,7 @@ public class TimeoutRetryPolicyTests extends TestCase {
assertEquals("foo", context.getLastThrowable().getMessage());
}
@Test
public void testParent() throws Exception {
TimeoutRetryPolicy policy = new TimeoutRetryPolicy();
RetryContext context = policy.open(null);

View File

@@ -16,8 +16,13 @@
package org.springframework.retry.support;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import org.junit.Before;
import org.junit.Test;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.context.RetryContextSupport;
@@ -25,17 +30,18 @@ import org.springframework.retry.context.RetryContextSupport;
/**
* @author Dave Syer
*/
public class RetrySynchronizationManagerTests extends TestCase {
public class RetrySynchronizationManagerTests {
RetryTemplate template = new RetryTemplate();
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
RetrySynchronizationManagerTests.clearAll();
RetryContext status = RetrySynchronizationManager.getContext();
assertNull(status);
}
@Test
public void testStatusIsStoredByTemplate() throws Exception {
RetryContext status = RetrySynchronizationManager.getContext();
@@ -54,6 +60,7 @@ public class RetrySynchronizationManagerTests extends TestCase {
assertNull(status);
}
@Test
public void testStatusRegistration() throws Exception {
RetryContext status = new RetryContextSupport(null);
RetryContext value = RetrySynchronizationManager.register(status);
@@ -62,6 +69,7 @@ public class RetrySynchronizationManagerTests extends TestCase {
assertEquals(status, value);
}
@Test
public void testClear() throws Exception {
RetryContext status = new RetryContextSupport(null);
RetryContext value = RetrySynchronizationManager.register(status);
@@ -71,6 +79,7 @@ public class RetrySynchronizationManagerTests extends TestCase {
assertNull(value);
}
@Test
public void testParent() throws Exception {
RetryContext parent = new RetryContextSupport(null);
RetryContext child = new RetryContextSupport(parent);