Migrate to Mockito.mock(T...) where feasible
This commit is contained in:
@@ -77,8 +77,8 @@ public class DispatcherHandlerTests {
|
||||
|
||||
@Test
|
||||
void preFlightRequest() {
|
||||
WebHandler webHandler = mock(WebHandler.class);
|
||||
HandlerMapping handlerMapping = mock(HandlerMapping.class);
|
||||
WebHandler webHandler = mock();
|
||||
HandlerMapping handlerMapping = mock();
|
||||
given((handlerMapping).getHandler(any())).willReturn(Mono.just(webHandler));
|
||||
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
@@ -132,7 +132,7 @@ public class DelegatingWebFluxConfigurationTests {
|
||||
|
||||
@Test
|
||||
void webSocketService() {
|
||||
WebSocketService service = mock(WebSocketService.class);
|
||||
WebSocketService service = mock();
|
||||
given(webFluxConfigurer.getWebSocketService()).willReturn(service);
|
||||
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ResourceHandlerRegistry}.
|
||||
@@ -126,10 +127,10 @@ class ResourceHandlerRegistryTests {
|
||||
|
||||
@Test
|
||||
void resourceChain() {
|
||||
ResourceUrlProvider resourceUrlProvider = Mockito.mock(ResourceUrlProvider.class);
|
||||
ResourceUrlProvider resourceUrlProvider = mock();
|
||||
this.registry.setResourceUrlProvider(resourceUrlProvider);
|
||||
ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
|
||||
ResourceTransformerSupport mockTransformer = Mockito.mock(ResourceTransformerSupport.class);
|
||||
ResourceResolver mockResolver = mock();
|
||||
ResourceTransformerSupport mockTransformer = mock();
|
||||
|
||||
this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);
|
||||
|
||||
@@ -189,11 +190,11 @@ class ResourceHandlerRegistryTests {
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void resourceChainWithOverrides() {
|
||||
CachingResourceResolver cachingResolver = Mockito.mock(CachingResourceResolver.class);
|
||||
VersionResourceResolver versionResolver = Mockito.mock(VersionResourceResolver.class);
|
||||
WebJarsResourceResolver webjarsResolver = Mockito.mock(WebJarsResourceResolver.class);
|
||||
CachingResourceResolver cachingResolver = mock();
|
||||
VersionResourceResolver versionResolver = mock();
|
||||
WebJarsResourceResolver webjarsResolver = mock();
|
||||
PathResourceResolver pathResourceResolver = new PathResourceResolver();
|
||||
CachingResourceTransformer cachingTransformer = Mockito.mock(CachingResourceTransformer.class);
|
||||
CachingResourceTransformer cachingTransformer = mock();
|
||||
CssLinkResourceTransformer cssLinkTransformer = new CssLinkResourceTransformer();
|
||||
|
||||
this.registration.setCacheControl(CacheControl.maxAge(3600, TimeUnit.MILLISECONDS))
|
||||
|
||||
@@ -333,7 +333,7 @@ public class WebFluxConfigurationSupportTests {
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Principal getUser() {
|
||||
return mock(Principal.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class DefaultClientRequestBuilderTests {
|
||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
||||
|
||||
ExchangeStrategies strategies = mock(ExchangeStrategies.class);
|
||||
ExchangeStrategies strategies = mock();
|
||||
given(strategies.messageWriters()).willReturn(messageWriters);
|
||||
|
||||
MockClientHttpRequest request = new MockClientHttpRequest(POST, "/");
|
||||
@@ -142,7 +142,7 @@ class DefaultClientRequestBuilderTests {
|
||||
.build();
|
||||
|
||||
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
|
||||
ExchangeStrategies strategies = mock(ExchangeStrategies.class);
|
||||
ExchangeStrategies strategies = mock();
|
||||
|
||||
result.writeTo(request, strategies).block();
|
||||
|
||||
@@ -168,7 +168,7 @@ class DefaultClientRequestBuilderTests {
|
||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
||||
|
||||
ExchangeStrategies strategies = mock(ExchangeStrategies.class);
|
||||
ExchangeStrategies strategies = mock();
|
||||
given(strategies.messageWriters()).willReturn(messageWriters);
|
||||
|
||||
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
|
||||
@@ -187,7 +187,7 @@ class DefaultClientRequestBuilderTests {
|
||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
||||
|
||||
ExchangeStrategies strategies = mock(ExchangeStrategies.class);
|
||||
ExchangeStrategies strategies = mock();
|
||||
given(strategies.messageWriters()).willReturn(messageWriters);
|
||||
|
||||
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
|
||||
@@ -207,7 +207,7 @@ class DefaultClientRequestBuilderTests {
|
||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
||||
|
||||
ExchangeStrategies strategies = mock(ExchangeStrategies.class);
|
||||
ExchangeStrategies strategies = mock();
|
||||
given(strategies.messageWriters()).willReturn(messageWriters);
|
||||
|
||||
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
|
||||
|
||||
@@ -61,20 +61,19 @@ import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||
*/
|
||||
class DefaultClientResponseTests {
|
||||
|
||||
private ClientHttpResponse mockResponse;
|
||||
private ClientHttpResponse mockResponse = mock();
|
||||
|
||||
private final HttpHeaders httpHeaders = new HttpHeaders();
|
||||
|
||||
private ExchangeStrategies mockExchangeStrategies;
|
||||
private ExchangeStrategies mockExchangeStrategies = mock();
|
||||
|
||||
private DefaultClientResponse defaultClientResponse;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void createMocks() {
|
||||
mockResponse = mock(ClientHttpResponse.class);
|
||||
void configureMocks() {
|
||||
given(mockResponse.getHeaders()).willReturn(this.httpHeaders);
|
||||
mockExchangeStrategies = mock(ExchangeStrategies.class);
|
||||
|
||||
defaultClientResponse = new DefaultClientResponse(mockResponse, mockExchangeStrategies, "", "", () -> null);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DefaultWebClientTests {
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClientResponse mockResponse = mock(ClientResponse.class);
|
||||
ClientResponse mockResponse = mock();
|
||||
when(mockResponse.statusCode()).thenReturn(HttpStatus.OK);
|
||||
when(mockResponse.bodyToMono(Void.class)).thenReturn(Mono.empty());
|
||||
given(this.exchangeFunction.exchange(this.captor.capture())).willReturn(Mono.just(mockResponse));
|
||||
@@ -380,7 +380,7 @@ public class DefaultWebClientTests {
|
||||
|
||||
@Test
|
||||
public void switchToErrorOnEmptyClientResponseMono() {
|
||||
ExchangeFunction exchangeFunction = mock(ExchangeFunction.class);
|
||||
ExchangeFunction exchangeFunction = mock();
|
||||
given(exchangeFunction.exchange(any())).willReturn(Mono.empty());
|
||||
WebClient client = WebClient.builder().baseUrl("/base").exchangeFunction(exchangeFunction).build();
|
||||
StepVerifier.create(client.get().uri("/path").retrieve().bodyToMono(Void.class))
|
||||
@@ -464,8 +464,8 @@ public class DefaultWebClientTests {
|
||||
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
|
||||
given(exchangeFunction.exchange(any())).willReturn(Mono.just(response));
|
||||
|
||||
Predicate<HttpStatusCode> predicate1 = mock(Predicate.class);
|
||||
Predicate<HttpStatusCode> predicate2 = mock(Predicate.class);
|
||||
Predicate<HttpStatusCode> predicate1 = mock();
|
||||
Predicate<HttpStatusCode> predicate2 = mock();
|
||||
|
||||
given(predicate1.test(HttpStatus.BAD_REQUEST)).willReturn(false);
|
||||
given(predicate2.test(HttpStatus.BAD_REQUEST)).willReturn(false);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
@Test
|
||||
public void andThen() {
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ClientResponse response = mock();
|
||||
ExchangeFunction exchange = r -> Mono.just(response);
|
||||
|
||||
boolean[] filtersInvoked = new boolean[2];
|
||||
@@ -82,7 +82,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
@Test
|
||||
public void apply() {
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ClientResponse response = mock();
|
||||
ExchangeFunction exchange = r -> Mono.just(response);
|
||||
|
||||
boolean[] filterInvoked = new boolean[1];
|
||||
@@ -101,7 +101,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
@Test
|
||||
public void basicAuthenticationUsernamePassword() {
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ClientResponse response = mock();
|
||||
|
||||
ExchangeFunction exchange = r -> {
|
||||
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isTrue();
|
||||
@@ -118,7 +118,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
@Test
|
||||
public void basicAuthenticationInvalidCharacters() {
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ExchangeFunction exchange = r -> Mono.just(mock(ClientResponse.class));
|
||||
ExchangeFunction exchange = r -> Mono.just(mock());
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ExchangeFilterFunctions.basicAuthentication("foo", "\ud83d\udca9").filter(request, exchange));
|
||||
@@ -131,7 +131,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
.attributes(org.springframework.web.reactive.function.client.ExchangeFilterFunctions
|
||||
.Credentials.basicAuthenticationCredentials("foo", "bar"))
|
||||
.build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ClientResponse response = mock();
|
||||
|
||||
ExchangeFunction exchange = r -> {
|
||||
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isTrue();
|
||||
@@ -149,7 +149,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void basicAuthenticationAbsentAttributes() {
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ClientResponse response = mock();
|
||||
|
||||
ExchangeFunction exchange = r -> {
|
||||
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isFalse();
|
||||
@@ -165,7 +165,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
@Test
|
||||
public void statusHandlerMatch() {
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ClientResponse response = mock();
|
||||
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
|
||||
|
||||
ExchangeFunction exchange = r -> Mono.just(response);
|
||||
@@ -183,7 +183,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
@Test
|
||||
public void statusHandlerNoMatch() {
|
||||
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ClientResponse response = mock();
|
||||
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
|
||||
|
||||
Mono<ClientResponse> result = ExchangeFilterFunctions
|
||||
|
||||
@@ -49,7 +49,7 @@ class WebClientObservationTests {
|
||||
|
||||
private final TestObservationRegistry observationRegistry = TestObservationRegistry.create();
|
||||
|
||||
private final ExchangeFunction exchangeFunction = mock(ExchangeFunction.class);
|
||||
private final ExchangeFunction exchangeFunction = mock();
|
||||
|
||||
private final ArgumentCaptor<ClientRequest> request = ArgumentCaptor.forClass(ClientRequest.class);
|
||||
|
||||
@@ -57,7 +57,7 @@ class WebClientObservationTests {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
ClientResponse mockResponse = mock(ClientResponse.class);
|
||||
ClientResponse mockResponse = mock();
|
||||
when(mockResponse.statusCode()).thenReturn(HttpStatus.OK);
|
||||
when(mockResponse.bodyToMono(Void.class)).thenReturn(Mono.empty());
|
||||
given(this.exchangeFunction.exchange(this.request.capture())).willReturn(Mono.just(mockResponse));
|
||||
@@ -95,7 +95,7 @@ class WebClientObservationTests {
|
||||
|
||||
@Test
|
||||
void recordsObservationForErrorExchange() {
|
||||
ExchangeFunction exchangeFunction = mock(ExchangeFunction.class);
|
||||
ExchangeFunction exchangeFunction = mock();
|
||||
given(exchangeFunction.exchange(any())).willReturn(Mono.error(new IllegalStateException()));
|
||||
WebClient client = WebClient.builder().observationRegistry(observationRegistry).exchangeFunction(exchangeFunction).build();
|
||||
StepVerifier.create(client.get().uri("/path").retrieve().bodyToMono(Void.class))
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
class ClientResponseWrapperTests {
|
||||
|
||||
private ClientResponse mockResponse = mock(ClientResponse.class);
|
||||
private ClientResponse mockResponse = mock();
|
||||
|
||||
private ClientResponseWrapper wrapper = new ClientResponseWrapper(mockResponse);
|
||||
|
||||
@@ -62,7 +62,7 @@ class ClientResponseWrapperTests {
|
||||
|
||||
@Test
|
||||
void headers() {
|
||||
ClientResponse.Headers headers = mock(ClientResponse.Headers.class);
|
||||
ClientResponse.Headers headers = mock();
|
||||
given(mockResponse.headers()).willReturn(headers);
|
||||
|
||||
assertThat(wrapper.headers()).isSameAs(headers);
|
||||
@@ -71,7 +71,7 @@ class ClientResponseWrapperTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void cookies() {
|
||||
MultiValueMap<String, ResponseCookie> cookies = mock(MultiValueMap.class);
|
||||
MultiValueMap<String, ResponseCookie> cookies = mock();
|
||||
given(mockResponse.cookies()).willReturn(cookies);
|
||||
|
||||
assertThat(wrapper.cookies()).isSameAs(cookies);
|
||||
|
||||
@@ -141,15 +141,15 @@ public class DefaultRenderingResponseTests {
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||
ViewResolver viewResolver = mock(ViewResolver.class);
|
||||
View view = mock(View.class);
|
||||
ViewResolver viewResolver = mock();
|
||||
View view = mock();
|
||||
given(viewResolver.resolveViewName("view", Locale.ENGLISH)).willReturn(Mono.just(view));
|
||||
given(view.render(model, null, exchange)).willReturn(Mono.empty());
|
||||
|
||||
List<ViewResolver> viewResolvers = new ArrayList<>();
|
||||
viewResolvers.add(viewResolver);
|
||||
|
||||
HandlerStrategies mockConfig = mock(HandlerStrategies.class);
|
||||
HandlerStrategies mockConfig = mock();
|
||||
given(mockConfig.viewResolvers()).willReturn(viewResolvers);
|
||||
|
||||
StepVerifier.create(result)
|
||||
@@ -172,18 +172,18 @@ public class DefaultRenderingResponseTests {
|
||||
MediaType contentType = MediaType.APPLICATION_PDF;
|
||||
exchange.getResponse().getHeaders().setContentType(contentType);
|
||||
|
||||
ViewResolver viewResolver = mock(ViewResolver.class);
|
||||
RedirectView view = mock(RedirectView.class);
|
||||
ViewResolver viewResolver = mock();
|
||||
RedirectView view = mock();
|
||||
given(viewResolver.resolveViewName(eq("view"), any())).willReturn(Mono.just(view));
|
||||
given(view.render(model, contentType, exchange)).willReturn(Mono.empty());
|
||||
|
||||
List<ViewResolver> viewResolvers = new ArrayList<>();
|
||||
viewResolvers.add(viewResolver);
|
||||
|
||||
HandlerStrategies mockConfig = mock(HandlerStrategies.class);
|
||||
HandlerStrategies mockConfig = mock();
|
||||
given(mockConfig.viewResolvers()).willReturn(viewResolvers);
|
||||
|
||||
ServerResponse.Context context = mock(ServerResponse.Context.class);
|
||||
ServerResponse.Context context = mock();
|
||||
given(context.viewResolvers()).willReturn(viewResolvers);
|
||||
|
||||
Mono<Void> result = renderingResponse.writeTo(exchange, context);
|
||||
@@ -200,13 +200,13 @@ public class DefaultRenderingResponseTests {
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||
TestView view = new TestView();
|
||||
ViewResolver viewResolver = mock(ViewResolver.class);
|
||||
ViewResolver viewResolver = mock();
|
||||
given(viewResolver.resolveViewName(any(), any())).willReturn(Mono.just(view));
|
||||
|
||||
List<ViewResolver> viewResolvers = new ArrayList<>();
|
||||
viewResolvers.add(viewResolver);
|
||||
|
||||
ServerResponse.Context context = mock(ServerResponse.Context.class);
|
||||
ServerResponse.Context context = mock();
|
||||
given(context.viewResolvers()).willReturn(viewResolvers);
|
||||
|
||||
StepVerifier.create(result.flatMap(response -> response.writeTo(exchange, context)))
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -39,22 +38,15 @@ import static org.mockito.Mockito.mock;
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class HeadersWrapperTests {
|
||||
class HeadersWrapperTests {
|
||||
|
||||
private ServerRequest.Headers mockHeaders;
|
||||
private ServerRequest.Headers mockHeaders = mock();
|
||||
|
||||
private ServerRequestWrapper.HeadersWrapper wrapper;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void createWrapper() {
|
||||
mockHeaders = mock(ServerRequest.Headers.class);
|
||||
wrapper = new ServerRequestWrapper.HeadersWrapper(mockHeaders);
|
||||
}
|
||||
private ServerRequestWrapper.HeadersWrapper wrapper = new ServerRequestWrapper.HeadersWrapper(mockHeaders);
|
||||
|
||||
|
||||
@Test
|
||||
public void accept() {
|
||||
void accept() {
|
||||
List<MediaType> accept = Collections.singletonList(MediaType.APPLICATION_JSON);
|
||||
given(mockHeaders.accept()).willReturn(accept);
|
||||
|
||||
@@ -62,7 +54,7 @@ public class HeadersWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptCharset() {
|
||||
void acceptCharset() {
|
||||
List<Charset> acceptCharset = Collections.singletonList(StandardCharsets.UTF_8);
|
||||
given(mockHeaders.acceptCharset()).willReturn(acceptCharset);
|
||||
|
||||
@@ -70,7 +62,7 @@ public class HeadersWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLength() {
|
||||
void contentLength() {
|
||||
OptionalLong contentLength = OptionalLong.of(42L);
|
||||
given(mockHeaders.contentLength()).willReturn(contentLength);
|
||||
|
||||
@@ -78,7 +70,7 @@ public class HeadersWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentType() {
|
||||
void contentType() {
|
||||
Optional<MediaType> contentType = Optional.of(MediaType.APPLICATION_JSON);
|
||||
given(mockHeaders.contentType()).willReturn(contentType);
|
||||
|
||||
@@ -86,7 +78,7 @@ public class HeadersWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void host() {
|
||||
void host() {
|
||||
InetSocketAddress host = InetSocketAddress.createUnresolved("example.com", 42);
|
||||
given(mockHeaders.host()).willReturn(host);
|
||||
|
||||
@@ -94,7 +86,7 @@ public class HeadersWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void range() {
|
||||
void range() {
|
||||
List<HttpRange> range = Collections.singletonList(HttpRange.createByteRange(42));
|
||||
given(mockHeaders.range()).willReturn(range);
|
||||
|
||||
@@ -102,7 +94,7 @@ public class HeadersWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void header() {
|
||||
void header() {
|
||||
String name = "foo";
|
||||
List<String> value = Collections.singletonList("bar");
|
||||
given(mockHeaders.header(name)).willReturn(value);
|
||||
@@ -111,7 +103,7 @@ public class HeadersWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asHttpHeaders() {
|
||||
void asHttpHeaders() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
given(mockHeaders.asHttpHeaders()).willReturn(httpHeaders);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class RouterFunctionsTests {
|
||||
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
RequestPredicate requestPredicate = mock();
|
||||
given(requestPredicate.test(request)).willReturn(true);
|
||||
|
||||
RouterFunction<ServerResponse>
|
||||
@@ -77,7 +77,7 @@ class RouterFunctionsTests {
|
||||
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
RequestPredicate requestPredicate = mock();
|
||||
given(requestPredicate.test(request)).willReturn(false);
|
||||
|
||||
RouterFunction<ServerResponse> result = RouterFunctions.route(requestPredicate, handlerFunction);
|
||||
@@ -96,7 +96,7 @@ class RouterFunctionsTests {
|
||||
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
RequestPredicate requestPredicate = mock();
|
||||
given(requestPredicate.nest(request)).willReturn(Optional.of(request));
|
||||
|
||||
RouterFunction<ServerResponse> result = RouterFunctions.nest(requestPredicate, routerFunction);
|
||||
@@ -116,7 +116,7 @@ class RouterFunctionsTests {
|
||||
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
|
||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
RequestPredicate requestPredicate = mock();
|
||||
given(requestPredicate.nest(request)).willReturn(Optional.empty());
|
||||
|
||||
RouterFunction<ServerResponse> result = RouterFunctions.nest(requestPredicate, routerFunction);
|
||||
|
||||
@@ -42,20 +42,20 @@ import static org.mockito.Mockito.mock;
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class ServerRequestWrapperTests {
|
||||
class ServerRequestWrapperTests {
|
||||
|
||||
private final ServerRequest mockRequest = mock(ServerRequest.class);
|
||||
private final ServerRequest mockRequest = mock();
|
||||
|
||||
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
|
||||
|
||||
|
||||
@Test
|
||||
public void request() {
|
||||
void request() {
|
||||
assertThat(wrapper.request()).isSameAs(mockRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void method() {
|
||||
void method() {
|
||||
HttpMethod method = HttpMethod.POST;
|
||||
given(mockRequest.method()).willReturn(method);
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uri() {
|
||||
void uri() {
|
||||
URI uri = URI.create("https://example.com");
|
||||
given(mockRequest.uri()).willReturn(uri);
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void path() {
|
||||
void path() {
|
||||
String path = "/foo/bar";
|
||||
given(mockRequest.path()).willReturn(path);
|
||||
|
||||
@@ -79,15 +79,15 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headers() {
|
||||
ServerRequest.Headers headers = mock(ServerRequest.Headers.class);
|
||||
void headers() {
|
||||
ServerRequest.Headers headers = mock();
|
||||
given(mockRequest.headers()).willReturn(headers);
|
||||
|
||||
assertThat(wrapper.headers()).isSameAs(headers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attribute() {
|
||||
void attribute() {
|
||||
String name = "foo";
|
||||
String value = "bar";
|
||||
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
|
||||
@@ -96,7 +96,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParam() {
|
||||
void queryParam() {
|
||||
String name = "foo";
|
||||
String value = "bar";
|
||||
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
|
||||
@@ -105,7 +105,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParams() {
|
||||
void queryParams() {
|
||||
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
|
||||
value.add("foo", "bar");
|
||||
given(mockRequest.queryParams()).willReturn(value);
|
||||
@@ -114,7 +114,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathVariable() {
|
||||
void pathVariable() {
|
||||
String name = "foo";
|
||||
String value = "bar";
|
||||
given(mockRequest.pathVariable(name)).willReturn(value);
|
||||
@@ -123,7 +123,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathVariables() {
|
||||
void pathVariables() {
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
given(mockRequest.pathVariables()).willReturn(pathVariables);
|
||||
|
||||
@@ -132,15 +132,15 @@ public class ServerRequestWrapperTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void cookies() {
|
||||
MultiValueMap<String, HttpCookie> cookies = mock(MultiValueMap.class);
|
||||
void cookies() {
|
||||
MultiValueMap<String, HttpCookie> cookies = mock();
|
||||
given(mockRequest.cookies()).willReturn(cookies);
|
||||
|
||||
assertThat(wrapper.cookies()).isSameAs(cookies);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bodyExtractor() {
|
||||
void bodyExtractor() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
|
||||
given(mockRequest.body(extractor)).willReturn(result);
|
||||
@@ -149,7 +149,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoClass() {
|
||||
void bodyToMonoClass() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
given(mockRequest.bodyToMono(String.class)).willReturn(result);
|
||||
|
||||
@@ -157,7 +157,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoParameterizedTypeReference() {
|
||||
void bodyToMonoParameterizedTypeReference() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
|
||||
given(mockRequest.bodyToMono(reference)).willReturn(result);
|
||||
@@ -166,7 +166,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxClass() {
|
||||
void bodyToFluxClass() {
|
||||
Flux<String> result = Flux.just("foo");
|
||||
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
|
||||
|
||||
@@ -174,7 +174,7 @@ public class ServerRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxParameterizedTypeReference() {
|
||||
void bodyToFluxParameterizedTypeReference() {
|
||||
Flux<String> result = Flux.just("foo");
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
|
||||
given(mockRequest.bodyToFlux(reference)).willReturn(result);
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.List;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
@@ -34,6 +33,7 @@ import org.springframework.web.reactive.resource.GzipSupport.GzippedFiles;
|
||||
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get;
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ public class CachingResourceResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveResourceInternalFromCache() {
|
||||
Resource expected = Mockito.mock(Resource.class);
|
||||
Resource expected = mock();
|
||||
this.cache.put(resourceKey("bar.css"), expected);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
||||
@@ -165,8 +165,8 @@ public class CachingResourceResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveResourceMatchingEncoding() {
|
||||
Resource resource = Mockito.mock(Resource.class);
|
||||
Resource gzipped = Mockito.mock(Resource.class);
|
||||
Resource resource = mock();
|
||||
Resource gzipped = mock();
|
||||
this.cache.put(resourceKey("bar.css"), resource);
|
||||
this.cache.put(resourceKey("bar.css+encoding=gzip"), gzipped);
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Map;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -34,6 +33,9 @@ import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get;
|
||||
|
||||
/**
|
||||
@@ -113,7 +115,7 @@ class CssLinkResourceTransformerTests {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/external.css"));
|
||||
|
||||
List<ResourceTransformer> transformers = Collections.singletonList(new CssLinkResourceTransformer());
|
||||
ResourceResolverChain mockChain = Mockito.mock(DefaultResourceResolverChain.class);
|
||||
ResourceResolverChain mockChain = mock();
|
||||
ResourceTransformerChain chain = new DefaultResourceTransformerChain(mockChain, transformers);
|
||||
|
||||
Resource resource = getResource("external.css");
|
||||
@@ -132,9 +134,9 @@ class CssLinkResourceTransformerTests {
|
||||
.verify();
|
||||
|
||||
List<Resource> locations = Collections.singletonList(resource);
|
||||
Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("https://example.org/fonts/css", locations);
|
||||
Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("file:///home/spring/image.png", locations);
|
||||
Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("//example.org/style.css", locations);
|
||||
verify(mockChain, never()).resolveUrlPath("https://example.org/fonts/css", locations);
|
||||
verify(mockChain, never()).resolveUrlPath("file:///home/spring/image.png", locations);
|
||||
verify(mockChain, never()).resolveUrlPath("//example.org/style.css", locations);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -304,10 +304,10 @@ class ResourceWebHandlerTests {
|
||||
|
||||
// Use mock ResourceResolver: i.e. we're only testing upfront validations...
|
||||
|
||||
Resource resource = mock(Resource.class);
|
||||
Resource resource = mock();
|
||||
given(resource.getFilename()).willThrow(new AssertionError("Resource should not be resolved"));
|
||||
given(resource.getInputStream()).willThrow(new AssertionError("Resource should not be resolved"));
|
||||
ResourceResolver resolver = mock(ResourceResolver.class);
|
||||
ResourceResolver resolver = mock();
|
||||
given(resolver.resolveResource(any(), any(), any(), any())).willReturn(Mono.just(resource));
|
||||
|
||||
ResourceWebHandler handler = new ResourceWebHandler();
|
||||
|
||||
@@ -17,13 +17,11 @@
|
||||
package org.springframework.web.reactive.resource;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -42,33 +40,26 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link VersionResourceResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class VersionResourceResolverTests {
|
||||
class VersionResourceResolverTests {
|
||||
|
||||
private List<Resource> locations;
|
||||
private List<Resource> locations = List.of(
|
||||
new ClassPathResource("test/", getClass()),
|
||||
new ClassPathResource("testalternatepath/", getClass()));
|
||||
|
||||
private VersionResourceResolver resolver;
|
||||
private ResourceResolverChain chain = mock();
|
||||
|
||||
private ResourceResolverChain chain;
|
||||
private VersionStrategy versionStrategy = mock();
|
||||
|
||||
private VersionStrategy versionStrategy;
|
||||
private VersionResourceResolver resolver = new VersionResourceResolver();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.locations = new ArrayList<>();
|
||||
this.locations.add(new ClassPathResource("test/", getClass()));
|
||||
this.locations.add(new ClassPathResource("testalternatepath/", getClass()));
|
||||
|
||||
this.resolver = new VersionResourceResolver();
|
||||
this.chain = mock(ResourceResolverChain.class);
|
||||
this.versionStrategy = mock(VersionStrategy.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceExisting() {
|
||||
void resolveResourceExisting() {
|
||||
String file = "bar.css";
|
||||
Resource expected = new ClassPathResource("test/" + file, getClass());
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.just(expected));
|
||||
@@ -84,7 +75,7 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceNoVersionStrategy() {
|
||||
void resolveResourceNoVersionStrategy() {
|
||||
String file = "missing.css";
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
@@ -98,7 +89,7 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceNoVersionInPath() {
|
||||
void resolveResourceNoVersionInPath() {
|
||||
String file = "bar.css";
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.empty());
|
||||
given(this.versionStrategy.extractVersion(file)).willReturn("");
|
||||
@@ -114,7 +105,7 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceNoResourceAfterVersionRemoved() {
|
||||
void resolveResourceNoResourceAfterVersionRemoved() {
|
||||
String versionFile = "bar-version.css";
|
||||
String version = "version";
|
||||
String file = "bar.css";
|
||||
@@ -133,7 +124,7 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceVersionDoesNotMatch() {
|
||||
void resolveResourceVersionDoesNotMatch() {
|
||||
String versionFile = "bar-version.css";
|
||||
String version = "version";
|
||||
String file = "bar.css";
|
||||
@@ -154,7 +145,7 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceSuccess() {
|
||||
void resolveResourceSuccess() {
|
||||
String versionFile = "bar-version.css";
|
||||
String version = "version";
|
||||
String file = "bar.css";
|
||||
@@ -179,10 +170,10 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStrategyForPath() {
|
||||
void getStrategyForPath() {
|
||||
Map<String, VersionStrategy> strategies = new HashMap<>();
|
||||
VersionStrategy jsStrategy = mock(VersionStrategy.class);
|
||||
VersionStrategy catchAllStrategy = mock(VersionStrategy.class);
|
||||
VersionStrategy jsStrategy = mock();
|
||||
VersionStrategy catchAllStrategy = mock();
|
||||
strategies.put("/**", catchAllStrategy);
|
||||
strategies.put("/**/*.js", jsStrategy);
|
||||
this.resolver.setStrategyMap(strategies);
|
||||
@@ -194,8 +185,7 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13883
|
||||
public void shouldConfigureFixedPrefixAutomatically() {
|
||||
|
||||
void shouldConfigureFixedPrefixAutomatically() {
|
||||
this.resolver.addFixedVersionStrategy("fixedversion", "/js/**", "/css/**", "/fixedversion/css/**");
|
||||
|
||||
assertThat(this.resolver.getStrategyMap()).hasSize(4);
|
||||
@@ -214,12 +204,11 @@ public class VersionResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15372
|
||||
public void resolveUrlPathNoVersionStrategy() {
|
||||
void resolveUrlPathNoVersionStrategy() {
|
||||
given(this.chain.resolveUrlPath("/foo.css", this.locations)).willReturn(Mono.just("/foo.css"));
|
||||
String resolved = this.resolver.resolveUrlPathInternal("/foo.css", this.locations, this.chain)
|
||||
.block(Duration.ofMillis(1000));
|
||||
assertThat(resolved).isEqualTo("/foo.css");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.reactive.resource;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -29,7 +28,6 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -43,33 +41,23 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class WebJarsResourceResolverTests {
|
||||
class WebJarsResourceResolverTests {
|
||||
|
||||
private static final Duration TIMEOUT = Duration.ofSeconds(1);
|
||||
|
||||
|
||||
private List<Resource> locations;
|
||||
private List<Resource> locations = List.of(new ClassPathResource("/META-INF/resources/webjars"));
|
||||
|
||||
private WebJarsResourceResolver resolver;
|
||||
// for this to work, an actual WebJar must be on the test classpath
|
||||
private WebJarsResourceResolver resolver = new WebJarsResourceResolver();
|
||||
|
||||
private ResourceResolverChain chain;
|
||||
private ResourceResolverChain chain = mock();
|
||||
|
||||
private ServerWebExchange exchange;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
// for this to work, an actual WebJar must be on the test classpath
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars"));
|
||||
this.resolver = new WebJarsResourceResolver();
|
||||
this.chain = mock(ResourceResolverChain.class);
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
}
|
||||
private ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveUrlExisting() {
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
void resolveUrlExisting() {
|
||||
String file = "/foo/2.3/foo.txt";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.just(file));
|
||||
|
||||
@@ -80,8 +68,7 @@ public class WebJarsResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveUrlExistingNotInJarFile() {
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
void resolveUrlExistingNotInJarFile() {
|
||||
String file = "foo/foo.txt";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
@@ -93,7 +80,7 @@ public class WebJarsResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveUrlWebJarResource() {
|
||||
void resolveUrlWebJarResource() {
|
||||
String file = "underscorejs/underscore.js";
|
||||
String expected = "underscorejs/1.8.3/underscore.js";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
|
||||
@@ -107,7 +94,7 @@ public class WebJarsResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveUrlWebJarResourceNotFound() {
|
||||
void resolveUrlWebJarResourceNotFound() {
|
||||
String file = "something/something.js";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
@@ -119,9 +106,8 @@ public class WebJarsResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceExisting() {
|
||||
Resource expected = mock(Resource.class);
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
void resolveResourceExisting() {
|
||||
Resource expected = mock();
|
||||
String file = "foo/2.3/foo.txt";
|
||||
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.just(expected));
|
||||
|
||||
@@ -134,7 +120,7 @@ public class WebJarsResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceNotFound() {
|
||||
void resolveResourceNotFound() {
|
||||
String file = "something/something.js";
|
||||
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
@@ -148,18 +134,15 @@ public class WebJarsResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceWebJar() {
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
|
||||
void resolveResourceWebJar() {
|
||||
String file = "underscorejs/underscore.js";
|
||||
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
Resource expected = mock(Resource.class);
|
||||
Resource expected = mock();
|
||||
String expectedPath = "underscorejs/1.8.3/underscore.js";
|
||||
given(this.chain.resolveResource(this.exchange, expectedPath, this.locations))
|
||||
.willReturn(Mono.just(expected));
|
||||
|
||||
|
||||
Resource actual = this.resolver
|
||||
.resolveResource(this.exchange, file, this.locations, this.chain)
|
||||
.block(TIMEOUT);
|
||||
|
||||
@@ -231,7 +231,7 @@ public class InvocableHandlerMethodTests {
|
||||
}
|
||||
|
||||
private <T> HandlerMethodArgumentResolver stubResolver(Mono<Object> stubValue) {
|
||||
HandlerMethodArgumentResolver resolver = mock(HandlerMethodArgumentResolver.class);
|
||||
HandlerMethodArgumentResolver resolver = mock();
|
||||
given(resolver.supportsParameter(any())).willReturn(true);
|
||||
given(resolver.resolveArgument(any(), any(), any())).willReturn(stubValue);
|
||||
return resolver;
|
||||
|
||||
@@ -118,7 +118,7 @@ public class ControllerAdviceTests {
|
||||
RequestMappingHandlerAdapter adapter = createAdapter(context);
|
||||
TestController controller = context.getBean(TestController.class);
|
||||
|
||||
Validator validator = mock(Validator.class);
|
||||
Validator validator = mock();
|
||||
controller.setValidator(validator);
|
||||
|
||||
BindingContext bindingContext = handle(adapter, controller, "handle").getBindingContext();
|
||||
|
||||
@@ -87,7 +87,7 @@ public class ModelInitializerTests {
|
||||
|
||||
@Test
|
||||
public void initBinderMethod() {
|
||||
Validator validator = mock(Validator.class);
|
||||
Validator validator = mock();
|
||||
|
||||
TestController controller = new TestController();
|
||||
controller.setValidator(validator);
|
||||
|
||||
@@ -57,7 +57,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class RequestMappingHandlerMappingTests {
|
||||
class RequestMappingHandlerMappingTests {
|
||||
|
||||
private final StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
|
||||
@@ -65,13 +65,13 @@ public class RequestMappingHandlerMappingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
this.handlerMapping.setApplicationContext(wac);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveEmbeddedValuesInPatterns() {
|
||||
void resolveEmbeddedValuesInPatterns() {
|
||||
this.handlerMapping.setEmbeddedValueResolver(value -> "/${pattern}/bar".equals(value) ? "/foo/bar" : value);
|
||||
|
||||
String[] patterns = new String[] { "/foo", "/${pattern}/bar" };
|
||||
@@ -81,7 +81,7 @@ public class RequestMappingHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathPrefix() throws Exception {
|
||||
void pathPrefix() throws Exception {
|
||||
this.handlerMapping.setEmbeddedValueResolver(value -> "/${prefix}".equals(value) ? "/api" : value);
|
||||
this.handlerMapping.setPathPrefixes(Collections.singletonMap(
|
||||
"/${prefix}", HandlerTypePredicate.forAnnotation(RestController.class)));
|
||||
@@ -94,7 +94,7 @@ public class RequestMappingHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRequestMappingViaComposedAnnotation() throws Exception {
|
||||
void resolveRequestMappingViaComposedAnnotation() throws Exception {
|
||||
RequestMappingInfo info = assertComposedAnnotationMapping("postJson", "/postJson", RequestMethod.POST);
|
||||
|
||||
assertThat(info.getConsumesCondition().getConsumableMediaTypes().iterator().next().toString()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||
@@ -102,7 +102,7 @@ public class RequestMappingHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test // SPR-14988
|
||||
public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
|
||||
void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
|
||||
RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.POST);
|
||||
|
||||
ConsumesRequestCondition condition = requestMappingInfo.getConsumesCondition();
|
||||
@@ -110,7 +110,7 @@ public class RequestMappingHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test // gh-22010
|
||||
public void consumesWithOptionalRequestBody() {
|
||||
void consumesWithOptionalRequestBody() {
|
||||
this.wac.registerSingleton("testController", ComposedAnnotationController.class);
|
||||
this.wac.refresh();
|
||||
this.handlerMapping.afterPropertiesSet();
|
||||
@@ -126,27 +126,27 @@ public class RequestMappingHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMapping() throws Exception {
|
||||
void getMapping() throws Exception {
|
||||
assertComposedAnnotationMapping(RequestMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postMapping() throws Exception {
|
||||
void postMapping() throws Exception {
|
||||
assertComposedAnnotationMapping(RequestMethod.POST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putMapping() throws Exception {
|
||||
void putMapping() throws Exception {
|
||||
assertComposedAnnotationMapping(RequestMethod.PUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteMapping() throws Exception {
|
||||
void deleteMapping() throws Exception {
|
||||
assertComposedAnnotationMapping(RequestMethod.DELETE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchMapping() throws Exception {
|
||||
void patchMapping() throws Exception {
|
||||
assertComposedAnnotationMapping(RequestMethod.PATCH);
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public class RequestMappingHandlerMappingTests {
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Principal getUser() {
|
||||
return mock(Principal.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,38 +48,35 @@ import static org.mockito.Mockito.mock;
|
||||
* Unit tests for {@link SessionAttributeMethodArgumentResolver}.
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class SessionAttributeMethodArgumentResolverTests {
|
||||
class SessionAttributeMethodArgumentResolverTests {
|
||||
|
||||
private WebSession session = mock();
|
||||
|
||||
private ServerWebExchange exchange = MockServerWebExchange.builder(MockServerHttpRequest.get("/")).session(this.session).build();
|
||||
|
||||
private Method handleMethod = ReflectionUtils.findMethod(getClass(), "handleWithSessionAttribute", (Class<?>[]) null);
|
||||
|
||||
private SessionAttributeMethodArgumentResolver resolver;
|
||||
|
||||
private ServerWebExchange exchange;
|
||||
|
||||
private WebSession session;
|
||||
|
||||
private Method handleMethod;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("resource")
|
||||
public void setup() {
|
||||
void setup() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.refresh();
|
||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||
this.resolver = new SessionAttributeMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
|
||||
this.session = mock(WebSession.class);
|
||||
this.exchange = MockServerWebExchange.builder(MockServerHttpRequest.get("/")).session(this.session).build();
|
||||
this.handleMethod = ReflectionUtils.findMethod(getClass(), "handleWithSessionAttribute", (Class<?>[]) null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
void supportsParameter() {
|
||||
assertThat(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, 0))).isTrue();
|
||||
assertThat(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, 4))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolve() {
|
||||
void resolve() {
|
||||
MethodParameter param = initMethodParameter(0);
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||
StepVerifier.create(mono).expectError(ServerWebInputException.class).verify();
|
||||
@@ -91,7 +88,7 @@ public class SessionAttributeMethodArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveWithName() {
|
||||
void resolveWithName() {
|
||||
MethodParameter param = initMethodParameter(1);
|
||||
Foo foo = new Foo();
|
||||
given(this.session.getAttribute("specialFoo")).willReturn(foo);
|
||||
@@ -100,7 +97,7 @@ public class SessionAttributeMethodArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveNotRequired() {
|
||||
void resolveNotRequired() {
|
||||
MethodParameter param = initMethodParameter(2);
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||
assertThat(mono.block()).isNull();
|
||||
@@ -113,7 +110,7 @@ public class SessionAttributeMethodArgumentResolverTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void resolveOptional() {
|
||||
void resolveOptional() {
|
||||
MethodParameter param = initMethodParameter(3);
|
||||
Optional<Object> actual = (Optional<Object>) this.resolver
|
||||
.resolveArgument(param, new BindingContext(), this.exchange).block();
|
||||
@@ -129,9 +126,7 @@ public class SessionAttributeMethodArgumentResolverTests {
|
||||
given(this.session.getAttribute("foo")).willReturn(foo);
|
||||
actual = (Optional<Object>) this.resolver.resolveArgument(param, bindingContext, this.exchange).block();
|
||||
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.isPresent()).isTrue();
|
||||
assertThat(actual.get()).isSameAs(foo);
|
||||
assertThat(actual).hasValue(foo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class WebSessionMethodArgumentResolverTests {
|
||||
public void resolverArgument() {
|
||||
|
||||
BindingContext context = new BindingContext();
|
||||
WebSession session = mock(WebSession.class);
|
||||
WebSession session = mock();
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.builder(request).session(session).build();
|
||||
|
||||
|
||||
@@ -67,13 +67,13 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ViewResolutionResultHandlerTests {
|
||||
class ViewResolutionResultHandlerTests {
|
||||
|
||||
private final BindingContext bindingContext = new BindingContext();
|
||||
|
||||
|
||||
@Test
|
||||
public void supports() {
|
||||
void supports() {
|
||||
testSupports(on(Handler.class).annotPresent(ModelAttribute.class).resolveReturnType(String.class));
|
||||
testSupports(on(Handler.class).annotNotPresent(ModelAttribute.class).resolveReturnType(String.class));
|
||||
testSupports(on(Handler.class).resolveReturnType(Mono.class, String.class));
|
||||
@@ -122,7 +122,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viewResolverOrder() {
|
||||
void viewResolverOrder() {
|
||||
TestViewResolver resolver1 = new TestViewResolver("account");
|
||||
TestViewResolver resolver2 = new TestViewResolver("profile");
|
||||
resolver1.setOrder(2);
|
||||
@@ -133,7 +133,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleReturnValueTypes() {
|
||||
void handleReturnValueTypes() {
|
||||
Object returnValue;
|
||||
MethodParameter returnType;
|
||||
ViewResolver resolver = new TestViewResolver("account");
|
||||
@@ -197,7 +197,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleWithMultipleResolvers() {
|
||||
void handleWithMultipleResolvers() {
|
||||
testHandle("/account",
|
||||
on(Handler.class).annotNotPresent(ModelAttribute.class).resolveReturnType(String.class),
|
||||
"profile", "profile: {id=123}",
|
||||
@@ -205,7 +205,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultViewName() {
|
||||
void defaultViewName() {
|
||||
testDefaultViewName(null, on(Handler.class).annotPresent(ModelAttribute.class).resolveReturnType(String.class));
|
||||
testDefaultViewName(Mono.empty(), on(Handler.class).resolveReturnType(Mono.class, String.class));
|
||||
testDefaultViewName(Mono.empty(), on(Handler.class).resolveReturnType(Mono.class, Void.class));
|
||||
@@ -231,7 +231,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unresolvedViewName() {
|
||||
void unresolvedViewName() {
|
||||
String returnValue = "account";
|
||||
MethodParameter returnType = on(Handler.class).annotPresent(ModelAttribute.class).resolveReturnType(String.class);
|
||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
||||
@@ -246,7 +246,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentNegotiation() {
|
||||
void contentNegotiation() {
|
||||
TestBean value = new TestBean("Joe");
|
||||
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
||||
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
||||
@@ -268,7 +268,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentNegotiationWith406() {
|
||||
void contentNegotiationWith406() {
|
||||
TestBean value = new TestBean("Joe");
|
||||
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
||||
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
||||
@@ -284,7 +284,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15291
|
||||
public void contentNegotiationWithRedirect() {
|
||||
void contentNegotiationWithRedirect() {
|
||||
HandlerResult handlerResult = new HandlerResult(new Object(), "redirect:/",
|
||||
on(Handler.class).annotNotPresent(ModelAttribute.class).resolveReturnType(String.class),
|
||||
this.bindingContext);
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.web.reactive.result.view.script;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -38,29 +38,30 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@Disabled("JRuby not compatible with JDK 9 yet")
|
||||
public class JRubyScriptTemplateTests {
|
||||
class JRubyScriptTemplateTests {
|
||||
|
||||
@Test
|
||||
public void renderTemplate() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
model.put("title", "Layout example");
|
||||
model.put("body", "This is the body");
|
||||
void renderTemplate() throws Exception {
|
||||
Map<String, Object> model = Map.of(
|
||||
"title", "Layout example",
|
||||
"body", "This is the body"
|
||||
);
|
||||
String url = "org/springframework/web/reactive/result/view/script/jruby/template.erb";
|
||||
MockServerHttpResponse response = renderViewWithModel(url, model);
|
||||
assertThat(response.getBodyAsString().block()).isEqualTo("<html><head><title>Layout example</title></head><body><p>This is the body</p></body></html>");
|
||||
assertThat(response.getBodyAsString().block())
|
||||
.isEqualTo("<html><head><title>Layout example</title></head><body><p>This is the body</p></body></html>");
|
||||
}
|
||||
|
||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
||||
|
||||
private static MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
||||
ScriptTemplateView view = createViewWithUrl(viewUrl);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||
return exchange.getResponse();
|
||||
}
|
||||
|
||||
private ScriptTemplateView createViewWithUrl(String viewUrl) throws Exception {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ScriptTemplatingConfiguration.class);
|
||||
ctx.refresh();
|
||||
private static ScriptTemplateView createViewWithUrl(String viewUrl) throws Exception {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ScriptTemplatingConfiguration.class);
|
||||
|
||||
ScriptTemplateView view = new ScriptTemplateView();
|
||||
view.setApplicationContext(ctx);
|
||||
@@ -74,7 +75,7 @@ public class JRubyScriptTemplateTests {
|
||||
static class ScriptTemplatingConfiguration {
|
||||
|
||||
@Bean
|
||||
public ScriptTemplateConfigurer jRubyConfigurer() {
|
||||
ScriptTemplateConfigurer jRubyConfigurer() {
|
||||
ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
|
||||
configurer.setScripts("org/springframework/web/reactive/result/view/script/jruby/render.rb");
|
||||
configurer.setEngineName("jruby");
|
||||
|
||||
@@ -40,10 +40,10 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class HandshakeWebSocketServiceTests {
|
||||
class HandshakeWebSocketServiceTests {
|
||||
|
||||
@Test
|
||||
public void sessionAttributePredicate() {
|
||||
void sessionAttributePredicate() {
|
||||
MockWebSession session = new MockWebSession();
|
||||
session.getAttributes().put("a1", "v1");
|
||||
session.getAttributes().put("a2", "v2");
|
||||
@@ -58,7 +58,7 @@ public class HandshakeWebSocketServiceTests {
|
||||
HandshakeWebSocketService service = new HandshakeWebSocketService(upgradeStrategy);
|
||||
service.setSessionAttributePredicate(name -> Arrays.asList("a1", "a3", "a5").contains(name));
|
||||
|
||||
service.handleRequest(exchange, mock(WebSocketHandler.class)).block();
|
||||
service.handleRequest(exchange, mock()).block();
|
||||
|
||||
HandshakeInfo info = upgradeStrategy.handshakeInfo;
|
||||
assertThat(info).isNotNull();
|
||||
|
||||
@@ -40,7 +40,7 @@ public class WebSocketUpgradeHandlerPredicateTests {
|
||||
|
||||
private final WebSocketUpgradeHandlerPredicate predicate = new WebSocketUpgradeHandlerPredicate();
|
||||
|
||||
private final WebSocketHandler webSocketHandler = mock(WebSocketHandler.class);
|
||||
private final WebSocketHandler webSocketHandler = mock();
|
||||
|
||||
ServerWebExchange httpGetExchange =
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
|
||||
Reference in New Issue
Block a user