Last active
April 11, 2018 22:01
-
-
Save igor-suhorukov/9af4520a8db964b914b2ae49909c07b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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