gh-2217 converted all Junit 4 test cases to Junit 5 (#2218)

* gh-2217 converted all Junit 4 test cases to Junit 5

* Added the junit platform launcher in the test scope to fix unit test case issues

* added the Junit platform launcher in test scope.
This commit is contained in:
Krishna
2023-02-01 20:44:08 +05:30
committed by GitHub
parent 3fcf9ac6f3
commit b66f23b03b
108 changed files with 833 additions and 938 deletions

View File

@@ -19,10 +19,9 @@ package sample;
import java.io.IOException;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -32,7 +31,6 @@ import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,7 +45,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
*
* @author Spencer Gibb
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config
@@ -67,7 +64,7 @@ public class ApplicationBootstrapTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
System.setProperty("spring.cloud.bootstrap.name", "bootstrapservercomposite");
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
@@ -80,7 +77,7 @@ public class ApplicationBootstrapTests {
System.setProperty("config.port", "" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("config.port");
System.clearProperty("spring.cloud.bootstrap.name");

View File

@@ -19,10 +19,9 @@ package sample;
import java.io.IOException;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -31,13 +30,11 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -57,7 +54,7 @@ public class ApplicationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -71,7 +68,7 @@ public class ApplicationTests {
System.setProperty("config.port", "" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("config.port");
if (server != null) {

View File

@@ -18,10 +18,9 @@ package sample;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
@@ -34,13 +33,11 @@ import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -62,7 +59,7 @@ public class ConfigDataCustomMediaTypeIntegrationTests {
@Autowired
ConfigurableEnvironment env;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -73,7 +70,7 @@ public class ConfigDataCustomMediaTypeIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -19,10 +19,9 @@ package sample;
import java.io.IOException;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -31,13 +30,11 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -56,7 +53,7 @@ public class ConfigDataIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -67,7 +64,7 @@ public class ConfigDataIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -18,10 +18,9 @@ package sample;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -31,13 +30,11 @@ import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -58,7 +55,7 @@ public class ConfigDataOrderingIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() {
server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class,
"--spring.profiles.active=native", "--server.port=" + configPort, "--spring.config.name=server");
@@ -66,7 +63,7 @@ public class ConfigDataOrderingIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -22,10 +22,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -37,7 +36,6 @@ import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@@ -46,7 +44,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -66,7 +63,7 @@ public class ConfigDataRetryIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -76,7 +73,7 @@ public class ConfigDataRetryIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -18,10 +18,9 @@ package sample;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
@@ -30,12 +29,10 @@ import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, properties = "spring.application.name:bad", webEnvironment = RANDOM_PORT)
public class ServerNativeApplicationTests {
@@ -49,7 +46,7 @@ public class ServerNativeApplicationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String repo = ConfigServerTestUtils.prepareLocalRepo();
server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class,
@@ -62,7 +59,7 @@ public class ServerNativeApplicationTests {
System.setProperty("config.port", "" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("config.port");
if (server != null) {