Reset mocks only when a test has an ApplicationContext
Prior to this commit and the previous commit, MockitoResetTestExecutionListener always attempted to load the ApplicationContext to reset mocks in its beforeTestMethod() and afterTestMethod() callbacks, even if there was no active ApplicationContext. The reason this was noticed is that the @BeforeMethod(alwaysRun = true) and @AfterMethod(alwaysRun = true) lifecycle methods in AbstractTestNGSpringContextTests are always invoked, even if a previous lifecycle configuration method failed (for example, due to a context-load failure). However, with JUnit Jupiter and the SpringExtension the beforeTestMethod() and afterTestMethod() callbacks in the TestExecutionListener API are not invoked if there was a previous lifecycle failure. Consequently, the reported drawbacks only exist when using Spring's TestNG base support classes This commit picks up where the previous commit left off by applying the same hasApplicationContext() check in beforeTestMethod(). This commit also introduces unit and integration tests for both Jupiter and TestNG support. Closes gh-36782
S
Sam Brannen committed
d87c03a6be82087258f66197f874d838831f8508
Parent: 1d91982