下面列出了怎么用org.springframework.test.context.junit4.statements.SpringFailOnTimeout的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void userExceptionPropagates() throws Throwable {
doThrow(new Boom()).when(statement).evaluate();
exception.expect(Boom.class);
new SpringFailOnTimeout(statement, 1).evaluate();
}
@Test
public void timeoutExceptionThrownIfNoUserException() throws Throwable {
doAnswer((Answer<Void>) invocation -> {
TimeUnit.MILLISECONDS.sleep(50);
return null;
}).when(statement).evaluate();
exception.expect(TimeoutException.class);
new SpringFailOnTimeout(statement, 1).evaluate();
}
@Test
public void noExceptionThrownIfNoUserExceptionAndTimeoutDoesNotOccur() throws Throwable {
doAnswer((Answer<Void>) invocation -> {
return null;
}).when(statement).evaluate();
new SpringFailOnTimeout(statement, 100).evaluate();
}
@Test
public void nullNextStatement() throws Throwable {
exception.expect(IllegalArgumentException.class);
new SpringFailOnTimeout(null, 1);
}
@Test
public void negativeTimeout() throws Throwable {
exception.expect(IllegalArgumentException.class);
new SpringFailOnTimeout(statement, -1);
}
/**
* Wrap the supplied {@link Statement} with a {@code SpringFailOnTimeout} statement.
* <p>Supports Spring's {@link org.springframework.test.annotation.Timed @Timed}
* annotation.
* @see SpringFailOnTimeout
*/
private Statement withPotentialTimeout(Statement next, Method testMethod, Object testInstance) {
return new SpringFailOnTimeout(next, testMethod);
}
/**
* Wrap the supplied {@link Statement} with a {@code SpringFailOnTimeout} statement.
* <p>Supports Spring's {@link org.springframework.test.annotation.Timed @Timed}
* annotation.
* @see SpringFailOnTimeout
*/
private Statement withPotentialTimeout(Statement next, Method testMethod, Object testInstance) {
return new SpringFailOnTimeout(next, testMethod);
}
/**
* Wrap the supplied {@link Statement} with a {@code SpringFailOnTimeout} statement.
* <p>Supports Spring's {@link org.springframework.test.annotation.Timed @Timed}
* annotation.
* @see SpringFailOnTimeout
*/
private Statement withPotentialTimeout(Statement next, FrameworkMethod frameworkMethod, Object testInstance) {
return new SpringFailOnTimeout(next, frameworkMethod.getMethod());
}