diff --git a/src/test/java/org/springframework/classify/BackToBackPatternClassifierTests.java b/src/test/java/org/springframework/classify/BackToBackPatternClassifierTests.java index c0b7204..934164c 100644 --- a/src/test/java/org/springframework/classify/BackToBackPatternClassifierTests.java +++ b/src/test/java/org/springframework/classify/BackToBackPatternClassifierTests.java @@ -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"; diff --git a/src/test/java/org/springframework/classify/BinaryExceptionClassifierTests.java b/src/test/java/org/springframework/classify/BinaryExceptionClassifierTests.java index 1d763b0..906f590 100644 --- a/src/test/java/org/springframework/classify/BinaryExceptionClassifierTests.java +++ b/src/test/java/org/springframework/classify/BinaryExceptionClassifierTests.java @@ -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> set = Collections .> singleton(IllegalStateException.class); assertTrue(new BinaryExceptionClassifier(set).classify(new IllegalStateException("Foo"))); } + @Test public void testTypesProvidedInConstructor() { classifier = new BinaryExceptionClassifier(Collections .> singleton(IllegalStateException.class)); assertTrue(classifier.classify(new IllegalStateException("Foo"))); } + @Test public void testTypesProvidedInConstructorWithNonDefault() { classifier = new BinaryExceptionClassifier(Collections .> singleton(IllegalStateException.class), false); diff --git a/src/test/java/org/springframework/classify/ClassifierAdapterTests.java b/src/test/java/org/springframework/classify/ClassifierAdapterTests.java index a97bfb3..c0cb71d 100644 --- a/src/test/java/org/springframework/classify/ClassifierAdapterTests.java +++ b/src/test/java/org/springframework/classify/ClassifierAdapterTests.java @@ -31,7 +31,6 @@ public class ClassifierAdapterTests { @Test public void testClassifierAdapterObject() { adapter = new ClassifierAdapter(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(); diff --git a/src/test/java/org/springframework/classify/ClassifierSupportTests.java b/src/test/java/org/springframework/classify/ClassifierSupportTests.java index c1416c2..1b6eb28 100644 --- a/src/test/java/org/springframework/classify/ClassifierSupportTests.java +++ b/src/test/java/org/springframework/classify/ClassifierSupportTests.java @@ -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 classifier = new ClassifierSupport("foo"); assertEquals(classifier.classify(null), "foo"); } + @Test public void testClassifyRandomException() { ClassifierSupport classifier = new ClassifierSupport("foo"); assertEquals(classifier.classify(new IllegalStateException("Foo")), classifier.classify(null)); diff --git a/src/test/java/org/springframework/retry/AbstractExceptionTests.java b/src/test/java/org/springframework/retry/AbstractExceptionTests.java index 8b2a61a..5b16eb7 100644 --- a/src/test/java/org/springframework/retry/AbstractExceptionTests.java +++ b/src/test/java/org/springframework/retry/AbstractExceptionTests.java @@ -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)); diff --git a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java index 5c280f9..b70a99b 100644 --- a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java @@ -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; diff --git a/src/test/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicyTests.java index 496253b..891d317 100644 --- a/src/test/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicyTests.java @@ -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()); diff --git a/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java index c71dc2b..93462f1 100644 --- a/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java @@ -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(); diff --git a/src/test/java/org/springframework/retry/backoff/ObjectWaitSleeperTests.java b/src/test/java/org/springframework/retry/backoff/ObjectWaitSleeperTests.java index edd7914..13d953c 100644 --- a/src/test/java/org/springframework/retry/backoff/ObjectWaitSleeperTests.java +++ b/src/test/java/org/springframework/retry/backoff/ObjectWaitSleeperTests.java @@ -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(); diff --git a/src/test/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptorTests.java b/src/test/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptorTests.java index ec31f59..6822e88 100644 --- a/src/test/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptorTests.java +++ b/src/test/java/org/springframework/retry/interceptor/StatefulRetryOperationsInterceptorTests.java @@ -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 list = new ArrayList(); @@ -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); diff --git a/src/test/java/org/springframework/retry/listener/RetryListenerSupportTests.java b/src/test/java/org/springframework/retry/listener/RetryListenerSupportTests.java index 0b7c5f8..fbcbfdb 100644 --- a/src/test/java/org/springframework/retry/listener/RetryListenerSupportTests.java +++ b/src/test/java/org/springframework/retry/listener/RetryListenerSupportTests.java @@ -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)); diff --git a/src/test/java/org/springframework/retry/listener/RetryListenerTests.java b/src/test/java/org/springframework/retry/listener/RetryListenerTests.java index bc6d3f8..e17ffb2 100644 --- a/src/test/java/org/springframework/retry/listener/RetryListenerTests.java +++ b/src/test/java/org/springframework/retry/listener/RetryListenerTests.java @@ -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 list = new ArrayList(); + @Test public void testOpenInterceptors() throws Exception { template.setListeners(new RetryListener[] { new RetryListenerSupport() { public boolean open(RetryContext context, RetryCallback 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 boolean open(RetryContext context, RetryCallback 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 void close(RetryContext context, RetryCallback 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 void close(RetryContext context, RetryCallback callback, Throwable t) { diff --git a/src/test/java/org/springframework/retry/policy/AlwaysRetryPolicyTests.java b/src/test/java/org/springframework/retry/policy/AlwaysRetryPolicyTests.java index a83118a..6bf4d0d 100644 --- a/src/test/java/org/springframework/retry/policy/AlwaysRetryPolicyTests.java +++ b/src/test/java/org/springframework/retry/policy/AlwaysRetryPolicyTests.java @@ -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); diff --git a/src/test/java/org/springframework/retry/policy/CompositeRetryPolicyTests.java b/src/test/java/org/springframework/retry/policy/CompositeRetryPolicyTests.java index 669489e..c76c1e7 100644 --- a/src/test/java/org/springframework/retry/policy/CompositeRetryPolicyTests.java +++ b/src/test/java/org/springframework/retry/policy/CompositeRetryPolicyTests.java @@ -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 list = new ArrayList(); 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 list = new ArrayList(); 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); diff --git a/src/test/java/org/springframework/retry/policy/ExceptionClassifierRetryPolicyTests.java b/src/test/java/org/springframework/retry/policy/ExceptionClassifierRetryPolicyTests.java index bba9e19..8dbe63a 100644 --- a/src/test/java/org/springframework/retry/policy/ExceptionClassifierRetryPolicyTests.java +++ b/src/test/java/org/springframework/retry/policy/ExceptionClassifierRetryPolicyTests.java @@ -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., 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, RetryPolicy>()); RetryContext context = policy.open(null); assertNotNull(context); } + @Test public void testNullContext() throws Exception { policy.setPolicyMap(Collections., 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() { 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); diff --git a/src/test/java/org/springframework/retry/policy/FatalExceptionRetryPolicyTests.java b/src/test/java/org/springframework/retry/policy/FatalExceptionRetryPolicyTests.java index 2700d3c..ac9b85c 100644 --- a/src/test/java/org/springframework/retry/policy/FatalExceptionRetryPolicyTests.java +++ b/src/test/java/org/springframework/retry/policy/FatalExceptionRetryPolicyTests.java @@ -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()); diff --git a/src/test/java/org/springframework/retry/policy/NeverRetryPolicyTests.java b/src/test/java/org/springframework/retry/policy/NeverRetryPolicyTests.java index a7ca895..eaeda2c 100644 --- a/src/test/java/org/springframework/retry/policy/NeverRetryPolicyTests.java +++ b/src/test/java/org/springframework/retry/policy/NeverRetryPolicyTests.java @@ -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); diff --git a/src/test/java/org/springframework/retry/policy/TimeoutRetryPolicyTests.java b/src/test/java/org/springframework/retry/policy/TimeoutRetryPolicyTests.java index c378dac..4db340c 100644 --- a/src/test/java/org/springframework/retry/policy/TimeoutRetryPolicyTests.java +++ b/src/test/java/org/springframework/retry/policy/TimeoutRetryPolicyTests.java @@ -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); diff --git a/src/test/java/org/springframework/retry/support/RetrySynchronizationManagerTests.java b/src/test/java/org/springframework/retry/support/RetrySynchronizationManagerTests.java index 638004a..0be7bfc 100644 --- a/src/test/java/org/springframework/retry/support/RetrySynchronizationManagerTests.java +++ b/src/test/java/org/springframework/retry/support/RetrySynchronizationManagerTests.java @@ -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);