Register EventPublishingTEL in JUnit 4 & TestNG base classes
Spring Framework 5.2 introduced an EventPublishingTestExecutionListener in the Spring TestContext Framework. This listener is automatically registered via the spring.factories mechanism; however, this listener is not registered in the abstract JUnit 4 and TestNG base classes. This commit addresses this oversight by explicitly registering the EventPublishingTestExecutionListener in the following classes. - AbstractJUnit4SpringContextTests - AbstractTransactionalJUnit4SpringContextTests - AbstractTestNGSpringContextTests - AbstractTransactionalTestNGSpringContextTests Closes gh-23748
This commit is contained in:
parent
fc74c43718
commit
6fd50d7d17
|
@ -27,6 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.TestContextManager;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.event.EventPublishingTestExecutionListener;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
@ -55,6 +56,7 @@ import org.springframework.test.context.web.ServletTestExecutionListener;
|
|||
* <li>{@link org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.support.DirtiesContextTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.event.EventPublishingTestExecutionListener}
|
||||
* </ul>
|
||||
*
|
||||
* <p>This class serves only as a convenience for extension.
|
||||
|
@ -82,12 +84,14 @@ import org.springframework.test.context.web.ServletTestExecutionListener;
|
|||
* @see DirtiesContextBeforeModesTestExecutionListener
|
||||
* @see DependencyInjectionTestExecutionListener
|
||||
* @see DirtiesContextTestExecutionListener
|
||||
* @see EventPublishingTestExecutionListener
|
||||
* @see AbstractTransactionalJUnit4SpringContextTests
|
||||
* @see org.springframework.test.context.testng.AbstractTestNGSpringContextTests
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestExecutionListeners({ ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class,
|
||||
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
EventPublishingTestExecutionListener.class })
|
||||
public abstract class AbstractJUnit4SpringContextTests implements ApplicationContextAware {
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,8 +27,13 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
|||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.event.EventPublishingTestExecutionListener;
|
||||
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.test.context.web.ServletTestExecutionListener;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -61,6 +66,7 @@ import org.springframework.util.Assert;
|
|||
* <li>{@link org.springframework.test.context.support.DirtiesContextTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.transaction.TransactionalTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.event.EventPublishingTestExecutionListener}
|
||||
* </ul>
|
||||
*
|
||||
* <p>This class serves only as a convenience for extension.
|
||||
|
@ -94,7 +100,10 @@ import org.springframework.util.Assert;
|
|||
* @see org.springframework.test.jdbc.JdbcTestUtils
|
||||
* @see org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests
|
||||
*/
|
||||
@TestExecutionListeners({TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class})
|
||||
@TestExecutionListeners(listeners = { ServletTestExecutionListener.class,
|
||||
DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
|
||||
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
|
||||
SqlScriptsTestExecutionListener.class, EventPublishingTestExecutionListener.class }, inheritListeners = false)
|
||||
@Transactional
|
||||
public abstract class AbstractTransactionalJUnit4SpringContextTests extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.TestContextManager;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.event.EventPublishingTestExecutionListener;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
@ -65,6 +66,7 @@ import org.springframework.test.context.web.ServletTestExecutionListener;
|
|||
* <li>{@link org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.support.DirtiesContextTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.event.EventPublishingTestExecutionListener}
|
||||
* </ul>
|
||||
*
|
||||
* @author Sam Brannen
|
||||
|
@ -78,11 +80,13 @@ import org.springframework.test.context.web.ServletTestExecutionListener;
|
|||
* @see DirtiesContextBeforeModesTestExecutionListener
|
||||
* @see DependencyInjectionTestExecutionListener
|
||||
* @see DirtiesContextTestExecutionListener
|
||||
* @see EventPublishingTestExecutionListener
|
||||
* @see AbstractTransactionalTestNGSpringContextTests
|
||||
* @see org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
|
||||
*/
|
||||
@TestExecutionListeners({ ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class,
|
||||
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
EventPublishingTestExecutionListener.class })
|
||||
public abstract class AbstractTestNGSpringContextTests implements IHookable, ApplicationContextAware {
|
||||
|
||||
/** Logger available to subclasses. */
|
||||
|
|
|
@ -26,8 +26,13 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.event.EventPublishingTestExecutionListener;
|
||||
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.test.context.web.ServletTestExecutionListener;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -60,6 +65,7 @@ import org.springframework.util.Assert;
|
|||
* <li>{@link org.springframework.test.context.support.DirtiesContextTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.transaction.TransactionalTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener}
|
||||
* <li>{@link org.springframework.test.context.event.EventPublishingTestExecutionListener}
|
||||
* </ul>
|
||||
*
|
||||
* @author Sam Brannen
|
||||
|
@ -78,7 +84,10 @@ import org.springframework.util.Assert;
|
|||
* @see org.springframework.test.jdbc.JdbcTestUtils
|
||||
* @see org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests
|
||||
*/
|
||||
@TestExecutionListeners({TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class})
|
||||
@TestExecutionListeners(listeners = { ServletTestExecutionListener.class,
|
||||
DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
|
||||
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
|
||||
SqlScriptsTestExecutionListener.class, EventPublishingTestExecutionListener.class }, inheritListeners = false)
|
||||
@Transactional
|
||||
public abstract class AbstractTransactionalTestNGSpringContextTests extends AbstractTestNGSpringContextTests {
|
||||
|
||||
|
|
Loading…
Reference in New Issue