From a393395bf16591e70139d42213bf1f09f2c3c117 Mon Sep 17 00:00:00 2001 From: Harry9656 Date: Sat, 27 Apr 2024 00:37:22 +0200 Subject: [PATCH] JAVA-34093: Fix spring-boot-persistance-2 junit-jupiter failures (#16497) --- ...ingBootJdbiApplicationIntegrationTest.java | 15 +++++------ ...gOraclePoolingApplicationC3P0LiveTest.java | 11 +++----- ...clePoolingApplicationHikariCPLiveTest.java | 11 +++----- ...raclePoolingApplicationOracleLiveTest.java | 11 +++----- ...lePoolingApplicationOracleUCPLiveTest.java | 7 ++--- .../CustomerControllerIntegrationTest.java | 27 +++++++++---------- .../states/UserEntityIntegrationTest.java | 9 +++---- ...otTomcatConnectionPoolIntegrationTest.java | 16 +++++------ 8 files changed, 43 insertions(+), 64 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/boot/jdbi/SpringBootJdbiApplicationIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/boot/jdbi/SpringBootJdbiApplicationIntegrationTest.java index 948d197f14..63acb95188 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/boot/jdbi/SpringBootJdbiApplicationIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/boot/jdbi/SpringBootJdbiApplicationIntegrationTest.java @@ -7,11 +7,9 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.boot.jdbi.dao.CarMakerDao; import com.baeldung.boot.jdbi.dao.CarModelDao; @@ -21,10 +19,9 @@ import com.baeldung.boot.jdbi.service.CarMakerService; import lombok.extern.slf4j.Slf4j; -@RunWith(SpringRunner.class) @SpringBootTest(classes = {SpringBootJdbiApplication.class, JdbiConfiguration.class}) @Slf4j -public class SpringBootJdbiApplicationIntegrationTest { +class SpringBootJdbiApplicationIntegrationTest { @Autowired @@ -37,7 +34,7 @@ public class SpringBootJdbiApplicationIntegrationTest { private CarMakerService carMakerService; @Test - public void givenNewCarMaker_whenInsertNewCarMaker_thenSuccess() { + void givenNewCarMaker_whenInsertNewCarMaker_thenSuccess() { assertNotNull(carMakerDao); @@ -51,7 +48,7 @@ public class SpringBootJdbiApplicationIntegrationTest { } @Test - public void givenNewCarMakers_whenInsertNewCarMakers_thenSuccess() { + void givenNewCarMakers_whenInsertNewCarMakers_thenSuccess() { assertNotNull(carMakerDao); @@ -74,7 +71,7 @@ public class SpringBootJdbiApplicationIntegrationTest { @Test - public void givenExistingCarMaker_whenFindById_thenReturnExistingCarMaker() { + void givenExistingCarMaker_whenFindById_thenReturnExistingCarMaker() { CarMaker maker = carMakerDao.findById(1L); assertThat(maker).isNotNull(); @@ -83,7 +80,7 @@ public class SpringBootJdbiApplicationIntegrationTest { } @Test - public void givenExistingCarMaker_whenBulkInsertFails_thenRollback() { + void givenExistingCarMaker_whenBulkInsertFails_thenRollback() { CarMaker maker = carMakerDao.findById(1L); CarModel m1 = CarModel.builder() diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationC3P0LiveTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationC3P0LiveTest.java index 5a2d3f2d29..d793244d56 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationC3P0LiveTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationC3P0LiveTest.java @@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = {SpringOraclePoolingApplication.class}) @ActiveProfiles({"oracle-pooling-basic", "c3p0"}) -public class SpringOraclePoolingApplicationC3P0LiveTest { +class SpringOraclePoolingApplicationC3P0LiveTest { @Autowired private DataSource dataSource; - @Test - public void givenC3p0Configuration_thenBuildsComboPooledDataSource() { + @Test + void givenC3p0Configuration_thenBuildsComboPooledDataSource() { assertTrue(dataSource instanceof com.mchange.v2.c3p0.ComboPooledDataSource); } diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationHikariCPLiveTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationHikariCPLiveTest.java index ab8fc1e121..d5732a55e2 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationHikariCPLiveTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationHikariCPLiveTest.java @@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = {SpringOraclePoolingApplication.class}) @ActiveProfiles("oracle-pooling-basic") -public class SpringOraclePoolingApplicationHikariCPLiveTest { +class SpringOraclePoolingApplicationHikariCPLiveTest { @Autowired private DataSource dataSource; - @Test - public void givenHikariCPConfiguration_thenBuildsHikariCP() { + @Test + void givenHikariCPConfiguration_thenBuildsHikariCP() { assertTrue(dataSource instanceof com.zaxxer.hikari.HikariDataSource); } diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleLiveTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleLiveTest.java index 229375dadd..2f94156fcf 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleLiveTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleLiveTest.java @@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = {SpringOraclePoolingApplication.class}) @ActiveProfiles({"oracle-pooling-basic", "oracle"}) -public class SpringOraclePoolingApplicationOracleLiveTest { +class SpringOraclePoolingApplicationOracleLiveTest { @Autowired private DataSource dataSource; - @Test - public void givenOracleConfiguration_thenBuildsOracleDataSource() { + @Test + void givenOracleConfiguration_thenBuildsOracleDataSource() { assertTrue(dataSource instanceof oracle.jdbc.pool.OracleDataSource); } diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleUCPLiveTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleUCPLiveTest.java index 6ef780fcef..35f2a1bd3b 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleUCPLiveTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/spring/oracle/pooling/SpringOraclePoolingApplicationOracleUCPLiveTest.java @@ -4,15 +4,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = {SpringOraclePoolingApplication.class}) @ActiveProfiles({"oracle-pooling-basic"}) @TestPropertySource(properties = "spring.datasource.type=oracle.ucp.jdbc.PoolDataSource") @@ -21,7 +18,7 @@ public class SpringOraclePoolingApplicationOracleUCPLiveTest { @Autowired private DataSource dataSource; - @Test + @Test public void givenOracleUCPConfiguration_thenBuildsOraclePoolDataSource() { assertTrue(dataSource instanceof oracle.ucp.jdbc.PoolDataSource); } diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/springboothsqldb/application/tests/CustomerControllerIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/springboothsqldb/application/tests/CustomerControllerIntegrationTest.java index bdd9a19b68..0709f1814a 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/springboothsqldb/application/tests/CustomerControllerIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/springboothsqldb/application/tests/CustomerControllerIntegrationTest.java @@ -1,13 +1,8 @@ package com.baeldung.springboothsqldb.application.tests; -import com.baeldung.springboothsqldb.application.entities.Customer; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.SerializationFeature; -import java.nio.charset.Charset; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -17,23 +12,27 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -@RunWith(SpringRunner.class) +import com.baeldung.springboothsqldb.application.entities.Customer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.fasterxml.jackson.databind.SerializationFeature; + @SpringBootTest @AutoConfigureMockMvc -public class CustomerControllerIntegrationTest { +class CustomerControllerIntegrationTest { private static MediaType MEDIA_TYPE_JSON; @Autowired private MockMvc mockMvc; - @Before - public void setUpJsonMediaType() { + @BeforeEach + void setUpJsonMediaType() { MEDIA_TYPE_JSON = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype()); } @Test - public void whenPostHttpRequesttoCustomers_thenStatusOK() throws Exception { + void whenPostHttpRequesttoCustomers_thenStatusOK() throws Exception { Customer customer = new Customer("John", "john@domain.com"); ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); @@ -50,7 +49,7 @@ public class CustomerControllerIntegrationTest { } @Test - public void whenGetHttpRequesttoCustomers_thenStatusOK() throws Exception { + void whenGetHttpRequesttoCustomers_thenStatusOK() throws Exception { this.mockMvc .perform(MockMvcRequestBuilders.get("/customers")) diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/states/UserEntityIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/states/UserEntityIntegrationTest.java index 0ce3ff34ce..ddc81446c1 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/states/UserEntityIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/states/UserEntityIntegrationTest.java @@ -1,20 +1,17 @@ package com.baeldung.states; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import jakarta.persistence.EntityManagerFactory; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -@RunWith(SpringRunner.class) @SpringBootTest class UserEntityIntegrationTest { @Autowired diff --git a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java index 4422c27150..e9ca90b008 100644 --- a/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-2/src/test/java/com/baeldung/tomcatconnectionpool/test/application/SpringBootTomcatConnectionPoolIntegrationTest.java @@ -1,27 +1,25 @@ package com.baeldung.tomcatconnectionpool.test.application; +import static org.assertj.core.api.Assertions.assertThat; + import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.tomcatconnectionpool.application.SpringBootConsoleApplication; -import static org.assertj.core.api.Assertions.*; -import org.springframework.boot.test.context.SpringBootTest; - -@RunWith(SpringRunner.class) @SpringBootTest(classes = {SpringBootConsoleApplication.class}) @TestPropertySource(properties = "spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource") -public class SpringBootTomcatConnectionPoolIntegrationTest { +class SpringBootTomcatConnectionPoolIntegrationTest { @Autowired private DataSource dataSource; @Test - public void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() { + void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() { assertThat(dataSource.getClass().getName()).isEqualTo("org.apache.tomcat.jdbc.pool.DataSource"); } }