Migrate ModifiedClassPath tests to JUnit 5
Migrate the remaining JUnit 4 tests to JUnit 5, making use of the new `ModifiedClassPathExtension`. See gh-17491
This commit is contained in:
@@ -18,15 +18,15 @@ package org.springframework.boot.test.autoconfigure.orm.jpa;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathExtension;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -40,16 +40,16 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ExtendWith(ModifiedClassPathExtension.class)
|
||||
@ClassPathExclusions({ "h2-*.jar", "hsqldb-*.jar", "derby-*.jar" })
|
||||
public class TestDatabaseAutoConfigurationNoEmbeddedTests {
|
||||
class TestDatabaseAutoConfigurationNoEmbeddedTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(ExistingDataSourceConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void applyAnyReplace() {
|
||||
void applyAnyReplace() {
|
||||
this.contextRunner.run((context) -> assertThat(context).getFailure().isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("Failed to replace DataSource with an embedded database for tests.")
|
||||
.hasMessageContaining("If you want an embedded database please put a supported one on the classpath")
|
||||
@@ -57,7 +57,7 @@ public class TestDatabaseAutoConfigurationNoEmbeddedTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyNoReplace() {
|
||||
void applyNoReplace() {
|
||||
this.contextRunner.withPropertyValues("spring.test.database.replace=NONE").run((context) -> {
|
||||
assertThat(context).hasSingleBean(DataSource.class);
|
||||
assertThat(context).getBean(DataSource.class).isSameAs(context.getBean("myCustomDataSource"));
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
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.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -33,12 +31,8 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@RestClientTest(ExampleRestClient.class)
|
||||
public class RestClientTestWithComponentIntegrationTests {
|
||||
|
||||
// JUnit 4 because RestClientTestWithoutJacksonIntegrationTests uses
|
||||
// ModifiedClassPathRunner
|
||||
class RestClientTestWithComponentIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockRestServiceServer server;
|
||||
@@ -47,7 +41,7 @@ public class RestClientTestWithComponentIntegrationTests {
|
||||
private ExampleRestClient client;
|
||||
|
||||
@Test
|
||||
public void mockServerCall() {
|
||||
void mockServerCall() {
|
||||
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
|
||||
assertThat(this.client.test()).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathExtension;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -35,10 +35,10 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ExtendWith(ModifiedClassPathExtension.class)
|
||||
@ClassPathExclusions("jackson-*.jar")
|
||||
@RestClientTest(ExampleRestClient.class)
|
||||
public class RestClientTestWithoutJacksonIntegrationTests {
|
||||
class RestClientTestWithoutJacksonIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private MockRestServiceServer server;
|
||||
@@ -47,7 +47,7 @@ public class RestClientTestWithoutJacksonIntegrationTests {
|
||||
private ExampleRestClient client;
|
||||
|
||||
@Test
|
||||
public void restClientTestCanBeUsedWhenJacksonIsNotOnTheClassPath() {
|
||||
void restClientTestCanBeUsedWhenJacksonIsNotOnTheClassPath() {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", classLoader)).isFalse();
|
||||
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
|
||||
|
||||
Reference in New Issue
Block a user