Skip to content

Instantly share code, notes, and snippets.

@igor-suhorukov
Last active April 11, 2018 22:01
Show Gist options
  • Save igor-suhorukov/9af4520a8db964b914b2ae49909c07b6 to your computer and use it in GitHub Desktop.
Save igor-suhorukov/9af4520a8db964b914b2ae49909c07b6 to your computer and use it in GitHub Desktop.
package org.springframework.test.context.junit4.spr16716;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.model.Statement;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.test.context.junit4.statements.SpringFailOnTimeout;
import java.util.concurrent.TimeoutException;
import static org.mockito.Mockito.doThrow;
/**
* Validate that invocation of getCause() in exception from finally block
* returns first raised exception from "try" block
* <a href="https://jira.spring.io/browse/SPR-16716" target="_blank">SPR-16716</a>.
*
* @author Igor Suhorukov
* @since 5.0.6
*/
@RunWith(MockitoJUnitRunner.class)
public class SpringFailOnTimeoutExceptionTest {
@Mock
private Statement statement;
@Test
public void validateException() throws Throwable {
Exception expectedException = new Exception();
doThrow(expectedException).when(statement).evaluate();
try {
new SpringFailOnTimeout(statement,1L);
} catch (Throwable ex) {
Assert.assertEquals(TimeoutException.class, ex.getClass());
Assert.assertEquals(expectedException, NestedExceptionUtils.getRootCause(ex));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment