From 8e6d44349d6f1ebc18a5d81f1b1b746766b3e02b Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 12 Jan 2026 11:50:03 +0100 Subject: [PATCH] Polishing --- .../jdbc/PopulatedSchemaDatabaseConfig.java | 6 ++--- .../jupiter/nested/SqlScriptNestedTests.java | 23 +++++-------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java index b3d09c34997..c1c751a8f08 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java @@ -32,12 +32,12 @@ import org.springframework.transaction.PlatformTransactionManager; * @author Sam Brannen * @since 4.1 */ -@Configuration +@Configuration(proxyBeanMethods = false) public class PopulatedSchemaDatabaseConfig { @Bean - PlatformTransactionManager transactionManager() { - return new DataSourceTransactionManager(dataSource()); + PlatformTransactionManager transactionManager(DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); } @Bean diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/SqlScriptNestedTests.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/SqlScriptNestedTests.java index 64148f34bfb..58aeace2fe6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/SqlScriptNestedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/SqlScriptNestedTests.java @@ -21,10 +21,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.NestedTestConfiguration; import org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration; +import org.springframework.test.context.jdbc.AbstractTransactionalTests; import org.springframework.test.context.jdbc.PopulatedSchemaDatabaseConfig; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlMergeMode; @@ -34,10 +33,8 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; -import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; -import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERRIDE; @@ -50,27 +47,19 @@ import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERR * @since 5.1.3 */ @SpringJUnitConfig(PopulatedSchemaDatabaseConfig.class) -@Transactional @TestInstance(Lifecycle.PER_CLASS) -class SqlScriptNestedTests { - - @Autowired - JdbcTemplate jdbcTemplate; +class SqlScriptNestedTests extends AbstractTransactionalTests { @BeforeTransaction @AfterTransaction void checkInitialDatabaseState() { - assertThat(countRowsInTable("user")).isEqualTo(0); + assertNumUsers(0); } @Test @Sql("/org/springframework/test/context/jdbc/data.sql") void sqlScripts() { - assertThat(countRowsInTable("user")).isEqualTo(1); - } - - private int countRowsInTable(String tableName) { - return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); + assertUsers("Dilbert"); } @Nested @@ -79,13 +68,13 @@ class SqlScriptNestedTests { @BeforeTransaction @AfterTransaction void checkInitialDatabaseState() { - assertThat(countRowsInTable("user")).isEqualTo(0); + assertNumUsers(0); } @Test @Sql("/org/springframework/test/context/jdbc/data.sql") void nestedSqlScripts() { - assertThat(countRowsInTable("user")).isEqualTo(1); + assertUsers("Dilbert"); } }