Introduce SpringFailOnTimeout(Statement, Method) constructor
This commit is contained in:
parent
f13f493551
commit
428499a384
|
|
@ -26,7 +26,6 @@ import org.junit.rules.MethodRule;
|
||||||
import org.junit.runners.model.FrameworkMethod;
|
import org.junit.runners.model.FrameworkMethod;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import org.springframework.test.annotation.TestAnnotationUtils;
|
|
||||||
import org.springframework.test.context.TestContextManager;
|
import org.springframework.test.context.TestContextManager;
|
||||||
import org.springframework.test.context.junit4.statements.ProfileValueChecker;
|
import org.springframework.test.context.junit4.statements.ProfileValueChecker;
|
||||||
import org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks;
|
import org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks;
|
||||||
|
|
@ -179,7 +178,6 @@ public class SpringMethodRule implements MethodRule {
|
||||||
* Wrap the supplied {@link Statement} with a {@code SpringRepeat} statement.
|
* Wrap the supplied {@link Statement} with a {@code SpringRepeat} statement.
|
||||||
* <p>Supports Spring's {@link org.springframework.test.annotation.Repeat @Repeat}
|
* <p>Supports Spring's {@link org.springframework.test.annotation.Repeat @Repeat}
|
||||||
* annotation.
|
* annotation.
|
||||||
* @see TestAnnotationUtils#getRepeatCount(java.lang.reflect.Method)
|
|
||||||
* @see SpringRepeat
|
* @see SpringRepeat
|
||||||
*/
|
*/
|
||||||
private Statement withPotentialRepeat(Statement next, FrameworkMethod frameworkMethod, Object testInstance) {
|
private Statement withPotentialRepeat(Statement next, FrameworkMethod frameworkMethod, Object testInstance) {
|
||||||
|
|
@ -190,11 +188,10 @@ public class SpringMethodRule implements MethodRule {
|
||||||
* Wrap the supplied {@link Statement} with a {@code SpringFailOnTimeout} statement.
|
* Wrap the supplied {@link Statement} with a {@code SpringFailOnTimeout} statement.
|
||||||
* <p>Supports Spring's {@link org.springframework.test.annotation.Timed @Timed}
|
* <p>Supports Spring's {@link org.springframework.test.annotation.Timed @Timed}
|
||||||
* annotation.
|
* annotation.
|
||||||
* @see TestAnnotationUtils#getTimeout(java.lang.reflect.Method)
|
|
||||||
* @see SpringFailOnTimeout
|
* @see SpringFailOnTimeout
|
||||||
*/
|
*/
|
||||||
private Statement withPotentialTimeout(Statement next, FrameworkMethod frameworkMethod, Object testInstance) {
|
private Statement withPotentialTimeout(Statement next, FrameworkMethod frameworkMethod, Object testInstance) {
|
||||||
return new SpringFailOnTimeout(next, TestAnnotationUtils.getTimeout(frameworkMethod.getMethod()));
|
return new SpringFailOnTimeout(next, frameworkMethod.getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,19 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4.statements;
|
package org.springframework.test.context.junit4.statements;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
import org.springframework.test.annotation.Timed;
|
|
||||||
|
import org.springframework.test.annotation.TestAnnotationUtils;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code SpringFailOnTimeout} is a custom JUnit {@link Statement} which adds
|
* {@code SpringFailOnTimeout} is a custom JUnit {@link Statement} which adds
|
||||||
* support for Spring's {@link Timed @Timed} annotation by throwing an exception
|
* support for Spring's {@link org.springframework.test.annotation.Timed @Timed}
|
||||||
* if the next statement in the execution chain takes more than the specified
|
* annotation by throwing an exception if the next statement in the execution
|
||||||
* number of milliseconds.
|
* chain takes more than the specified number of milliseconds.
|
||||||
*
|
*
|
||||||
* <p>In contrast to JUnit's
|
* <p>In contrast to JUnit's
|
||||||
* {@link org.junit.internal.runners.statements.FailOnTimeout FailOnTimeout},
|
* {@link org.junit.internal.runners.statements.FailOnTimeout FailOnTimeout},
|
||||||
|
|
@ -45,11 +47,27 @@ public class SpringFailOnTimeout extends Statement {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new {@code SpringFailOnTimeout} statement.
|
* Construct a new {@code SpringFailOnTimeout} statement for the supplied
|
||||||
|
* {@code testMethod}, retrieving the configured timeout from the
|
||||||
|
* {@code @Timed} annotation on the supplied method.
|
||||||
*
|
*
|
||||||
* @param next the next {@code Statement} in the execution chain
|
* @param next the next {@code Statement} in the execution chain
|
||||||
* @param timeout the configured {@code timeout} for the current test
|
* @param testMethod the current test method
|
||||||
* @see Timed#millis()
|
* @see TestAnnotationUtils#getTimeout(Method)
|
||||||
|
*/
|
||||||
|
public SpringFailOnTimeout(Statement next, Method testMethod) {
|
||||||
|
this(next, TestAnnotationUtils.getTimeout(testMethod));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new {@code SpringFailOnTimeout} statement for the supplied
|
||||||
|
* {@code timeout}.
|
||||||
|
* <p>If the supplied {@code timeout} is {@code 0}, the execution of the
|
||||||
|
* {@code next} statement will not be timed.
|
||||||
|
*
|
||||||
|
* @param next the next {@code Statement} in the execution chain; never {@code null}
|
||||||
|
* @param timeout the configured {@code timeout} for the current test, in milliseconds;
|
||||||
|
* never negative
|
||||||
*/
|
*/
|
||||||
public SpringFailOnTimeout(Statement next, long timeout) {
|
public SpringFailOnTimeout(Statement next, long timeout) {
|
||||||
Assert.notNull(next, "next statement must not be null");
|
Assert.notNull(next, "next statement must not be null");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue