Class SpringFailOnTimeout
- java.lang.Object
- org.junit.runners.model.Statement
- org.springframework.test.context.junit4.statements.SpringFailOnTimeout
public class SpringFailOnTimeout extends Statement
SpringFailOnTimeoutis a custom JUnitStatementwhich adds support for Spring's@Timedannotation by throwing an exception if the next statement in the execution chain takes more than the specified number of milliseconds.In contrast to JUnit's
FailOnTimeout, the nextstatementwill be executed in the same thread as the caller and will therefore not be aborted preemptively.- Since:
- 3.0
- Author:
- Sam Brannen
- See Also:
evaluate()
Constructor Summary
Constructors Constructor Description SpringFailOnTimeout(Statement next, long timeout)Construct a newSpringFailOnTimeoutstatement for the suppliedtimeout.SpringFailOnTimeout(Statement next, Method testMethod)Construct a newSpringFailOnTimeoutstatement for the suppliedtestMethod, retrieving the configured timeout from the@Timedannotation on the supplied method.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidevaluate()Evaluate the nextstatementin the execution chain (typically an instance ofSpringRepeat) and throw aTimeoutExceptionif the nextstatementexecutes longer than the specifiedtimeout.
Constructor Detail
SpringFailOnTimeout
public SpringFailOnTimeout(Statement next, Method testMethod)
Construct a newSpringFailOnTimeoutstatement for the suppliedtestMethod, retrieving the configured timeout from the@Timedannotation on the supplied method.- Parameters:
next- the nextStatementin the execution chaintestMethod- the current test method- See Also:
TestAnnotationUtils.getTimeout(Method)
SpringFailOnTimeout
public SpringFailOnTimeout(Statement next, long timeout)
Construct a newSpringFailOnTimeoutstatement for the suppliedtimeout.If the supplied
timeoutis0, the execution of thenextstatement will not be timed.- Parameters:
next- the nextStatementin the execution chain; nevernulltimeout- the configuredtimeoutfor the current test, in milliseconds; never negative
Method Detail
evaluate
public void evaluate() throws Throwable
Evaluate the nextstatementin the execution chain (typically an instance ofSpringRepeat) and throw aTimeoutExceptionif the nextstatementexecutes longer than the specifiedtimeout.