diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java b/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java index 09adb2acb90..a5078e5b4de 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java @@ -309,8 +309,8 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement); statement = withBefores(frameworkMethod, testInstance, statement); statement = withAfters(frameworkMethod, testInstance, statement); - statement = withPotentialTimeout(frameworkMethod, testInstance, statement); statement = withPotentialRepeat(frameworkMethod, testInstance, statement); + statement = withPotentialTimeout(frameworkMethod, testInstance, statement); return statement; } diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/junit4/RepeatedSpringRunnerTests.java b/org.springframework.test/src/test/java/org/springframework/test/context/junit4/RepeatedSpringRunnerTests.java index 40c1d59c10c..b12e6675e03 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/context/junit4/RepeatedSpringRunnerTests.java +++ b/org.springframework.test/src/test/java/org/springframework/test/context/junit4/RepeatedSpringRunnerTests.java @@ -30,7 +30,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.springframework.test.annotation.Repeat; import org.springframework.test.annotation.Timed; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; /** @@ -76,7 +75,8 @@ public class RepeatedSpringRunnerTests { { NonAnnotatedRepeatedTestCase.class, 0, 1, 1, 1 },// { DefaultRepeatValueRepeatedTestCase.class, 0, 1, 1, 1 },// { NegativeRepeatValueRepeatedTestCase.class, 0, 1, 1, 1 },// - { RepeatedFiveTimesRepeatedTestCase.class, 0, 1, 1, 5 } // + { RepeatedFiveTimesRepeatedTestCase.class, 0, 1, 1, 5 },// + { TimedRepeatedTestCase.class, 3, 4, 4, (5 + 1 + 4 + 10) } // }); } @@ -101,7 +101,6 @@ public class RepeatedSpringRunnerTests { @RunWith(SpringJUnit4ClassRunner.class) @TestExecutionListeners( {}) - @ContextConfiguration(locations = {}) public abstract static class AbstractRepeatedTestCase { protected void incrementInvocationCount() throws IOException { @@ -113,7 +112,7 @@ public class RepeatedSpringRunnerTests { @Test @Timed(millis = 10000) - public void testNonAnnotated() throws Exception { + public void nonAnnotated() throws Exception { incrementInvocationCount(); } } @@ -123,7 +122,7 @@ public class RepeatedSpringRunnerTests { @Test @Repeat @Timed(millis = 10000) - public void testDefaultRepeatValue() throws Exception { + public void defaultRepeatValue() throws Exception { incrementInvocationCount(); } } @@ -133,7 +132,7 @@ public class RepeatedSpringRunnerTests { @Test @Repeat(-5) @Timed(millis = 10000) - public void testNegativeRepeatValue() throws Exception { + public void negativeRepeatValue() throws Exception { incrementInvocationCount(); } } @@ -142,10 +141,48 @@ public class RepeatedSpringRunnerTests { @Test @Repeat(5) - @Timed(millis = 10000) - public void testRepeatedFiveTimes() throws Exception { + public void repeatedFiveTimes() throws Exception { incrementInvocationCount(); } } + /** + * Unit tests for claims raised in SPR-6011. + */ + public static final class TimedRepeatedTestCase extends AbstractRepeatedTestCase { + + @Test + @Timed(millis = 10000) + @Repeat(5) + public void repeatedFiveTimesButDoesNotExceedTimeout() throws Exception { + incrementInvocationCount(); + } + + @Test + @Timed(millis = 100) + @Repeat(1) + public void singleRepetitionExceedsTimeout() throws Exception { + incrementInvocationCount(); + Thread.sleep(250); + } + + @Test + @Timed(millis = 200) + @Repeat(4) + public void firstRepetitionOfManyExceedsTimeout() throws Exception { + incrementInvocationCount(); + Thread.sleep(250); + } + + @Test + @Timed(millis = 1000) + @Repeat(10) + public void collectiveRepetitionsExceedTimeout() throws Exception { + incrementInvocationCount(); + Thread.sleep(150); + } + } + }