From 685b42e85f60fe8b7ac2dc9e0cdcb7669af765e2 Mon Sep 17 00:00:00 2001 From: Szymon Linowski Date: Sun, 1 Aug 2021 12:04:56 +0200 Subject: [PATCH] Switch remaining jUnit4 tests to jUnit jupiter --- .../openfeign/DefaultGzipDecoderTests.java | 5 +-- .../EnableFeignClientsSpringDataTests.java | 5 +-- .../openfeign/EnableFeignClientsTests.java | 13 +++--- .../FeignBuilderCustomizerTests.java | 2 +- .../openfeign/FeignClientBuilderTests.java | 17 +++----- .../FeignClientUsingConfigurerTest.java | 5 +-- .../openfeign/FeignClientsRegistrarTests.java | 29 +++++++------ .../openfeign/FeignCompressionTests.java | 5 +-- .../cloud/openfeign/FeignContextTest.java | 2 +- .../FeignErrorDecoderFactoryTests.java | 2 +- .../FeignHttpClient5ConfigurationTests.java | 6 +-- .../FeignHttpClientConfigurationTests.java | 13 +++--- .../openfeign/FeignLoggerFactoryTests.java | 2 +- .../FeignOkHttpConfigurationTests.java | 13 +++--- .../cloud/openfeign/SpringDecoderTests.java | 10 ++--- .../beans/BeansFeignClientTests.java | 5 +-- .../circuitbreaker/CircuitBreakerTests.java | 9 ++-- .../encoding/FeignAcceptEncodingTests.java | 5 +-- .../encoding/FeignContentEncodingTests.java | 5 +-- .../encoding/FeignPageableEncodingTests.java | 5 +-- .../proto/ProtobufNotInClasspathTest.java | 5 +-- .../proto/ProtobufSpringEncoderTest.java | 8 ++-- ...FeignHalAutoConfigurationContextTests.java | 6 +-- .../FeignHalAutoConfigurationTests.java | 8 ++-- .../openfeign/hateoas/FeignHalTests.java | 5 +-- .../invalid/FeignClientValidationTests.java | 13 +++--- .../OAuth2FeignRequestInterceptorTests.java | 43 +++++++++++-------- .../FeignHttpClientPropertiesTests.java | 9 ++-- .../support/PageableEncoderTests.java | 5 +-- .../openfeign/support/SpringEncoderTests.java | 12 +++--- .../support/SpringMvcContractTests.java | 17 +++++--- .../valid/FeignClientNotPrimaryTests.java | 5 +-- .../valid/FeignClientValidationTests.java | 2 +- .../valid/IterableParameterTests.java | 5 +-- .../scanning/FeignClientEnvVarTests.java | 5 +-- .../scanning/FeignClientScanningTests.java | 5 +-- 36 files changed, 124 insertions(+), 187 deletions(-) diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/DefaultGzipDecoderTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/DefaultGzipDecoderTests.java index 356412be..bc217406 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/DefaultGzipDecoderTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/DefaultGzipDecoderTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign; import java.util.Objects; -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.beans.factory.annotation.Value; @@ -31,7 +30,6 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -40,7 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Jaesik Kim */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = DefaultGzipDecoderTests.Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=defaultGzipDecoderTests", "feign.compression.response.enabled=true", diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsSpringDataTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsSpringDataTests.java index 26f55d31..f3900ac2 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsSpringDataTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsSpringDataTests.java @@ -17,8 +17,7 @@ package org.springframework.cloud.openfeign; import feign.codec.Encoder; -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.autoconfigure.EnableAutoConfiguration; @@ -26,12 +25,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.openfeign.support.PageableSpringEncoder; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Spencer Gibb */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = EnableFeignClientsSpringDataTests.PlainConfiguration.class) @DirtiesContext public class EnableFeignClientsSpringDataTests { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsTests.java index c4925dbc..6a5636e5 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/EnableFeignClientsTests.java @@ -23,17 +23,15 @@ import feign.codec.Decoder; import feign.codec.Encoder; import feign.optionals.OptionalDecoder; import feign.slf4j.Slf4jLogger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.openfeign.support.SpringEncoder; import org.springframework.cloud.openfeign.support.SpringMvcContract; import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -41,20 +39,19 @@ import org.springframework.context.annotation.Import; /** * @author Spencer Gibb */ -@RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions({ "spring-data-commons-*.jar" }) public class EnableFeignClientsTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { context = new SpringApplicationBuilder().web(WebApplicationType.NONE) .properties("debug=true", "feign.httpclient.enabled=false") .sources(EnableFeignClientsTests.PlainConfiguration.class).run(); } - @After + @AfterEach public void tearDown() { if (context != null) { context.close(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignBuilderCustomizerTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignBuilderCustomizerTests.java index 33de748d..0e3abb4d 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignBuilderCustomizerTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignBuilderCustomizerTests.java @@ -20,7 +20,7 @@ import java.lang.reflect.Field; import feign.Feign; import feign.Logger; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientBuilderTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientBuilderTests.java index c2273830..64798aa9 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientBuilderTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientBuilderTests.java @@ -25,11 +25,8 @@ import java.util.Collections; import java.util.List; import feign.Feign; -import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cloud.openfeign.testclients.TestClient; @@ -37,6 +34,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Sven Döring @@ -44,9 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class FeignClientBuilderTests { - @Rule - public ExpectedException thrown = ExpectedException.none(); - private FeignClientBuilder feignClientBuilder; private ApplicationContext applicationContext; @@ -75,7 +70,7 @@ public class FeignClientBuilderTests { return (T) ReflectionUtils.getField(field, factoryBean); } - @Before + @BeforeEach public void setUp() { this.applicationContext = Mockito.mock(ApplicationContext.class); this.feignClientBuilder = new FeignClientBuilder(this.applicationContext); @@ -170,11 +165,9 @@ public class FeignClientBuilderTests { // the // FeignClientFactoryBean final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestClient.class, "TestClient"); - // expect: 'the build will fail right after calling build() with the mocked // unusual exception' - this.thrown.expect(Matchers.isA(ClosedFileSystemException.class)); - builder.build(); + assertThatExceptionOfType(ClosedFileSystemException.class).isThrownBy(() -> builder.build()); } private interface TestFeignClient { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientUsingConfigurerTest.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientUsingConfigurerTest.java index 95456153..a530f0ca 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientUsingConfigurerTest.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientUsingConfigurerTest.java @@ -24,8 +24,7 @@ import feign.Feign; import feign.Logger; import feign.RequestInterceptor; import feign.micrometer.MicrometerCapability; -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.beans.factory.config.ConfigurableListableBeanFactory; @@ -35,7 +34,6 @@ import org.springframework.cloud.openfeign.clientconfig.FeignClientConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -45,7 +43,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Jonatan Ivanov */ @DirtiesContext -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = FeignClientUsingConfigurerTest.Application.class, value = { "feign.client.config.default.loggerLevel=full", "feign.client.config.default.requestInterceptors[0]=org.springframework.cloud.openfeign.FeignClientUsingPropertiesTests.FooRequestInterceptor", diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java index 16e86bc9..0b758dc3 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java @@ -18,7 +18,7 @@ package org.springframework.cloud.openfeign; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.GetMapping; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Spencer Gibb @@ -37,24 +38,24 @@ import static org.assertj.core.api.Assertions.assertThatCode; */ public class FeignClientsRegistrarTests { - @Test(expected = IllegalStateException.class) + @Test public void badNameHttpPrefix() { - testGetName("https://bad_hostname"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("http://bad_hostname")); } - @Test(expected = IllegalStateException.class) + @Test public void badNameHttpsPrefix() { - testGetName("https://bad_hostname"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("https://bad_hostname")); } - @Test(expected = IllegalStateException.class) + @Test public void badName() { - testGetName("bad_hostname"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("bad_hostname")); } - @Test(expected = IllegalStateException.class) + @Test public void badNameStartsWithHttp() { - testGetName("http_bad_hostname"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("http_bad_hostname")); } @Test @@ -81,14 +82,16 @@ public class FeignClientsRegistrarTests { return registrar.getName(Collections.singletonMap("name", name)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFallback() { - new AnnotationConfigApplicationContext(FallbackTestConfig.class); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new AnnotationConfigApplicationContext(FallbackTestConfig.class)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFallbackFactory() { - new AnnotationConfigApplicationContext(FallbackFactoryTestConfig.class); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new AnnotationConfigApplicationContext(FallbackFactoryTestConfig.class)); } @Test diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignCompressionTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignCompressionTests.java index 67858f11..7b52d3c0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignCompressionTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignCompressionTests.java @@ -21,8 +21,7 @@ import java.util.Map; import feign.Client; import feign.RequestInterceptor; import feign.httpclient.ApacheHttpClient; -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.autoconfigure.AutoConfigurations; @@ -33,7 +32,6 @@ import org.springframework.cloud.openfeign.encoding.FeignAcceptGzipEncodingInter import org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingAutoConfiguration; import org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingInterceptor; import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -43,7 +41,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Ryan Baxter * @author Biju Kunjummen */ -@RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar" }) public class FeignCompressionTests { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignContextTest.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignContextTest.java index 072bfef7..aed35206 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignContextTest.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignContextTest.java @@ -21,7 +21,7 @@ import java.util.Collection; import feign.Logger; import feign.RequestInterceptor; import org.assertj.core.util.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignErrorDecoderFactoryTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignErrorDecoderFactoryTests.java index c2150ea1..b8fb6c9d 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignErrorDecoderFactoryTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignErrorDecoderFactoryTests.java @@ -18,7 +18,7 @@ package org.springframework.cloud.openfeign; import feign.Response; import feign.codec.ErrorDecoder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClient5ConfigurationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClient5ConfigurationTests.java index b1a57c1a..dfca5f27 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClient5ConfigurationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClient5ConfigurationTests.java @@ -22,14 +22,12 @@ import feign.httpclient.ApacheHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; import org.apache.hc.client5.http.io.HttpClientConnectionManager; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.commons.httpclient.HttpClientConfiguration; import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; import org.springframework.context.ConfigurableApplicationContext; import static org.assertj.core.api.Assertions.assertThat; @@ -59,7 +57,6 @@ public class FeignHttpClient5ConfigurationTests { assertThat(client).isInstanceOf(ApacheHttp5Client.class); } - @RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions("ribbon-loadbalancer-{version:\\d.*}.jar") public static class WithoutLoadBalancerInClasspath { @@ -108,7 +105,6 @@ public class FeignHttpClient5ConfigurationTests { } - @RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar", "feign-hc5-{version:\\d.*}.jar", "httpclient5-{version:\\d.*}.jar", "httpcore5-{version:\\d.*}.jar", "httpcore5-h2-{version:\\d.*}.jar" }) public static class WithoutLoadBalancerAndHc5InClasspath { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClientConfigurationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClientConfigurationTests.java index 6cd5352e..2603d77f 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClientConfigurationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttpClientConfigurationTests.java @@ -26,16 +26,14 @@ import org.apache.http.config.Lookup; import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.impl.conn.DefaultHttpClientConnectionOperator; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.commons.httpclient.HttpClientConfiguration; import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.util.ReflectionUtils; @@ -44,20 +42,19 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Ryan Baxter */ -@RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar" }) public class FeignHttpClientConfigurationTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new SpringApplicationBuilder() .properties("debug=true", "feign.httpclient.disableSslValidation=true").web(WebApplicationType.NONE) .sources(HttpClientConfiguration.class, FeignAutoConfiguration.class).run(); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignLoggerFactoryTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignLoggerFactoryTests.java index ab94972e..f13af024 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignLoggerFactoryTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignLoggerFactoryTests.java @@ -18,7 +18,7 @@ package org.springframework.cloud.openfeign; import feign.Logger; import feign.slf4j.Slf4jLogger; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignOkHttpConfigurationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignOkHttpConfigurationTests.java index 160ab1b2..0f4fa47b 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignOkHttpConfigurationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignOkHttpConfigurationTests.java @@ -21,17 +21,15 @@ import java.lang.reflect.Field; import javax.net.ssl.HostnameVerifier; import okhttp3.OkHttpClient; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.commons.httpclient.HttpClientConfiguration; import org.springframework.cloud.commons.httpclient.OkHttpClientFactory; import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.util.ReflectionUtils; @@ -40,13 +38,12 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Ryan Baxter */ -@RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar" }) public class FeignOkHttpConfigurationTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new SpringApplicationBuilder() .properties("debug=true", "feign.httpclient.disableSslValidation=true", "feign.okhttp.enabled=true", @@ -55,7 +52,7 @@ public class FeignOkHttpConfigurationTests { .run(); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java index c7d5691d..904cfc46 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/SpringDecoderTests.java @@ -21,8 +21,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -37,7 +37,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -47,7 +46,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Spencer Gibb * @author Olga Maciaszek-Sharma */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SpringDecoderTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = { "spring.application.name=springdecodertest", "spring.jmx.enabled=false" }) @DirtiesContext @@ -131,9 +129,9 @@ public class SpringDecoderTests extends FeignClientFactoryBean { assertThat(header).as("header was wrong").isEqualTo("myval"); } - @Test(expected = RuntimeException.class) + @Test public void test404() { - testClient().getNotFound(); + Assertions.assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> testClient().getNotFound()); } @Test diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/beans/BeansFeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/beans/BeansFeignClientTests.java index 326c6b02..e348527d 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/beans/BeansFeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/beans/BeansFeignClientTests.java @@ -21,8 +21,7 @@ import java.lang.reflect.Proxy; import java.util.Map; import java.util.Objects; -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.beans.factory.annotation.Qualifier; @@ -38,7 +37,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -52,7 +50,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Halvdan Hoem Grelland * @author Aaron Whiteside */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = BeansFeignClientTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = { "spring.application.name=feignclienttest", "logging.level.org.springframework.cloud.openfeign.valid=DEBUG", "feign.httpclient.enabled=false", diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java index a300c163..2a120a0b 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java @@ -20,11 +20,10 @@ import java.util.function.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -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.autoconfigure.EnableAutoConfiguration; @@ -43,7 +42,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Component; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.SocketUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -53,7 +51,6 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Spencer Gibb */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = CircuitBreakerTests.Application.class, webEnvironment = WebEnvironment.DEFINED_PORT, value = { "spring.application.name=springcircuittest", "spring.jmx.enabled=false", "feign.circuitbreaker.enabled=true" }) @DirtiesContext @@ -78,7 +75,7 @@ public class CircuitBreakerTests { System.clearProperty("server.port"); } - @Before + @BeforeEach public void setup() { this.myCircuitBreaker.clear(); } diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignAcceptEncodingTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignAcceptEncodingTests.java index 54c939cd..208eb9b3 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignAcceptEncodingTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignAcceptEncodingTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign.encoding; 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.autoconfigure.SpringBootApplication; @@ -39,7 +38,6 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; -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; @@ -51,7 +49,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen */ @SpringBootTest(classes = FeignAcceptEncodingTests.Application.class, webEnvironment = RANDOM_PORT, value = { "feign.compression.response.enabled=true" }) -@RunWith(SpringRunner.class) @DirtiesContext public class FeignAcceptEncodingTests { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignContentEncodingTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignContentEncodingTests.java index 3225f001..f6500142 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignContentEncodingTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignContentEncodingTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign.encoding; 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.autoconfigure.SpringBootApplication; @@ -38,7 +37,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -50,7 +48,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen */ @SpringBootTest(classes = FeignContentEncodingTests.Application.class, webEnvironment = RANDOM_PORT, value = { "feign.compression.request.enabled=true", "ribbon.OkToRetryOnAllOperations=false" }) -@RunWith(SpringJUnit4ClassRunner.class) public class FeignContentEncodingTests { @Autowired diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java index ecc52e37..acccf57e 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.openfeign.encoding; import java.util.List; import java.util.Optional; -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.autoconfigure.SpringBootApplication; @@ -45,7 +44,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.web.config.EnableSpringDataWebSupport; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -58,7 +56,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen */ @SpringBootTest(classes = FeignPageableEncodingTests.Application.class, webEnvironment = RANDOM_PORT, value = { "feign.compression.request.enabled=true", "feign.autoconfiguration.jackson.enabled=true" }) -@RunWith(SpringJUnit4ClassRunner.class) public class FeignPageableEncodingTests { @Autowired diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufNotInClasspathTest.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufNotInClasspathTest.java index b4cb0ea1..d7c39a37 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufNotInClasspathTest.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufNotInClasspathTest.java @@ -17,14 +17,12 @@ package org.springframework.cloud.openfeign.encoding.proto; import feign.RequestTemplate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.ObjectFactory; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.cloud.openfeign.support.SpringEncoder; import org.springframework.cloud.test.ClassPathExclusions; -import org.springframework.cloud.test.ModifiedClassPathRunner; import org.springframework.http.converter.StringHttpMessageConverter; import static feign.Request.HttpMethod.POST; @@ -34,7 +32,6 @@ import static feign.Request.HttpMethod.POST; * * @author ScienJus */ -@RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions("protobuf-*.jar") public class ProtobufNotInClasspathTest { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufSpringEncoderTest.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufSpringEncoderTest.java index 39af6b35..4a11dfa1 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufSpringEncoderTest.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/proto/ProtobufSpringEncoderTest.java @@ -35,12 +35,12 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.message.BasicHttpResponse; import org.apache.http.message.BasicStatusLine; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatchers; import org.mockito.BDDMockito; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.ObjectFactory; @@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.fail; * * @author ScienJus */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ProtobufSpringEncoderTest { @Mock diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationContextTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationContextTests.java index 570a96fd..1a54f492 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationContextTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationContextTests.java @@ -16,8 +16,8 @@ package org.springframework.cloud.openfeign.hateoas; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; @@ -38,7 +38,7 @@ public class FeignHalAutoConfigurationContextTests { private WebApplicationContextRunner contextRunner; - @Before + @BeforeEach public void setUp() { contextRunner = new WebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class, diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationTests.java index b2757760..887f1727 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalAutoConfigurationTests.java @@ -19,11 +19,11 @@ package org.springframework.cloud.openfeign.hateoas; import java.util.Collections; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -45,7 +45,7 @@ import static org.springframework.hateoas.MediaTypes.HAL_JSON; * @author Hector Espert * @author Olga Maciaszek-Sharma */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class FeignHalAutoConfigurationTests { @Mock diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalTests.java index 5f0ead98..86dd743f 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/hateoas/FeignHalTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign.hateoas; import java.util.Collection; -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; @@ -31,7 +30,6 @@ import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.Link; import org.springframework.hateoas.PagedModel; import org.springframework.test.annotation.DirtiesContext; -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; @@ -42,7 +40,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Hector Espert */ @SpringBootTest(classes = FeignHalApplication.class, webEnvironment = RANDOM_PORT, value = "debug=true") -@RunWith(SpringRunner.class) @DirtiesContext public class FeignHalTests { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/invalid/FeignClientValidationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/invalid/FeignClientValidationTests.java index 6e5960fe..36abbcf0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/invalid/FeignClientValidationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/invalid/FeignClientValidationTests.java @@ -16,9 +16,7 @@ package org.springframework.cloud.openfeign.invalid; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration; import org.springframework.cloud.commons.httpclient.HttpClientConfiguration; @@ -31,15 +29,13 @@ import org.springframework.context.annotation.Import; import org.springframework.web.bind.annotation.GetMapping; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Dave Syer */ public class FeignClientValidationTests { - @Rule - public ExpectedException expected = ExpectedException.none(); - @Test public void testServiceIdAndValue() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( @@ -61,8 +57,9 @@ public class FeignClientValidationTests { @Test public void testNotLegalHostname() { - this.expected.expectMessage("not legal hostname (foo_bar)"); - new AnnotationConfigApplicationContext(BadHostnameConfiguration.class); + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> new AnnotationConfigApplicationContext(BadHostnameConfiguration.class)) + .withMessage("Service id not legal hostname (foo_bar)"); } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/security/OAuth2FeignRequestInterceptorTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/security/OAuth2FeignRequestInterceptorTests.java index b0c06f41..bdc7770a 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/security/OAuth2FeignRequestInterceptorTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/security/OAuth2FeignRequestInterceptorTests.java @@ -21,9 +21,9 @@ import java.util.Map; import feign.Request.HttpMethod; import feign.RequestTemplate; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; import org.springframework.security.oauth2.client.OAuth2ClientContext; @@ -32,8 +32,7 @@ import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedExc import org.springframework.security.oauth2.client.token.AccessTokenRequest; import org.springframework.security.oauth2.common.OAuth2AccessToken; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.hasSize; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -47,7 +46,7 @@ public class OAuth2FeignRequestInterceptorTests { private RequestTemplate requestTemplate; - @Before + @BeforeEach public void setUp() { oAuth2FeignRequestInterceptor = new OAuth2FeignRequestInterceptor(new MockOAuth2ClientContext("Fancy"), new BaseOAuth2ProtectedResourceDetails()); @@ -58,25 +57,32 @@ public class OAuth2FeignRequestInterceptorTests { public void applyAuthorizationHeader() { oAuth2FeignRequestInterceptor.apply(requestTemplate); Map> headers = requestTemplate.headers(); - Assert.assertTrue("RequestTemplate must have a Authorization header", headers.containsKey("Authorization")); - Assert.assertThat("Authorization must have a extract of Fancy", headers.get("Authorization"), - contains("Bearer Fancy")); + + assertThat(headers.containsKey("Authorization")).describedAs("RequestTemplate must have a Authorization header") + .isTrue(); + assertThat(headers.containsKey("Authorization")).describedAs("RequestTemplate must have a Authorization header") + .isTrue(); + Assertions.assertThat(headers.get("Authorization")).describedAs("Authorization must have a extract of Fancy") + .contains("Bearer Fancy"); } - @Test(expected = OAuth2AccessDeniedException.class) + @Test public void tryToAcquireToken() { oAuth2FeignRequestInterceptor = new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), new BaseOAuth2ProtectedResourceDetails()); - OAuth2AccessToken oAuth2AccessToken = oAuth2FeignRequestInterceptor.getToken(); - Assert.assertTrue(oAuth2AccessToken.getValue() + " Must be null", oAuth2AccessToken.getValue() == null); + + Assertions.assertThatExceptionOfType(OAuth2AccessDeniedException.class) + .isThrownBy(() -> oAuth2FeignRequestInterceptor.getToken()).withMessage( + "Unable to obtain a new access token for resource 'null'. The provider manager is not configured to support it."); } @Test public void configureAccessTokenProvider() { OAuth2AccessToken mockedToken = new MockOAuth2AccessToken("MOCKED_TOKEN"); oAuth2FeignRequestInterceptor.setAccessTokenProvider(new MockAccessTokenProvider(mockedToken)); - Assert.assertEquals("Should return same mocked token instance", mockedToken, - oAuth2FeignRequestInterceptor.acquireAccessToken()); + + assertThat(oAuth2FeignRequestInterceptor.acquireAccessToken()) + .describedAs("Should return same mocked token instance").isEqualTo(mockedToken); } @Test @@ -103,10 +109,11 @@ public class OAuth2FeignRequestInterceptorTests { oAuth2FeignRequestInterceptor.apply(requestTemplate); Map> headers = requestTemplate.headers(); - Assert.assertTrue("RequestTemplate must have a Authorization header", headers.containsKey("Authorization")); - Assert.assertThat("Authorization must have a extract of Fancy", headers.get("Authorization"), hasSize(1)); - Assert.assertThat("Authorization must have a extract of Fancy", headers.get("Authorization"), - contains("Bearer Fancy")); + assertThat(headers.containsKey("Authorization")).describedAs("RequestTemplate must have a Authorization header") + .isTrue(); + assertThat(headers.get("Authorization")).describedAs("Authorization must have a extract of Fancy").hasSize(1); + assertThat(headers.get("Authorization")).describedAs("Authorization must have a extract of Fancy") + .contains("Bearer Fancy"); } } diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/FeignHttpClientPropertiesTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/FeignHttpClientPropertiesTests.java index 0835b322..7c19d0ba 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/FeignHttpClientPropertiesTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/FeignHttpClientPropertiesTests.java @@ -18,9 +18,8 @@ package org.springframework.cloud.openfeign.support; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -31,7 +30,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.cloud.openfeign.support.FeignHttpClientProperties.Hc5Properties.DEFAULT_SOCKET_TIMEOUT; @@ -41,13 +39,12 @@ import static org.springframework.cloud.openfeign.support.FeignHttpClientPropert * @author Ryan Baxter * @author Nguyen Ky Thanh */ -@RunWith(SpringRunner.class) @DirtiesContext public class FeignHttpClientPropertiesTests { private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - @After + @AfterEach public void clear() { if (this.context != null) { this.context.close(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/PageableEncoderTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/PageableEncoderTests.java index 15ff0c53..bca3d7e1 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/PageableEncoderTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/PageableEncoderTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign.support; import feign.RequestTemplate; import feign.codec.Encoder; -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; @@ -28,7 +27,6 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -38,7 +36,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * * @author Charlie Mordant. */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SpringEncoderTests.Application.class, webEnvironment = RANDOM_PORT, value = { "spring.application.name=springencodertest", "spring.jmx.enabled=false" }) @DirtiesContext diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java index 600d2e88..9ff4c41b 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java @@ -26,8 +26,8 @@ import java.util.List; import feign.RequestTemplate; import feign.codec.EncodeException; import feign.codec.Encoder; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -52,7 +52,6 @@ import org.springframework.http.converter.HttpMessageNotWritableException; import org.springframework.http.converter.ResourceHttpMessageConverter; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -71,7 +70,6 @@ import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE; * @author Ahmad Mozafarnia * @author Can Bezmen */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SpringEncoderTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = { "spring.application.name=springencodertest", "spring.jmx.enabled=false" }) @DirtiesContext @@ -147,14 +145,16 @@ public class SpringEncoderTests { .isEqualTo(APPLICATION_OCTET_STREAM_VALUE); } - @Test(expected = EncodeException.class) + @Test public void testMultipartFile1() { Encoder encoder = this.context.getInstance("foo", Encoder.class); assertThat(encoder).isNotNull(); RequestTemplate request = new RequestTemplate(); MultipartFile multipartFile = new MockMultipartFile("test_multipart_file", "hi".getBytes()); - encoder.encode(multipartFile, MultipartFile.class, request); + + Assertions.assertThatExceptionOfType(EncodeException.class) + .isThrownBy(() -> encoder.encode(multipartFile, MultipartFile.class, request)); } // gh-105, gh-107 diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java index 7f6d7ad7..fbff0769 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java @@ -31,8 +31,8 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonAutoDetect; import feign.MethodMetadata; import feign.Param; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.openfeign.CollectionFormat; import org.springframework.cloud.openfeign.SpringQueryMap; @@ -63,6 +63,7 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; import static feign.CollectionFormat.SSV; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.Assume.assumeTrue; /** @@ -113,7 +114,7 @@ public class SpringMvcContractTests { return false; } - @Before + @BeforeEach public void setup() { contract = new SpringMvcContract(Collections.emptyList(), getConversionService()); } @@ -485,11 +486,12 @@ public class SpringMvcContractTests { assertThat(headers.get("aHeader").iterator().next()).isEqualTo("{aHeader}"); } - @Test(expected = IllegalStateException.class) + @Test public void testProcessHeaderMapMoreThanOnce() throws Exception { Method method = TestTemplate_HeaderMap.class.getDeclaredMethod("headerMapMoreThanOnce", MultiValueMap.class, MultiValueMap.class); - contract.parseAndValidateMetadata(method.getDeclaringClass(), method); + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> contract.parseAndValidateMetadata(method.getDeclaringClass(), method)); } @Test @@ -516,11 +518,12 @@ public class SpringMvcContractTests { assertThat(params.get("aParam").iterator().next()).isEqualTo("{aParam}"); } - @Test(expected = IllegalStateException.class) + @Test public void testProcessQueryMapMoreThanOnce() throws Exception { Method method = TestTemplate_QueryMap.class.getDeclaredMethod("queryMapMoreThanOnce", MultiValueMap.class, MultiValueMap.class); - contract.parseAndValidateMetadata(method.getDeclaringClass(), method); + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> contract.parseAndValidateMetadata(method.getDeclaringClass(), method)); } @Test diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientNotPrimaryTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientNotPrimaryTests.java index 6bc5f78a..1e036730 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientNotPrimaryTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientNotPrimaryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.openfeign.valid; import java.util.List; import feign.Logger; -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.autoconfigure.EnableAutoConfiguration; @@ -36,7 +35,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -47,7 +45,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Spencer Gibb * @author Jakub Narloch */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = FeignClientNotPrimaryTests.Application.class, webEnvironment = RANDOM_PORT, value = { "spring.application.name=feignclientnotprimarytest", "logging.level.org.springframework.cloud.openfeign.valid=DEBUG", "feign.httpclient.enabled=false", diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientValidationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientValidationTests.java index e94e6bbd..a70111fc 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientValidationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientValidationTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.openfeign.valid; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration; import org.springframework.cloud.commons.httpclient.HttpClientConfiguration; diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/IterableParameterTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/IterableParameterTests.java index 2e963a97..4d017f43 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/IterableParameterTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/IterableParameterTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign.valid; import io.vavr.collection.HashSet; import io.vavr.collection.Set; -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.autoconfigure.EnableAutoConfiguration; @@ -37,7 +36,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -47,7 +45,6 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Spencer Gibb */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = IterableParameterTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = { "spring.application.name=iterableparametertest", "logging.level.org.springframework.cloud.openfeign.valid=DEBUG", "feign.httpclient.enabled=false", diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientEnvVarTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientEnvVarTests.java index a6160e76..3d734724 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientEnvVarTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientEnvVarTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.openfeign.valid.scanning; -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.autoconfigure.EnableAutoConfiguration; @@ -34,7 +33,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -44,7 +42,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Ryan Baxter */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = FeignClientEnvVarTests.Application.class, webEnvironment = RANDOM_PORT, value = { "spring.application.name=feignclienttest", "feign.httpclient.enabled=false", "basepackage=org.springframework.cloud.openfeign.testclients" }) diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientScanningTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientScanningTests.java index 1f4b9721..7e438165 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientScanningTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/scanning/FeignClientScanningTests.java @@ -17,8 +17,7 @@ package org.springframework.cloud.openfeign.valid.scanning; import feign.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.beans.factory.annotation.Value; @@ -36,7 +35,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -46,7 +44,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Spencer Gibb */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = FeignClientScanningTests.Application.class, webEnvironment = RANDOM_PORT, value = { "spring.application.name=feignclienttest", "feign.httpclient.enabled=false" }) @DirtiesContext