Introduce MethodInvoker API for TestExecutionListeners
In order to be able to support parameter injection in @BeforeTransaction and @AfterTransaction methods (see gh-30736), this commit introduces a MethodInvoker API for TestExecutionListeners as a generic mechanism for delegating to the underlying testing framework to invoke methods. The default implementation simply invokes the method without arguments, which allows TestExecutionListeners using this mechanism to operate correctly when the underlying testing framework is JUnit 4, TestNG, etc. A JUnit Jupiter specific implementation is registered in the SpringExtension which delegates to the ExtensionContext.getExecutableInvoker() mechanism introduced in JUnit Jupiter 5.9. This allows a TestExecutionListener to transparently benefit from registered ParameterResolvers in JUnit Jupiter (including the SpringExtension) when invoking user methods, effectively providing support for parameter injection for arbitrary methods. Closes gh-31199
This commit is contained in:
@@ -37,6 +37,7 @@ import org.springframework.transaction.support.SimpleTransactionStatus;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.transaction.annotation.Propagation.NOT_SUPPORTED;
|
||||
import static org.springframework.transaction.annotation.Propagation.REQUIRED;
|
||||
@@ -58,7 +59,7 @@ class TransactionalTestExecutionListenerTests {
|
||||
}
|
||||
};
|
||||
|
||||
private final TestContext testContext = mock();
|
||||
private final TestContext testContext = mock(CALLS_REAL_METHODS);
|
||||
|
||||
|
||||
@AfterEach
|
||||
|
||||
Reference in New Issue
Block a user