Migrate JUnit 4 assertions to AssertJ

Migrate all existing JUnit 4 `assert...` based assertions to AssertJ
and add a checkstyle rule to ensure they don't return.

See gh-23022
This commit is contained in:
Phillip Webb
2019-05-23 15:51:39 -07:00
parent 95a9d46a87
commit 9d74da006c
1636 changed files with 37861 additions and 40390 deletions

View File

@@ -51,9 +51,6 @@ import org.springframework.web.server.WebHandler;
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.springframework.http.MediaType.APPLICATION_JSON;
/**
@@ -94,7 +91,7 @@ public class DispatcherHandlerErrorTests {
// SPR-17475
AtomicReference<Throwable> exceptionRef = new AtomicReference<>();
StepVerifier.create(mono).consumeErrorWith(exceptionRef::set).verify();
StepVerifier.create(mono).consumeErrorWith(ex -> assertNotSame(exceptionRef.get(), ex)).verify();
StepVerifier.create(mono).consumeErrorWith(ex -> assertThat(ex).isNotSameAs(exceptionRef.get())).verify();
}
@Test
@@ -103,7 +100,7 @@ public class DispatcherHandlerErrorTests {
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher)
.consumeErrorWith(error -> assertSame(EXCEPTION, error))
.consumeErrorWith(error -> assertThat(error).isSameAs(EXCEPTION))
.verify();
}
@@ -113,7 +110,7 @@ public class DispatcherHandlerErrorTests {
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher)
.consumeErrorWith(error -> assertSame(EXCEPTION, error))
.consumeErrorWith(error -> assertThat(error).isSameAs(EXCEPTION))
.verify();
}
@@ -150,7 +147,7 @@ public class DispatcherHandlerErrorTests {
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher)
.consumeErrorWith(error -> assertSame(EXCEPTION, error))
.consumeErrorWith(error -> assertThat(error).isSameAs(EXCEPTION))
.verify();
}
@@ -162,7 +159,7 @@ public class DispatcherHandlerErrorTests {
WebHandler webHandler = new ExceptionHandlingWebHandler(this.dispatcherHandler, handlers);
webHandler.handle(exchange).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exchange.getResponse().getStatusCode());
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}

View File

@@ -33,7 +33,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.method.ResolvableMethod;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -69,7 +69,7 @@ public class DispatcherHandlerTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
dispatcherHandler.handle(exchange).block(Duration.ofSeconds(0));
assertEquals("1", exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5)));
assertThat(exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5))).isEqualTo("1");
}

View File

@@ -32,7 +32,7 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.reactive.function.client.WebClient;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for server response flushing behavior.
@@ -77,7 +77,7 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
try {
StepVerifier.create(result)
.consumeNextWith(value -> assertEquals(64 * 1024, value.length()))
.consumeNextWith(value -> assertThat(value.length()).isEqualTo((64 * 1024)))
.expectComplete()
.verify(Duration.ofSeconds(10L));
}

View File

@@ -25,8 +25,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.NotAcceptableStatusException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* Unit tests for {@link HeaderContentTypeResolver}.
@@ -44,11 +44,11 @@ public class HeaderContentTypeResolverTests {
List<MediaType> mediaTypes = this.resolver.resolveMediaTypes(
MockServerWebExchange.from(MockServerHttpRequest.get("/").header("accept", header)));
assertEquals(4, mediaTypes.size());
assertEquals("text/html", mediaTypes.get(0).toString());
assertEquals("text/x-c", mediaTypes.get(1).toString());
assertEquals("text/x-dvi;q=0.8", mediaTypes.get(2).toString());
assertEquals("text/plain;q=0.5", mediaTypes.get(3).toString());
assertThat(mediaTypes.size()).isEqualTo(4);
assertThat(mediaTypes.get(0).toString()).isEqualTo("text/html");
assertThat(mediaTypes.get(1).toString()).isEqualTo("text/x-c");
assertThat(mediaTypes.get(2).toString()).isEqualTo("text/x-dvi;q=0.8");
assertThat(mediaTypes.get(3).toString()).isEqualTo("text/plain;q=0.5");
}
@Test

View File

@@ -27,8 +27,8 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.NotAcceptableStatusException;
import org.springframework.web.server.ServerWebExchange;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* Unit tests for {@link ParameterContentTypeResolver}.
@@ -42,7 +42,7 @@ public class ParameterContentTypeResolverTests {
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(RequestedContentTypeResolver.MEDIA_TYPE_ALL_LIST, mediaTypes);
assertThat(mediaTypes).isEqualTo(RequestedContentTypeResolver.MEDIA_TYPE_ALL_LIST);
}
@Test
@@ -59,12 +59,12 @@ public class ParameterContentTypeResolverTests {
Map<String, MediaType> mapping = Collections.emptyMap();
RequestedContentTypeResolver resolver = new ParameterContentTypeResolver(mapping);
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(new MediaType("text", "html")), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(new MediaType("text", "html")));
mapping = Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML);
resolver = new ParameterContentTypeResolver(mapping);
mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(new MediaType("application", "xhtml+xml")), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(new MediaType("application", "xhtml+xml")));
}
@Test
@@ -73,7 +73,7 @@ public class ParameterContentTypeResolverTests {
RequestedContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(new MediaType("application", "vnd.ms-excel")), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(new MediaType("application", "vnd.ms-excel")));
}
@Test // SPR-13747
@@ -83,7 +83,7 @@ public class ParameterContentTypeResolverTests {
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(mapping);
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
private MockServerWebExchange createExchange(String format) {

View File

@@ -24,7 +24,7 @@ import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link RequestedContentTypeResolverBuilder}.
@@ -40,7 +40,7 @@ public class RequestedContentTypeResolverBuilderTests {
MockServerHttpRequest.get("/flower").accept(MediaType.IMAGE_GIF));
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(MediaType.IMAGE_GIF), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(MediaType.IMAGE_GIF));
}
@Test
@@ -53,7 +53,7 @@ public class RequestedContentTypeResolverBuilderTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/flower?format=json"));
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
@Test
@@ -66,7 +66,7 @@ public class RequestedContentTypeResolverBuilderTests {
List<MediaType> mediaTypes = resolver.resolveMediaTypes(
MockServerWebExchange.from(MockServerHttpRequest.get("/flower?s=json")));
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
@Test // SPR-10513
@@ -79,7 +79,7 @@ public class RequestedContentTypeResolverBuilderTests {
List<MediaType> mediaTypes = resolver.resolveMediaTypes(
MockServerWebExchange.from(MockServerHttpRequest.get("/").accept(MediaType.ALL)));
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
@Test // SPR-12286
@@ -91,11 +91,11 @@ public class RequestedContentTypeResolverBuilderTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").accept(MediaType.ALL));
mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
assertThat(mediaTypes).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
}

View File

@@ -23,8 +23,7 @@ import org.junit.Test;
import org.springframework.web.cors.CorsConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test fixture with a {@link CorsRegistry}.
@@ -38,14 +37,14 @@ public class CorsRegistryTests {
@Test
public void noMapping() {
assertTrue(this.registry.getCorsConfigurations().isEmpty());
assertThat(this.registry.getCorsConfigurations().isEmpty()).isTrue();
}
@Test
public void multipleMappings() {
this.registry.addMapping("/foo");
this.registry.addMapping("/bar");
assertEquals(2, this.registry.getCorsConfigurations().size());
assertThat(this.registry.getCorsConfigurations().size()).isEqualTo(2);
}
@Test
@@ -54,14 +53,14 @@ public class CorsRegistryTests {
.allowedMethods("DELETE").allowCredentials(false).allowedHeaders("header1", "header2")
.exposedHeaders("header3", "header4").maxAge(3600);
Map<String, CorsConfiguration> configs = this.registry.getCorsConfigurations();
assertEquals(1, configs.size());
assertThat(configs.size()).isEqualTo(1);
CorsConfiguration config = configs.get("/foo");
assertEquals(Arrays.asList("https://domain2.com", "https://domain2.com"), config.getAllowedOrigins());
assertEquals(Arrays.asList("DELETE"), config.getAllowedMethods());
assertEquals(Arrays.asList("header1", "header2"), config.getAllowedHeaders());
assertEquals(Arrays.asList("header3", "header4"), config.getExposedHeaders());
assertEquals(false, config.getAllowCredentials());
assertEquals(Long.valueOf(3600), config.getMaxAge());
assertThat(config.getAllowedOrigins()).isEqualTo(Arrays.asList("https://domain2.com", "https://domain2.com"));
assertThat(config.getAllowedMethods()).isEqualTo(Arrays.asList("DELETE"));
assertThat(config.getAllowedHeaders()).isEqualTo(Arrays.asList("header1", "header2"));
assertThat(config.getExposedHeaders()).isEqualTo(Arrays.asList("header3", "header4"));
assertThat(config.getAllowCredentials()).isEqualTo(false);
assertThat(config.getMaxAge()).isEqualTo(Long.valueOf(3600));
}
}

View File

@@ -37,10 +37,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willAnswer;
@@ -106,10 +103,11 @@ public class DelegatingWebFluxConfigurationTests {
verify(webFluxConfigurer).addFormatters(formatterRegistry.capture());
verify(webFluxConfigurer).configureArgumentResolvers(any());
assertNotNull(initializer);
assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);
assertSame(formatterRegistry.getValue(), initializer.getConversionService());
assertEquals(13, codecsConfigurer.getValue().getReaders().size());
assertThat(initializer).isNotNull();
boolean condition = initializer.getValidator() instanceof LocalValidatorFactoryBean;
assertThat(condition).isTrue();
assertThat(initializer.getConversionService()).isSameAs(formatterRegistry.getValue());
assertThat(codecsConfigurer.getValue().getReaders().size()).isEqualTo(13);
}
@Test

View File

@@ -49,10 +49,6 @@ import org.springframework.web.reactive.resource.VersionResourceResolver;
import org.springframework.web.reactive.resource.WebJarsResourceResolver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link ResourceHandlerRegistry}.
@@ -77,7 +73,7 @@ public class ResourceHandlerRegistryTests {
@Test
public void noResourceHandlers() throws Exception {
this.registry = new ResourceHandlerRegistry(new GenericApplicationContext());
assertNull(this.registry.getHandlerMapping());
assertThat((Object) this.registry.getHandlerMapping()).isNull();
}
@Test
@@ -90,8 +86,7 @@ public class ResourceHandlerRegistryTests {
handler.handle(exchange).block(Duration.ofSeconds(5));
StepVerifier.create(exchange.getResponse().getBody())
.consumeNextWith(buf -> assertEquals("test stylesheet content",
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
.consumeNextWith(buf -> assertThat(DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)).isEqualTo("test stylesheet content"))
.expectComplete()
.verify();
}
@@ -107,16 +102,16 @@ public class ResourceHandlerRegistryTests {
@Test
public void order() {
assertEquals(Integer.MAX_VALUE -1, this.registry.getHandlerMapping().getOrder());
assertThat(this.registry.getHandlerMapping().getOrder()).isEqualTo(Integer.MAX_VALUE -1);
this.registry.setOrder(0);
assertEquals(0, this.registry.getHandlerMapping().getOrder());
assertThat(this.registry.getHandlerMapping().getOrder()).isEqualTo(0);
}
@Test
public void hasMappingForPattern() {
assertTrue(this.registry.hasMappingForPattern("/resources/**"));
assertFalse(this.registry.hasMappingForPattern("/whatever"));
assertThat(this.registry.hasMappingForPattern("/resources/**")).isTrue();
assertThat(this.registry.hasMappingForPattern("/whatever")).isFalse();
}
@Test

View File

@@ -32,11 +32,7 @@ import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigu
import org.springframework.web.reactive.result.view.script.ScriptTemplateConfigurer;
import org.springframework.web.reactive.result.view.script.ScriptTemplateViewResolver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link ViewResolverRegistry}.
@@ -60,22 +56,22 @@ public class ViewResolverRegistryTests {
@Test
public void order() {
assertEquals(Ordered.LOWEST_PRECEDENCE, this.registry.getOrder());
assertThat(this.registry.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE);
}
@Test
public void hasRegistrations() {
assertFalse(this.registry.hasRegistrations());
assertThat(this.registry.hasRegistrations()).isFalse();
this.registry.freeMarker();
assertTrue(this.registry.hasRegistrations());
assertThat(this.registry.hasRegistrations()).isTrue();
}
@Test
public void noResolvers() {
assertNotNull(this.registry.getViewResolvers());
assertEquals(0, this.registry.getViewResolvers().size());
assertFalse(this.registry.hasRegistrations());
assertThat(this.registry.getViewResolvers()).isNotNull();
assertThat(this.registry.getViewResolvers().size()).isEqualTo(0);
assertThat(this.registry.hasRegistrations()).isFalse();
}
@Test
@@ -83,8 +79,8 @@ public class ViewResolverRegistryTests {
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
this.registry.viewResolver(viewResolver);
assertSame(viewResolver, this.registry.getViewResolvers().get(0));
assertEquals(1, this.registry.getViewResolvers().size());
assertThat(this.registry.getViewResolvers().get(0)).isSameAs(viewResolver);
assertThat(this.registry.getViewResolvers().size()).isEqualTo(1);
}
@Test
@@ -92,8 +88,8 @@ public class ViewResolverRegistryTests {
View view = new HttpMessageWriterView(new Jackson2JsonEncoder());
this.registry.defaultViews(view);
assertEquals(1, this.registry.getDefaultViews().size());
assertSame(view, this.registry.getDefaultViews().get(0));
assertThat(this.registry.getDefaultViews().size()).isEqualTo(1);
assertThat(this.registry.getDefaultViews().get(0)).isSameAs(view);
}
@Test // SPR-16431
@@ -101,11 +97,11 @@ public class ViewResolverRegistryTests {
this.registry.scriptTemplate().prefix("/").suffix(".html");
List<ViewResolver> viewResolvers = this.registry.getViewResolvers();
assertEquals(1, viewResolvers.size());
assertEquals(ScriptTemplateViewResolver.class, viewResolvers.get(0).getClass());
assertThat(viewResolvers.size()).isEqualTo(1);
assertThat(viewResolvers.get(0).getClass()).isEqualTo(ScriptTemplateViewResolver.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(viewResolvers.get(0));
assertEquals("/", accessor.getPropertyValue("prefix"));
assertEquals(".html", accessor.getPropertyValue("suffix"));
assertThat(accessor.getPropertyValue("prefix")).isEqualTo("/");
assertThat(accessor.getPropertyValue("suffix")).isEqualTo(".html");
}
}

View File

@@ -76,11 +76,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebHandler;
import org.springframework.web.util.pattern.PathPatternParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.springframework.core.ResolvableType.forClass;
import static org.springframework.core.ResolvableType.forClassWithGenerics;
@@ -107,21 +103,21 @@ public class WebFluxConfigurationSupportTests {
String name = "requestMappingHandlerMapping";
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
assertNotNull(mapping);
assertThat(mapping).isNotNull();
assertEquals(0, mapping.getOrder());
assertThat(mapping.getOrder()).isEqualTo(0);
PathPatternParser patternParser = mapping.getPathPatternParser();
assertNotNull(patternParser);
assertThat(patternParser).isNotNull();
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
assertTrue(matchOptionalTrailingSlash);
assertThat(matchOptionalTrailingSlash).isTrue();
name = "webFluxContentTypeResolver";
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
assertSame(resolver, mapping.getContentTypeResolver());
assertThat(mapping.getContentTypeResolver()).isSameAs(resolver);
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
assertThat(resolver.resolveMediaTypes(exchange)).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
@Test
@@ -132,17 +128,16 @@ public class WebFluxConfigurationSupportTests {
String name = "requestMappingHandlerMapping";
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
assertNotNull(mapping);
assertThat(mapping).isNotNull();
PathPatternParser patternParser = mapping.getPathPatternParser();
assertNotNull(patternParser);
assertThat(patternParser).isNotNull();
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
assertFalse(matchOptionalTrailingSlash);
assertThat(matchOptionalTrailingSlash).isFalse();
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
assertEquals(1, map.size());
assertEquals(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")),
map.keySet().iterator().next().getPatternsCondition().getPatterns());
assertThat(map.size()).isEqualTo(1);
assertThat(map.keySet().iterator().next().getPatternsCondition().getPatterns()).isEqualTo(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")));
}
@Test
@@ -151,10 +146,10 @@ public class WebFluxConfigurationSupportTests {
String name = "requestMappingHandlerAdapter";
RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
assertThat(adapter).isNotNull();
List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
assertEquals(13, readers.size());
assertThat(readers.size()).isEqualTo(13);
ResolvableType multiValueMapType = forClassWithGenerics(MultiValueMap.class, String.class, String.class);
@@ -170,17 +165,17 @@ public class WebFluxConfigurationSupportTests {
assertHasMessageReader(readers, forClass(TestBean.class), null);
WebBindingInitializer bindingInitializer = adapter.getWebBindingInitializer();
assertNotNull(bindingInitializer);
assertThat(bindingInitializer).isNotNull();
WebExchangeDataBinder binder = new WebExchangeDataBinder(new Object());
bindingInitializer.initBinder(binder);
name = "webFluxConversionService";
ConversionService service = context.getBean(name, ConversionService.class);
assertSame(service, binder.getConversionService());
assertThat(binder.getConversionService()).isSameAs(service);
name = "webFluxValidator";
Validator validator = context.getBean(name, Validator.class);
assertSame(validator, binder.getValidator());
assertThat(binder.getValidator()).isSameAs(validator);
}
@Test
@@ -189,10 +184,10 @@ public class WebFluxConfigurationSupportTests {
String name = "requestMappingHandlerAdapter";
RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
assertThat(adapter).isNotNull();
List<HttpMessageReader<?>> messageReaders = adapter.getMessageReaders();
assertEquals(2, messageReaders.size());
assertThat(messageReaders.size()).isEqualTo(2);
assertHasMessageReader(messageReaders, forClass(String.class), TEXT_PLAIN);
assertHasMessageReader(messageReaders, forClass(TestBean.class), APPLICATION_XML);
@@ -204,12 +199,12 @@ public class WebFluxConfigurationSupportTests {
String name = "responseEntityResultHandler";
ResponseEntityResultHandler handler = context.getBean(name, ResponseEntityResultHandler.class);
assertNotNull(handler);
assertThat(handler).isNotNull();
assertEquals(0, handler.getOrder());
assertThat(handler.getOrder()).isEqualTo(0);
List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
assertEquals(11, writers.size());
assertThat(writers.size()).isEqualTo(11);
assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
@@ -223,7 +218,7 @@ public class WebFluxConfigurationSupportTests {
name = "webFluxContentTypeResolver";
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
assertSame(resolver, handler.getContentTypeResolver());
assertThat(handler.getContentTypeResolver()).isSameAs(resolver);
}
@Test
@@ -232,12 +227,12 @@ public class WebFluxConfigurationSupportTests {
String name = "responseBodyResultHandler";
ResponseBodyResultHandler handler = context.getBean(name, ResponseBodyResultHandler.class);
assertNotNull(handler);
assertThat(handler).isNotNull();
assertEquals(100, handler.getOrder());
assertThat(handler.getOrder()).isEqualTo(100);
List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
assertEquals(11, writers.size());
assertThat(writers.size()).isEqualTo(11);
assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
@@ -251,7 +246,7 @@ public class WebFluxConfigurationSupportTests {
name = "webFluxContentTypeResolver";
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
assertSame(resolver, handler.getContentTypeResolver());
assertThat(handler.getContentTypeResolver()).isSameAs(resolver);
}
@Test
@@ -260,19 +255,19 @@ public class WebFluxConfigurationSupportTests {
String name = "viewResolutionResultHandler";
ViewResolutionResultHandler handler = context.getBean(name, ViewResolutionResultHandler.class);
assertNotNull(handler);
assertThat(handler).isNotNull();
assertEquals(Ordered.LOWEST_PRECEDENCE, handler.getOrder());
assertThat(handler.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE);
List<ViewResolver> resolvers = handler.getViewResolvers();
assertEquals(1, resolvers.size());
assertEquals(FreeMarkerViewResolver.class, resolvers.get(0).getClass());
assertThat(resolvers.size()).isEqualTo(1);
assertThat(resolvers.get(0).getClass()).isEqualTo(FreeMarkerViewResolver.class);
List<View> views = handler.getDefaultViews();
assertEquals(1, views.size());
assertThat(views.size()).isEqualTo(1);
MimeType type = MimeTypeUtils.parseMimeType("application/json");
assertEquals(type, views.get(0).getSupportedMediaTypes().get(0));
assertThat(views.get(0).getSupportedMediaTypes().get(0)).isEqualTo(type);
}
@Test
@@ -281,13 +276,13 @@ public class WebFluxConfigurationSupportTests {
String name = "resourceHandlerMapping";
AbstractUrlHandlerMapping handlerMapping = context.getBean(name, AbstractUrlHandlerMapping.class);
assertNotNull(handlerMapping);
assertThat(handlerMapping).isNotNull();
assertEquals(Ordered.LOWEST_PRECEDENCE - 1, handlerMapping.getOrder());
assertThat(handlerMapping.getOrder()).isEqualTo((Ordered.LOWEST_PRECEDENCE - 1));
SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
WebHandler webHandler = (WebHandler) urlHandlerMapping.getUrlMap().get("/images/**");
assertNotNull(webHandler);
assertThat(webHandler).isNotNull();
}
@Test
@@ -296,16 +291,16 @@ public class WebFluxConfigurationSupportTests {
String name = "resourceUrlProvider";
ResourceUrlProvider resourceUrlProvider = context.getBean(name, ResourceUrlProvider.class);
assertNotNull(resourceUrlProvider);
assertThat(resourceUrlProvider).isNotNull();
}
private void assertHasMessageReader(List<HttpMessageReader<?>> readers, ResolvableType type, MediaType mediaType) {
assertTrue(readers.stream().anyMatch(c -> mediaType == null || c.canRead(type, mediaType)));
assertThat(readers.stream().anyMatch(c -> mediaType == null || c.canRead(type, mediaType))).isTrue();
}
private void assertHasMessageWriter(List<HttpMessageWriter<?>> writers, ResolvableType type, MediaType mediaType) {
assertTrue(writers.stream().anyMatch(c -> mediaType == null || c.canWrite(type, mediaType)));
assertThat(writers.stream().anyMatch(c -> mediaType == null || c.canWrite(type, mediaType))).isTrue();
}
private ApplicationContext loadConfig(Class<?>... configurationClasses) {

View File

@@ -63,10 +63,8 @@ import org.springframework.mock.http.client.reactive.test.MockClientHttpResponse
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.util.MultiValueMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;
/**
@@ -175,8 +173,8 @@ public class BodyExtractorsTests {
StepVerifier.create(result)
.consumeNextWith(user -> {
assertEquals("foo", user.getUsername());
assertNull(user.getPassword());
assertThat(user.getUsername()).isEqualTo("foo");
assertThat(user.getPassword()).isNull();
})
.expectComplete()
.verify();
@@ -266,12 +264,12 @@ public class BodyExtractorsTests {
StepVerifier.create(result)
.consumeNextWith(user -> {
assertEquals("foo", user.getUsername());
assertNull(user.getPassword());
assertThat(user.getUsername()).isEqualTo("foo");
assertThat(user.getPassword()).isNull();
})
.consumeNextWith(user -> {
assertEquals("bar", user.getUsername());
assertNull(user.getPassword());
assertThat(user.getUsername()).isEqualTo("bar");
assertThat(user.getPassword()).isNull();
})
.expectComplete()
.verify();
@@ -328,13 +326,13 @@ public class BodyExtractorsTests {
StepVerifier.create(result)
.consumeNextWith(form -> {
assertEquals("Invalid result", 3, form.size());
assertEquals("Invalid result", "value 1", form.getFirst("name 1"));
assertThat(form.size()).as("Invalid result").isEqualTo(3);
assertThat(form.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = form.get("name 2");
assertEquals("Invalid result", 2, values.size());
assertEquals("Invalid result", "value 2+1", values.get(0));
assertEquals("Invalid result", "value 2+2", values.get(1));
assertNull("Invalid result", form.getFirst("name 3"));
assertThat(values.size()).as("Invalid result").isEqualTo(2);
assertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
assertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
assertThat(form.getFirst("name 3")).as("Invalid result").isNull();
})
.expectComplete()
.verify();
@@ -375,24 +373,27 @@ public class BodyExtractorsTests {
StepVerifier.create(result)
.consumeNextWith(part -> {
assertEquals("text", part.name());
assertTrue(part instanceof FormFieldPart);
assertThat(part.name()).isEqualTo("text");
boolean condition = part instanceof FormFieldPart;
assertThat(condition).isTrue();
FormFieldPart formFieldPart = (FormFieldPart) part;
assertEquals("text default", formFieldPart.value());
assertThat(formFieldPart.value()).isEqualTo("text default");
})
.consumeNextWith(part -> {
assertEquals("file1", part.name());
assertTrue(part instanceof FilePart);
assertThat(part.name()).isEqualTo("file1");
boolean condition = part instanceof FilePart;
assertThat(condition).isTrue();
FilePart filePart = (FilePart) part;
assertEquals("a.txt", filePart.filename());
assertEquals(MediaType.TEXT_PLAIN, filePart.headers().getContentType());
assertThat(filePart.filename()).isEqualTo("a.txt");
assertThat(filePart.headers().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
})
.consumeNextWith(part -> {
assertEquals("file2", part.name());
assertTrue(part instanceof FilePart);
assertThat(part.name()).isEqualTo("file2");
boolean condition = part instanceof FilePart;
assertThat(condition).isTrue();
FilePart filePart = (FilePart) part;
assertEquals("a.html", filePart.filename());
assertEquals(MediaType.TEXT_HTML, filePart.headers().getContentType());
assertThat(filePart.filename()).isEqualTo("a.html");
assertThat(filePart.headers().getContentType()).isEqualTo(MediaType.TEXT_HTML);
})
.expectComplete()
.verify();
@@ -433,7 +434,8 @@ public class BodyExtractorsTests {
body.emit(buffer);
})
.expectErrorSatisfies(throwable -> {
assertTrue(throwable instanceof UnsupportedMediaTypeException);
boolean condition = throwable instanceof UnsupportedMediaTypeException;
assertThat(condition).isTrue();
assertThatExceptionOfType(IllegalReferenceCountException.class).isThrownBy(
buffer::release);
body.assertCancelled();

View File

@@ -68,8 +68,6 @@ import org.springframework.util.MultiValueMap;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;
/**
@@ -126,7 +124,7 @@ public class BodyInsertersTests {
StepVerifier.create(response.getBody())
.consumeNextWith(buf -> {
String actual = DataBufferTestUtils.dumpString(buf, UTF_8);
assertEquals("foo", actual);
assertThat(actual).isEqualTo("foo");
})
.expectComplete()
.verify();
@@ -172,7 +170,7 @@ public class BodyInsertersTests {
StepVerifier.create(response.getBody())
.consumeNextWith(buf -> {
String actual = DataBufferTestUtils.dumpString(buf, UTF_8);
assertEquals("foo", actual);
assertThat(actual).isEqualTo("foo");
})
.expectComplete()
.verify();
@@ -194,7 +192,7 @@ public class BodyInsertersTests {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
DataBufferUtils.release(dataBuffer);
assertArrayEquals(expectedBytes, resultBytes);
assertThat(resultBytes).isEqualTo(expectedBytes);
})
.expectComplete()
.verify();
@@ -237,7 +235,7 @@ public class BodyInsertersTests {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
DataBufferUtils.release(dataBuffer);
assertArrayEquals(expectedBytes, resultBytes);
assertThat(resultBytes).isEqualTo(expectedBytes);
})
.expectComplete()
.verify();
@@ -275,8 +273,7 @@ public class BodyInsertersTests {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
DataBufferUtils.release(dataBuffer);
assertArrayEquals("name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8),
resultBytes);
assertThat(resultBytes).isEqualTo("name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8));
})
.expectComplete()
.verify();
@@ -300,8 +297,7 @@ public class BodyInsertersTests {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
DataBufferUtils.release(dataBuffer);
assertArrayEquals("name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8),
resultBytes);
assertThat(resultBytes).isEqualTo("name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8));
})
.expectComplete()
.verify();

View File

@@ -37,7 +37,7 @@ import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
@@ -59,7 +59,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
StepVerifier
.create(result)
.consumeNextWith(response -> assertEquals(HttpStatus.OK, response.statusCode()))
.consumeNextWith(response -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK))
.verifyComplete();
}
@@ -73,7 +73,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
StepVerifier
.create(result)
.consumeNextWith(response -> assertEquals(HttpStatus.OK, response.statusCode()))
.consumeNextWith(response -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK))
.verifyComplete();
}
@@ -100,9 +100,9 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
.flatMap(map -> {
Map<String, Part> parts = map.toSingleValueMap();
try {
assertEquals(2, parts.size());
assertEquals("foo.txt", ((FilePart) parts.get("fooPart")).filename());
assertEquals("bar", ((FormFieldPart) parts.get("barPart")).value());
assertThat(parts.size()).isEqualTo(2);
assertThat(((FilePart) parts.get("fooPart")).filename()).isEqualTo("foo.txt");
assertThat(((FormFieldPart) parts.get("barPart")).value()).isEqualTo("bar");
}
catch(Exception e) {
return Mono.error(e);
@@ -115,9 +115,9 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
return request.body(BodyExtractors.toParts()).collectList()
.flatMap(parts -> {
try {
assertEquals(2, parts.size());
assertEquals("foo.txt", ((FilePart) parts.get(0)).filename());
assertEquals("bar", ((FormFieldPart) parts.get(1)).value());
assertThat(parts.size()).isEqualTo(2);
assertThat(((FilePart) parts.get(0)).filename()).isEqualTo("foo.txt");
assertThat(((FormFieldPart) parts.get(1)).value()).isEqualTo("bar");
}
catch(Exception e) {
return Mono.error(e);

View File

@@ -37,8 +37,7 @@ import org.springframework.mock.http.client.reactive.test.MockClientHttpRequest;
import org.springframework.web.reactive.function.BodyInserter;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.http.HttpMethod.DELETE;
@@ -60,22 +59,22 @@ public class DefaultClientRequestBuilderTests {
.headers(httpHeaders -> httpHeaders.set("foo", "baar"))
.cookies(cookies -> cookies.set("baz", "quux"))
.build();
assertEquals(new URI("https://example.com"), result.url());
assertEquals(GET, result.method());
assertEquals(1, result.headers().size());
assertEquals("baar", result.headers().getFirst("foo"));
assertEquals(1, result.cookies().size());
assertEquals("quux", result.cookies().getFirst("baz"));
assertThat(result.url()).isEqualTo(new URI("https://example.com"));
assertThat(result.method()).isEqualTo(GET);
assertThat(result.headers().size()).isEqualTo(1);
assertThat(result.headers().getFirst("foo")).isEqualTo("baar");
assertThat(result.cookies().size()).isEqualTo(1);
assertThat(result.cookies().getFirst("baz")).isEqualTo("quux");
}
@Test
public void method() throws URISyntaxException {
URI url = new URI("https://example.com");
ClientRequest.Builder builder = ClientRequest.create(DELETE, url);
assertEquals(DELETE, builder.build().method());
assertThat(builder.build().method()).isEqualTo(DELETE);
builder.method(OPTIONS);
assertEquals(OPTIONS, builder.build().method());
assertThat(builder.build().method()).isEqualTo(OPTIONS);
}
@Test
@@ -83,17 +82,17 @@ public class DefaultClientRequestBuilderTests {
URI url1 = new URI("https://example.com/foo");
URI url2 = new URI("https://example.com/bar");
ClientRequest.Builder builder = ClientRequest.create(DELETE, url1);
assertEquals(url1, builder.build().url());
assertThat(builder.build().url()).isEqualTo(url1);
builder.url(url2);
assertEquals(url2, builder.build().url());
assertThat(builder.build().url()).isEqualTo(url2);
}
@Test
public void cookie() {
ClientRequest result = ClientRequest.create(GET, URI.create("https://example.com"))
.cookie("foo", "bar").build();
assertEquals("bar", result.cookies().getFirst("foo"));
assertThat(result.cookies().getFirst("foo")).isEqualTo("bar");
}
@Test
@@ -108,8 +107,8 @@ public class DefaultClientRequestBuilderTests {
result.writeTo(request, strategies).block();
assertEquals("MyValue", request.getHeaders().getFirst("MyKey"));
assertEquals("bar", request.getCookies().getFirst("foo").getValue());
assertThat(request.getHeaders().getFirst("MyKey")).isEqualTo("MyValue");
assertThat(request.getCookies().getFirst("foo").getValue()).isEqualTo("bar");
StepVerifier.create(request.getBody()).expectComplete().verify();
}
@@ -135,7 +134,7 @@ public class DefaultClientRequestBuilderTests {
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
result.writeTo(request, strategies).block();
assertNotNull(request.getBody());
assertThat(request.getBody()).isNotNull();
StepVerifier.create(request.getBody())
.expectNextCount(1)
@@ -157,7 +156,7 @@ public class DefaultClientRequestBuilderTests {
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
result.writeTo(request, strategies).block();
assertNotNull(request.getBody());
assertThat(request.getBody()).isNotNull();
StepVerifier.create(request.getBody())
.expectNextCount(1)
@@ -180,7 +179,7 @@ public class DefaultClientRequestBuilderTests {
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
result.writeTo(request, strategies).block();
assertNotNull(request.getBody());
assertThat(request.getBody()).isNotNull();
StepVerifier.create(request.getBody())
.expectNextCount(1)

View File

@@ -30,8 +30,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -57,11 +56,11 @@ public class DefaultClientResponseBuilderTests {
.body(body)
.build();
assertEquals(HttpStatus.BAD_GATEWAY, response.statusCode());
assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_GATEWAY);
HttpHeaders responseHeaders = response.headers().asHttpHeaders();
assertEquals("bar", responseHeaders.getFirst("foo"));
assertNotNull("qux", response.cookies().getFirst("baz"));
assertEquals("qux", response.cookies().getFirst("baz").getValue());
assertThat(responseHeaders.getFirst("foo")).isEqualTo("bar");
assertThat(response.cookies().getFirst("baz")).as("qux").isNotNull();
assertThat(response.cookies().getFirst("baz").getValue()).isEqualTo("qux");
StepVerifier.create(response.bodyToFlux(String.class))
.expectNext("baz")
@@ -90,11 +89,11 @@ public class DefaultClientResponseBuilderTests {
.body(body)
.build();
assertEquals(HttpStatus.BAD_REQUEST, result.statusCode());
assertEquals(1, result.headers().asHttpHeaders().size());
assertEquals("baar", result.headers().asHttpHeaders().getFirst("foo"));
assertEquals(1, result.cookies().size());
assertEquals("quux", result.cookies().getFirst("baz").getValue());
assertThat(result.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(result.headers().asHttpHeaders().size()).isEqualTo(1);
assertThat(result.headers().asHttpHeaders().getFirst("foo")).isEqualTo("baar");
assertThat(result.cookies().size()).isEqualTo(1);
assertThat(result.cookies().getFirst("baz").getValue()).isEqualTo("quux");
StepVerifier.create(result.bodyToFlux(String.class))
.expectNext("baz")

View File

@@ -46,9 +46,8 @@ import org.springframework.http.codec.HttpMessageReader;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
@@ -79,7 +78,7 @@ public class DefaultClientResponseTests {
HttpStatus status = HttpStatus.CONTINUE;
given(mockResponse.getStatusCode()).willReturn(status);
assertEquals(status, defaultClientResponse.statusCode());
assertThat(defaultClientResponse.statusCode()).isEqualTo(status);
}
@Test
@@ -87,7 +86,7 @@ public class DefaultClientResponseTests {
int status = 999;
given(mockResponse.getRawStatusCode()).willReturn(status);
assertEquals(status, defaultClientResponse.rawStatusCode());
assertThat(defaultClientResponse.rawStatusCode()).isEqualTo(status);
}
@Test
@@ -105,9 +104,9 @@ public class DefaultClientResponseTests {
given(mockResponse.getHeaders()).willReturn(httpHeaders);
ClientResponse.Headers headers = defaultClientResponse.headers();
assertEquals(OptionalLong.of(contentLength), headers.contentLength());
assertEquals(Optional.of(contentType), headers.contentType());
assertEquals(httpHeaders, headers.asHttpHeaders());
assertThat(headers.contentLength()).isEqualTo(OptionalLong.of(contentLength));
assertThat(headers.contentType()).isEqualTo(Optional.of(contentType));
assertThat(headers.asHttpHeaders()).isEqualTo(httpHeaders);
}
@Test
@@ -118,7 +117,7 @@ public class DefaultClientResponseTests {
given(mockResponse.getCookies()).willReturn(cookies);
assertSame(cookies, defaultClientResponse.cookies());
assertThat(defaultClientResponse.cookies()).isSameAs(cookies);
}
@@ -135,7 +134,7 @@ public class DefaultClientResponseTests {
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.body(toMono(String.class));
assertEquals("foo", resultMono.block());
assertThat(resultMono.block()).isEqualTo("foo");
}
@Test
@@ -151,7 +150,7 @@ public class DefaultClientResponseTests {
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.bodyToMono(String.class);
assertEquals("foo", resultMono.block());
assertThat(resultMono.block()).isEqualTo("foo");
}
@Test
@@ -169,7 +168,7 @@ public class DefaultClientResponseTests {
Mono<String> resultMono =
defaultClientResponse.bodyToMono(new ParameterizedTypeReference<String>() {
});
assertEquals("foo", resultMono.block());
assertThat(resultMono.block()).isEqualTo("foo");
}
@Test
@@ -186,7 +185,7 @@ public class DefaultClientResponseTests {
Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class);
Mono<List<String>> result = resultFlux.collectList();
assertEquals(Collections.singletonList("foo"), result.block());
assertThat(result.block()).isEqualTo(Collections.singletonList("foo"));
}
@Test
@@ -205,7 +204,7 @@ public class DefaultClientResponseTests {
defaultClientResponse.bodyToFlux(new ParameterizedTypeReference<String>() {
});
Mono<List<String>> result = resultFlux.collectList();
assertEquals(Collections.singletonList("foo"), result.block());
assertThat(result.block()).isEqualTo(Collections.singletonList("foo"));
}
@Test
@@ -221,10 +220,10 @@ public class DefaultClientResponseTests {
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block();
assertEquals("foo", result.getBody());
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue());
assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
assertThat(result.getBody()).isEqualTo("foo");
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getStatusCodeValue()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
}
@Test
@@ -246,11 +245,11 @@ public class DefaultClientResponseTests {
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block();
assertEquals("foo", result.getBody());
assertThat(result.getBody()).isEqualTo("foo");
assertThatIllegalArgumentException().isThrownBy(
result::getStatusCode);
assertEquals(999, result.getStatusCodeValue());
assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
assertThat(result.getStatusCodeValue()).isEqualTo(999);
assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
}
@Test
@@ -268,10 +267,10 @@ public class DefaultClientResponseTests {
ResponseEntity<String> result = defaultClientResponse.toEntity(
new ParameterizedTypeReference<String>() {
}).block();
assertEquals("foo", result.getBody());
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue());
assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
assertThat(result.getBody()).isEqualTo("foo");
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getStatusCodeValue()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
}
@Test
@@ -287,10 +286,10 @@ public class DefaultClientResponseTests {
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block();
assertEquals(Collections.singletonList("foo"), result.getBody());
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue());
assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
assertThat(result.getBody()).isEqualTo(Collections.singletonList("foo"));
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getStatusCodeValue()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
}
@Test
@@ -312,11 +311,11 @@ public class DefaultClientResponseTests {
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block();
assertEquals(Collections.singletonList("foo"), result.getBody());
assertThat(result.getBody()).isEqualTo(Collections.singletonList("foo"));
assertThatIllegalArgumentException().isThrownBy(
result::getStatusCode);
assertEquals(999, result.getStatusCodeValue());
assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
assertThat(result.getStatusCodeValue()).isEqualTo(999);
assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
}
@Test
@@ -335,10 +334,10 @@ public class DefaultClientResponseTests {
ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(
new ParameterizedTypeReference<String>() {
}).block();
assertEquals(Collections.singletonList("foo"), result.getBody());
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue());
assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType());
assertThat(result.getBody()).isEqualTo(Collections.singletonList("foo"));
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getStatusCodeValue()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
}

View File

@@ -34,10 +34,8 @@ import org.springframework.core.NamedThreadLocal;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -76,9 +74,9 @@ public class DefaultWebClientTests {
.exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("/base/path", request.url().toString());
assertEquals(new HttpHeaders(), request.headers());
assertEquals(Collections.emptyMap(), request.cookies());
assertThat(request.url().toString()).isEqualTo("/base/path");
assertThat(request.headers()).isEqualTo(new HttpHeaders());
assertThat(request.cookies()).isEqualTo(Collections.emptyMap());
}
@Test
@@ -88,7 +86,7 @@ public class DefaultWebClientTests {
.exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("/base/path?q=12", request.url().toString());
assertThat(request.url().toString()).isEqualTo("/base/path?q=12");
}
@Test // gh-22705
@@ -98,8 +96,8 @@ public class DefaultWebClientTests {
.exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("/base/path/identifier?q=12", request.url().toString());
assertEquals("/path/{id}", request.attribute(WebClient.class.getName() + ".uriTemplate").get());
assertThat(request.url().toString()).isEqualTo("/base/path/identifier?q=12");
assertThat(request.attribute(WebClient.class.getName() + ".uriTemplate").get()).isEqualTo("/path/{id}");
}
@Test
@@ -109,7 +107,7 @@ public class DefaultWebClientTests {
.exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("/path", request.url().toString());
assertThat(request.url().toString()).isEqualTo("/path");
}
@Test
@@ -119,8 +117,8 @@ public class DefaultWebClientTests {
.exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("application/json", request.headers().getFirst("Accept"));
assertEquals("123", request.cookies().getFirst("id"));
assertThat(request.headers().getFirst("Accept")).isEqualTo("application/json");
assertThat(request.cookies().getFirst("id")).isEqualTo("123");
}
@Test
@@ -132,8 +130,8 @@ public class DefaultWebClientTests {
client.get().uri("/path").exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("application/json", request.headers().getFirst("Accept"));
assertEquals("123", request.cookies().getFirst("id"));
assertThat(request.headers().getFirst("Accept")).isEqualTo("application/json");
assertThat(request.cookies().getFirst("id")).isEqualTo("123");
}
@Test
@@ -149,8 +147,8 @@ public class DefaultWebClientTests {
.exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("application/xml", request.headers().getFirst("Accept"));
assertEquals("456", request.cookies().getFirst("id"));
assertThat(request.headers().getFirst("Accept")).isEqualTo("application/xml");
assertThat(request.cookies().getFirst("id")).isEqualTo("456");
}
@Test
@@ -177,7 +175,7 @@ public class DefaultWebClientTests {
context.remove();
}
assertEquals("bar", actual.get("foo"));
assertThat(actual.get("foo")).isEqualTo("bar");
}
@Test
@@ -214,19 +212,19 @@ public class DefaultWebClientTests {
// Now, verify what each client has..
WebClient.Builder builder1 = client1.mutate();
builder1.filters(filters -> assertEquals(1, filters.size()));
builder1.defaultHeaders(headers -> assertEquals(1, headers.size()));
builder1.defaultCookies(cookies -> assertEquals(1, cookies.size()));
builder1.filters(filters -> assertThat(filters.size()).isEqualTo(1));
builder1.defaultHeaders(headers -> assertThat(headers.size()).isEqualTo(1));
builder1.defaultCookies(cookies -> assertThat(cookies.size()).isEqualTo(1));
WebClient.Builder builder2 = client2.mutate();
builder2.filters(filters -> assertEquals(2, filters.size()));
builder2.defaultHeaders(headers -> assertEquals(2, headers.size()));
builder2.defaultCookies(cookies -> assertEquals(2, cookies.size()));
builder2.filters(filters -> assertThat(filters.size()).isEqualTo(2));
builder2.defaultHeaders(headers -> assertThat(headers.size()).isEqualTo(2));
builder2.defaultCookies(cookies -> assertThat(cookies.size()).isEqualTo(2));
WebClient.Builder builder1a = client1a.mutate();
builder1a.filters(filters -> assertEquals(2, filters.size()));
builder1a.defaultHeaders(headers -> assertEquals(2, headers.size()));
builder1a.defaultCookies(cookies -> assertEquals(2, cookies.size()));
builder1a.filters(filters -> assertThat(filters.size()).isEqualTo(2));
builder1a.defaultHeaders(headers -> assertThat(headers.size()).isEqualTo(2));
builder1a.defaultCookies(cookies -> assertThat(cookies.size()).isEqualTo(2));
}
@Test
@@ -242,10 +240,10 @@ public class DefaultWebClientTests {
.attribute("foo", "bar")
.exchange().block(Duration.ofSeconds(10));
assertEquals("bar", actual.get("foo"));
assertThat(actual.get("foo")).isEqualTo("bar");
ClientRequest request = verifyAndGetRequest();
assertEquals("bar", request.attribute("foo").get());
assertThat(request.attribute("foo").get()).isEqualTo("bar");
}
@Test
@@ -261,10 +259,10 @@ public class DefaultWebClientTests {
.attribute("foo", null)
.exchange().block(Duration.ofSeconds(10));
assertNull(actual.get("foo"));
assertThat(actual.get("foo")).isNull();
ClientRequest request = verifyAndGetRequest();
assertFalse(request.attribute("foo").isPresent());
assertThat(request.attribute("foo").isPresent()).isFalse();
}
@Test
@@ -278,8 +276,8 @@ public class DefaultWebClientTests {
client.get().uri("/path").exchange().block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("application/json", request.headers().getFirst("Accept"));
assertEquals("123", request.cookies().getFirst("id"));
assertThat(request.headers().getFirst("Accept")).isEqualTo("application/json");
assertThat(request.cookies().getFirst("id")).isEqualTo("123");
}
@Test
@@ -306,7 +304,7 @@ public class DefaultWebClientTests {
verifyZeroInteractions(this.exchangeFunction);
exchange.block(Duration.ofSeconds(10));
ClientRequest request = verifyAndGetRequest();
assertEquals("value", request.headers().getFirst("Custom"));
assertThat(request.headers().getFirst("Custom")).isEqualTo("value");
}
private ClientRequest verifyAndGetRequest() {

View File

@@ -33,10 +33,8 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.BodyExtractors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -58,15 +56,15 @@ public class ExchangeFilterFunctionsTests {
boolean[] filtersInvoked = new boolean[2];
ExchangeFilterFunction filter1 = (r, n) -> {
assertFalse(filtersInvoked[0]);
assertFalse(filtersInvoked[1]);
assertThat(filtersInvoked[0]).isFalse();
assertThat(filtersInvoked[1]).isFalse();
filtersInvoked[0] = true;
assertFalse(filtersInvoked[1]);
assertThat(filtersInvoked[1]).isFalse();
return n.exchange(r);
};
ExchangeFilterFunction filter2 = (r, n) -> {
assertTrue(filtersInvoked[0]);
assertFalse(filtersInvoked[1]);
assertThat(filtersInvoked[0]).isTrue();
assertThat(filtersInvoked[1]).isFalse();
filtersInvoked[1] = true;
return n.exchange(r);
};
@@ -74,10 +72,10 @@ public class ExchangeFilterFunctionsTests {
ClientResponse result = filter.filter(request, exchange).block();
assertEquals(response, result);
assertThat(result).isEqualTo(response);
assertTrue(filtersInvoked[0]);
assertTrue(filtersInvoked[1]);
assertThat(filtersInvoked[0]).isTrue();
assertThat(filtersInvoked[1]).isTrue();
}
@Test
@@ -88,15 +86,15 @@ public class ExchangeFilterFunctionsTests {
boolean[] filterInvoked = new boolean[1];
ExchangeFilterFunction filter = (r, n) -> {
assertFalse(filterInvoked[0]);
assertThat(filterInvoked[0]).isFalse();
filterInvoked[0] = true;
return n.exchange(r);
};
ExchangeFunction filteredExchange = filter.apply(exchange);
ClientResponse result = filteredExchange.exchange(request).block();
assertEquals(response, result);
assertTrue(filterInvoked[0]);
assertThat(result).isEqualTo(response);
assertThat(filterInvoked[0]).isTrue();
}
@Test
@@ -105,15 +103,15 @@ public class ExchangeFilterFunctionsTests {
ClientResponse response = mock(ClientResponse.class);
ExchangeFunction exchange = r -> {
assertTrue(r.headers().containsKey(HttpHeaders.AUTHORIZATION));
assertTrue(r.headers().getFirst(HttpHeaders.AUTHORIZATION).startsWith("Basic "));
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isTrue();
assertThat(r.headers().getFirst(HttpHeaders.AUTHORIZATION).startsWith("Basic ")).isTrue();
return Mono.just(response);
};
ExchangeFilterFunction auth = ExchangeFilterFunctions.basicAuthentication("foo", "bar");
assertFalse(request.headers().containsKey(HttpHeaders.AUTHORIZATION));
assertThat(request.headers().containsKey(HttpHeaders.AUTHORIZATION)).isFalse();
ClientResponse result = auth.filter(request, exchange).block();
assertEquals(response, result);
assertThat(result).isEqualTo(response);
}
@Test
@@ -135,15 +133,15 @@ public class ExchangeFilterFunctionsTests {
ClientResponse response = mock(ClientResponse.class);
ExchangeFunction exchange = r -> {
assertTrue(r.headers().containsKey(HttpHeaders.AUTHORIZATION));
assertTrue(r.headers().getFirst(HttpHeaders.AUTHORIZATION).startsWith("Basic "));
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isTrue();
assertThat(r.headers().getFirst(HttpHeaders.AUTHORIZATION).startsWith("Basic ")).isTrue();
return Mono.just(response);
};
ExchangeFilterFunction auth = ExchangeFilterFunctions.basicAuthentication();
assertFalse(request.headers().containsKey(HttpHeaders.AUTHORIZATION));
assertThat(request.headers().containsKey(HttpHeaders.AUTHORIZATION)).isFalse();
ClientResponse result = auth.filter(request, exchange).block();
assertEquals(response, result);
assertThat(result).isEqualTo(response);
}
@Test
@@ -153,14 +151,14 @@ public class ExchangeFilterFunctionsTests {
ClientResponse response = mock(ClientResponse.class);
ExchangeFunction exchange = r -> {
assertFalse(r.headers().containsKey(HttpHeaders.AUTHORIZATION));
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isFalse();
return Mono.just(response);
};
ExchangeFilterFunction auth = ExchangeFilterFunctions.basicAuthentication();
assertFalse(request.headers().containsKey(HttpHeaders.AUTHORIZATION));
assertThat(request.headers().containsKey(HttpHeaders.AUTHORIZATION)).isFalse();
ClientResponse result = auth.filter(request, exchange).block();
assertEquals(response, result);
assertThat(result).isEqualTo(response);
}
@Test
@@ -211,8 +209,8 @@ public class ExchangeFilterFunctionsTests {
.filter(request, req -> Mono.just(response));
StepVerifier.create(result.flatMapMany(res -> res.body(BodyExtractors.toDataBuffers())))
.consumeNextWith(buffer -> assertEquals("foo", string(buffer)))
.consumeNextWith(buffer -> assertEquals("ba", string(buffer)))
.consumeNextWith(buffer -> assertThat(string(buffer)).isEqualTo("foo"))
.consumeNextWith(buffer -> assertThat(string(buffer)).isEqualTo("ba"))
.expectComplete()
.verify();

View File

@@ -18,8 +18,7 @@ package org.springframework.web.reactive.function.client;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -29,15 +28,15 @@ public class ExchangeStrategiesTests {
@Test
public void empty() {
ExchangeStrategies strategies = ExchangeStrategies.empty().build();
assertTrue(strategies.messageReaders().isEmpty());
assertTrue(strategies.messageWriters().isEmpty());
assertThat(strategies.messageReaders().isEmpty()).isTrue();
assertThat(strategies.messageWriters().isEmpty()).isTrue();
}
@Test
public void withDefaults() {
ExchangeStrategies strategies = ExchangeStrategies.withDefaults();
assertFalse(strategies.messageReaders().isEmpty());
assertFalse(strategies.messageWriters().isEmpty());
assertThat(strategies.messageReaders().isEmpty()).isFalse();
assertThat(strategies.messageWriters().isEmpty()).isFalse();
}
}

View File

@@ -38,8 +38,7 @@ import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.client.reactive.ReactorResourceFactory;
import org.springframework.web.reactive.function.UnsupportedMediaTypeException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* WebClient integration tests focusing on data buffer management.
@@ -105,7 +104,7 @@ public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAlloca
.bodyToMono(Void.class);
StepVerifier.create(mono).expectComplete().verify(Duration.ofSeconds(3));
assertEquals(1, this.server.getRequestCount());
assertThat(this.server.getRequestCount()).isEqualTo(1);
}
@Test // SPR-17482
@@ -121,7 +120,7 @@ public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAlloca
.bodyToMono(new ParameterizedTypeReference<Map<String, String>>() {});
StepVerifier.create(mono).expectError(UnsupportedMediaTypeException.class).verify(Duration.ofSeconds(3));
assertEquals(1, this.server.getRequestCount());
assertThat(this.server.getRequestCount()).isEqualTo(1);
}
@Test
@@ -164,8 +163,8 @@ public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAlloca
.onStatus(status -> status.equals(errorStatus), exceptionFunction)
.bodyToMono(String.class);
StepVerifier.create(mono).expectErrorSatisfies(actual -> assertSame(expected, actual)).verify(DELAY);
assertEquals(1, this.server.getRequestCount());
StepVerifier.create(mono).expectErrorSatisfies(actual -> assertThat(actual).isSameAs(expected)).verify(DELAY);
assertThat(this.server.getRequestCount()).isEqualTo(1);
}
}

View File

@@ -56,10 +56,6 @@ import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.codec.Pojo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Integration tests using an {@link ExchangeFunction} through {@link WebClient}.
@@ -118,15 +114,15 @@ public class WebClientIntegrationTests {
StepVerifier.create(result)
.consumeNextWith(
httpHeaders -> {
assertEquals(MediaType.TEXT_PLAIN, httpHeaders.getContentType());
assertEquals(13L, httpHeaders.getContentLength());
assertThat(httpHeaders.getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(httpHeaders.getContentLength()).isEqualTo(13L);
})
.expectComplete().verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -146,9 +142,9 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("testvalue", request.getHeader("X-Test-Header"));
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader("X-Test-Header")).isEqualTo("testvalue");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -168,9 +164,9 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("testvalue", request.getHeader("X-Test-Header"));
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader("X-Test-Header")).isEqualTo("testvalue");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -191,8 +187,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/json", request.getPath());
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertThat(request.getPath()).isEqualTo("/json");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
});
}
@@ -210,15 +206,15 @@ public class WebClientIntegrationTests {
StepVerifier.create(result)
.assertNext(valueContainer -> {
Foo foo = valueContainer.getContainerValue();
assertNotNull(foo);
assertEquals("bar", foo.getFooValue());
assertThat(foo).isNotNull();
assertThat(foo.getFooValue()).isEqualTo("bar");
})
.expectComplete().verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/json", request.getPath());
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertThat(request.getPath()).isEqualTo("/json");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
});
}
@@ -235,17 +231,17 @@ public class WebClientIntegrationTests {
StepVerifier.create(result)
.consumeNextWith(entity -> {
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(MediaType.APPLICATION_JSON, entity.getHeaders().getContentType());
assertEquals(31, entity.getHeaders().getContentLength());
assertEquals(content, entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
assertThat(entity.getHeaders().getContentLength()).isEqualTo(31);
assertThat(entity.getBody()).isEqualTo(content);
})
.expectComplete().verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/json", request.getPath());
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertThat(request.getPath()).isEqualTo("/json");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
});
}
@@ -262,19 +258,19 @@ public class WebClientIntegrationTests {
StepVerifier.create(result)
.consumeNextWith(entity -> {
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(MediaType.APPLICATION_JSON, entity.getHeaders().getContentType());
assertEquals(58, entity.getHeaders().getContentLength());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
assertThat(entity.getHeaders().getContentLength()).isEqualTo(58);
Pojo pojo1 = new Pojo("foo1", "bar1");
Pojo pojo2 = new Pojo("foo2", "bar2");
assertEquals(Arrays.asList(pojo1, pojo2), entity.getBody());
assertThat(entity.getBody()).isEqualTo(Arrays.asList(pojo1, pojo2));
})
.expectComplete().verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/json", request.getPath());
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertThat(request.getPath()).isEqualTo("/json");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
});
}
@@ -295,8 +291,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/json", request.getPath());
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertThat(request.getPath()).isEqualTo("/json");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
});
}
@@ -313,14 +309,14 @@ public class WebClientIntegrationTests {
.bodyToMono(Pojo.class);
StepVerifier.create(result)
.consumeNextWith(p -> assertEquals("barbar", p.getBar()))
.consumeNextWith(p -> assertThat(p.getBar()).isEqualTo("barbar"))
.expectComplete()
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/pojo", request.getPath());
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertThat(request.getPath()).isEqualTo("/pojo");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
});
}
@@ -344,8 +340,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/pojos", request.getPath());
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertThat(request.getPath()).isEqualTo("/pojos");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
});
}
@@ -363,17 +359,17 @@ public class WebClientIntegrationTests {
.bodyToMono(Pojo.class);
StepVerifier.create(result)
.consumeNextWith(p -> assertEquals("BARBAR", p.getBar()))
.consumeNextWith(p -> assertThat(p.getBar()).isEqualTo("BARBAR"))
.expectComplete()
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/pojo/capitalize", request.getPath());
assertEquals("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}", request.getBody().readUtf8());
assertEquals("31", request.getHeader(HttpHeaders.CONTENT_LENGTH));
assertEquals("application/json", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("application/json", request.getHeader(HttpHeaders.CONTENT_TYPE));
assertThat(request.getPath()).isEqualTo("/pojo/capitalize");
assertThat(request.getBody().readUtf8()).isEqualTo("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}");
assertThat(request.getHeader(HttpHeaders.CONTENT_LENGTH)).isEqualTo("31");
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo("application/json");
});
}
@@ -395,8 +391,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("/test", request.getPath());
assertEquals("testkey=testvalue", request.getHeader(HttpHeaders.COOKIE));
assertThat(request.getPath()).isEqualTo("/test");
assertThat(request.getHeader(HttpHeaders.COOKIE)).isEqualTo("testkey=testvalue");
});
}
@@ -423,8 +419,8 @@ public class WebClientIntegrationTests {
catch (IOException ex) {
throw new IllegalStateException(ex);
}
assertEquals(expected.length, actual.size());
assertEquals(hash(expected), hash(actual.toByteArray()));
assertThat(actual.size()).isEqualTo(expected.length);
assertThat(hash(actual.toByteArray())).isEqualTo(hash(expected));
});
}
@@ -442,14 +438,14 @@ public class WebClientIntegrationTests {
Mono<ClientResponse> result = this.webClient.get().uri("/greeting?name=Spring").exchange();
StepVerifier.create(result)
.consumeNextWith(response -> assertEquals(HttpStatus.NOT_FOUND, response.statusCode()))
.consumeNextWith(response -> assertThat(response.statusCode()).isEqualTo(HttpStatus.NOT_FOUND))
.expectComplete()
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -469,8 +465,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -489,8 +485,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting");
});
}
@@ -508,33 +504,32 @@ public class WebClientIntegrationTests {
StepVerifier.create(result)
.expectErrorSatisfies(throwable -> {
assertTrue(throwable instanceof WebClientResponseException);
assertThat(throwable instanceof WebClientResponseException).isTrue();
WebClientResponseException ex = (WebClientResponseException) throwable;
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getRawStatusCode());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),
ex.getStatusText());
assertEquals(MediaType.TEXT_PLAIN, ex.getHeaders().getContentType());
assertEquals(errorMessage, ex.getResponseBodyAsString());
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(ex.getRawStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.value());
assertThat(ex.getStatusText()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
assertThat(ex.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage);
HttpRequest request = ex.getRequest();
assertEquals(HttpMethod.GET, request.getMethod());
assertEquals(URI.create(this.server.url(path).toString()), request.getURI());
assertNotNull(request.getHeaders());
assertThat(request.getMethod()).isEqualTo(HttpMethod.GET);
assertThat(request.getURI()).isEqualTo(URI.create(this.server.url(path).toString()));
assertThat(request.getHeaders()).isNotNull();
})
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals(path, request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo(path);
});
}
@Test
public void shouldSupportUnknownStatusCode() {
int errorStatus = 555;
assertNull(HttpStatus.resolve(errorStatus));
assertThat((Object) HttpStatus.resolve(errorStatus)).isNull();
String errorMessage = "Something went wrong";
prepareResponse(response -> response.setResponseCode(errorStatus)
.setHeader("Content-Type", "text/plain").setBody(errorMessage));
@@ -544,21 +539,21 @@ public class WebClientIntegrationTests {
.exchange();
StepVerifier.create(result)
.consumeNextWith(response -> assertEquals(555, response.rawStatusCode()))
.consumeNextWith(response -> assertThat(response.rawStatusCode()).isEqualTo(555))
.expectComplete()
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/unknownPage", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/unknownPage");
});
}
@Test
public void shouldGetErrorSignalWhenRetrievingUnknownStatusCode() {
int errorStatus = 555;
assertNull(HttpStatus.resolve(errorStatus));
assertThat((Object) HttpStatus.resolve(errorStatus)).isNull();
String errorMessage = "Something went wrong";
prepareResponse(response -> response.setResponseCode(errorStatus)
.setHeader("Content-Type", "text/plain").setBody(errorMessage));
@@ -570,20 +565,20 @@ public class WebClientIntegrationTests {
StepVerifier.create(result)
.expectErrorSatisfies(throwable -> {
assertTrue(throwable instanceof UnknownHttpStatusCodeException);
assertThat(throwable instanceof UnknownHttpStatusCodeException).isTrue();
UnknownHttpStatusCodeException ex = (UnknownHttpStatusCodeException) throwable;
assertEquals("Unknown status code ["+errorStatus+"]", ex.getMessage());
assertEquals(errorStatus, ex.getRawStatusCode());
assertEquals("", ex.getStatusText());
assertEquals(MediaType.TEXT_PLAIN, ex.getHeaders().getContentType());
assertEquals(errorMessage, ex.getResponseBodyAsString());
assertThat(ex.getMessage()).isEqualTo(("Unknown status code ["+errorStatus+"]"));
assertThat(ex.getRawStatusCode()).isEqualTo(errorStatus);
assertThat(ex.getStatusText()).isEqualTo("");
assertThat(ex.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage);
})
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/unknownPage", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/unknownPage");
});
}
@@ -604,8 +599,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -626,8 +621,8 @@ public class WebClientIntegrationTests {
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -642,14 +637,14 @@ public class WebClientIntegrationTests {
.flatMap(response -> response.toEntity(String.class));
StepVerifier.create(result)
.consumeNextWith(response -> assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()))
.consumeNextWith(response -> assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND))
.expectComplete()
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> {
assertEquals("*/*", request.getHeader(HttpHeaders.ACCEPT));
assertEquals("/greeting?name=Spring", request.getPath());
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("*/*");
assertThat(request.getPath()).isEqualTo("/greeting?name=Spring");
});
}
@@ -677,7 +672,7 @@ public class WebClientIntegrationTests {
.verify(Duration.ofSeconds(3));
expectRequestCount(1);
expectRequest(request -> assertEquals("bar", request.getHeader("foo")));
expectRequest(request -> assertThat(request.getHeader("foo")).isEqualTo("bar"));
}
@Test
@@ -733,7 +728,7 @@ public class WebClientIntegrationTests {
.flatMap(response -> response.toEntity(Void.class));
StepVerifier.create(result).assertNext(r ->
assertTrue(r.getStatusCode().is2xxSuccessful())
assertThat(r.getStatusCode().is2xxSuccessful()).isTrue()
).verifyComplete();
}
@@ -764,7 +759,7 @@ public class WebClientIntegrationTests {
}
private void expectRequestCount(int count) {
assertEquals(count, this.server.getRequestCount());
assertThat(this.server.getRequestCount()).isEqualTo(count);
}

View File

@@ -34,8 +34,7 @@ import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.client.ClientResponse;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -56,7 +55,7 @@ public class ClientResponseWrapperTests {
@Test
public void response() {
assertSame(mockResponse, wrapper.response());
assertThat(wrapper.response()).isSameAs(mockResponse);
}
@Test
@@ -64,7 +63,7 @@ public class ClientResponseWrapperTests {
HttpStatus status = HttpStatus.BAD_REQUEST;
given(mockResponse.statusCode()).willReturn(status);
assertSame(status, wrapper.statusCode());
assertThat(wrapper.statusCode()).isSameAs(status);
}
@Test
@@ -72,7 +71,7 @@ public class ClientResponseWrapperTests {
int status = 999;
given(mockResponse.rawStatusCode()).willReturn(status);
assertEquals(status, wrapper.rawStatusCode());
assertThat(wrapper.rawStatusCode()).isEqualTo(status);
}
@Test
@@ -80,7 +79,7 @@ public class ClientResponseWrapperTests {
ClientResponse.Headers headers = mock(ClientResponse.Headers.class);
given(mockResponse.headers()).willReturn(headers);
assertSame(headers, wrapper.headers());
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
@@ -89,7 +88,7 @@ public class ClientResponseWrapperTests {
MultiValueMap<String, ResponseCookie> cookies = mock(MultiValueMap.class);
given(mockResponse.cookies()).willReturn(cookies);
assertSame(cookies, wrapper.cookies());
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
@@ -98,7 +97,7 @@ public class ClientResponseWrapperTests {
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockResponse.body(extractor)).willReturn(result);
assertSame(result, wrapper.body(extractor));
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
@@ -106,7 +105,7 @@ public class ClientResponseWrapperTests {
Mono<String> result = Mono.just("foo");
given(mockResponse.bodyToMono(String.class)).willReturn(result);
assertSame(result, wrapper.bodyToMono(String.class));
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
@@ -115,7 +114,7 @@ public class ClientResponseWrapperTests {
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
given(mockResponse.bodyToMono(reference)).willReturn(result);
assertSame(result, wrapper.bodyToMono(reference));
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
@@ -123,7 +122,7 @@ public class ClientResponseWrapperTests {
Flux<String> result = Flux.just("foo");
given(mockResponse.bodyToFlux(String.class)).willReturn(result);
assertSame(result, wrapper.bodyToFlux(String.class));
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
@@ -132,7 +131,7 @@ public class ClientResponseWrapperTests {
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
given(mockResponse.bodyToFlux(reference)).willReturn(result);
assertSame(result, wrapper.bodyToFlux(reference));
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
@Test
@@ -140,7 +139,7 @@ public class ClientResponseWrapperTests {
Mono<ResponseEntity<String>> result = Mono.just(new ResponseEntity<>("foo", HttpStatus.OK));
given(mockResponse.toEntity(String.class)).willReturn(result);
assertSame(result, wrapper.toEntity(String.class));
assertThat(wrapper.toEntity(String.class)).isSameAs(result);
}
@Test
@@ -149,7 +148,7 @@ public class ClientResponseWrapperTests {
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
given(mockResponse.toEntity(reference)).willReturn(result);
assertSame(result, wrapper.toEntity(reference));
assertThat(wrapper.toEntity(reference)).isSameAs(result);
}
@Test
@@ -157,7 +156,7 @@ public class ClientResponseWrapperTests {
Mono<ResponseEntity<List<String>>> result = Mono.just(new ResponseEntity<>(singletonList("foo"), HttpStatus.OK));
given(mockResponse.toEntityList(String.class)).willReturn(result);
assertSame(result, wrapper.toEntityList(String.class));
assertThat(wrapper.toEntityList(String.class)).isSameAs(result);
}
@Test
@@ -166,7 +165,7 @@ public class ClientResponseWrapperTests {
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
given(mockResponse.toEntityList(reference)).willReturn(result);
assertSame(result, wrapper.toEntityList(reference));
assertThat(wrapper.toEntityList(reference)).isSameAs(result);
}

View File

@@ -47,9 +47,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.result.view.ViewResolver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -60,14 +58,14 @@ public class DefaultEntityResponseBuilderTests {
public void fromObject() {
String body = "foo";
EntityResponse<String> response = EntityResponse.fromObject(body).build().block();
assertSame(body, response.entity());
assertThat(response.entity()).isSameAs(body);
}
@Test
public void fromPublisherClass() {
Flux<String> body = Flux.just("foo", "bar");
EntityResponse<Flux<String>> response = EntityResponse.fromPublisher(body, String.class).build().block();
assertSame(body, response.entity());
assertThat(response.entity()).isSameAs(body);
}
@Test
@@ -75,7 +73,7 @@ public class DefaultEntityResponseBuilderTests {
Flux<String> body = Flux.just("foo", "bar");
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
EntityResponse<Flux<String>> response = EntityResponse.fromPublisher(body, typeReference).build().block();
assertSame(body, response.entity());
assertThat(response.entity()).isSameAs(body);
}
@Test
@@ -218,7 +216,7 @@ public class DefaultEntityResponseBuilderTests {
.expectComplete()
.verify();
assertNotNull(exchange.getResponse().getBody());
assertThat(exchange.getResponse().getBody()).isNotNull();
}
@Test
@@ -237,7 +235,7 @@ public class DefaultEntityResponseBuilderTests {
responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();
@@ -262,7 +260,7 @@ public class DefaultEntityResponseBuilderTests {
responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();

View File

@@ -45,7 +45,7 @@ import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.reactive.result.view.ViewResolverSupport;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -173,7 +173,7 @@ public class DefaultRenderingResponseTests {
StepVerifier.create(result.flatMap(response -> response.writeTo(exchange, context)))
.verifyComplete();
assertEquals(ViewResolverSupport.DEFAULT_CONTENT_TYPE, exchange.getResponse().getHeaders().getContentType());
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(ViewResolverSupport.DEFAULT_CONTENT_TYPE);
}
@@ -204,7 +204,7 @@ public class DefaultRenderingResponseTests {
responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();
@@ -229,7 +229,7 @@ public class DefaultRenderingResponseTests {
responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();

View File

@@ -30,7 +30,7 @@ import org.springframework.http.ResponseCookie;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -61,11 +61,11 @@ public class DefaultServerRequestBuilderTests {
.body(body)
.build();
assertEquals(HttpMethod.HEAD, result.method());
assertEquals(1, result.headers().asHttpHeaders().size());
assertEquals("baar", result.headers().asHttpHeaders().getFirst("foo"));
assertEquals(1, result.cookies().size());
assertEquals("quux", result.cookies().getFirst("baz").getValue());
assertThat(result.method()).isEqualTo(HttpMethod.HEAD);
assertThat(result.headers().asHttpHeaders().size()).isEqualTo(1);
assertThat(result.headers().asHttpHeaders().getFirst("foo")).isEqualTo("baar");
assertThat(result.cookies().size()).isEqualTo(1);
assertThat(result.cookies().getFirst("baz").getValue()).isEqualTo("quux");
StepVerifier.create(result.bodyToFlux(String.class))
.expectNext("baz")

View File

@@ -56,9 +56,8 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebInputException;
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
/**
@@ -78,7 +77,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(method, "https://example.com")),
this.messageReaders);
assertEquals(method, request.method());
assertThat(request.method()).isEqualTo(method);
}
@Test
@@ -89,7 +88,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, uri)),
this.messageReaders);
assertEquals(uri, request.uri());
assertThat(request.uri()).isEqualTo(uri);
}
@Test
@@ -101,11 +100,11 @@ public class DefaultServerRequestTests {
URI result = request.uriBuilder().build();
assertEquals("http", result.getScheme());
assertEquals("localhost", result.getHost());
assertEquals(-1, result.getPort());
assertEquals("/path", result.getPath());
assertEquals("a=1", result.getQuery());
assertThat(result.getScheme()).isEqualTo("http");
assertThat(result.getHost()).isEqualTo("localhost");
assertThat(result.getPort()).isEqualTo(-1);
assertThat(result.getPath()).isEqualTo("/path");
assertThat(result.getQuery()).isEqualTo("a=1");
}
@Test
@@ -116,7 +115,7 @@ public class DefaultServerRequestTests {
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
assertEquals(Optional.of("bar"), request.attribute("foo"));
assertThat(request.attribute("foo")).isEqualTo(Optional.of("bar"));
}
@Test
@@ -125,7 +124,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo=bar")),
this.messageReaders);
assertEquals(Optional.of("bar"), request.queryParam("foo"));
assertThat(request.queryParam("foo")).isEqualTo(Optional.of("bar"));
}
@Test
@@ -134,7 +133,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
this.messageReaders);
assertEquals(Optional.of(""), request.queryParam("foo"));
assertThat(request.queryParam("foo")).isEqualTo(Optional.of(""));
}
@Test
@@ -143,7 +142,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
this.messageReaders);
assertEquals(Optional.empty(), request.queryParam("bar"));
assertThat(request.queryParam("bar")).isEqualTo(Optional.empty());
}
@Test
@@ -154,7 +153,7 @@ public class DefaultServerRequestTests {
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
assertEquals("bar", request.pathVariable("foo"));
assertThat(request.pathVariable("foo")).isEqualTo("bar");
}
@@ -178,7 +177,7 @@ public class DefaultServerRequestTests {
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
assertEquals(pathVariables, request.pathVariables());
assertThat(request.pathVariables()).isEqualTo(pathVariables);
}
@Test
@@ -205,11 +204,11 @@ public class DefaultServerRequestTests {
this.messageReaders);
ServerRequest.Headers headers = request.headers();
assertEquals(accept, headers.accept());
assertEquals(acceptCharset, headers.acceptCharset());
assertEquals(OptionalLong.of(contentLength), headers.contentLength());
assertEquals(Optional.of(contentType), headers.contentType());
assertEquals(httpHeaders, headers.asHttpHeaders());
assertThat(headers.accept()).isEqualTo(accept);
assertThat(headers.acceptCharset()).isEqualTo(acceptCharset);
assertThat(headers.contentLength()).isEqualTo(OptionalLong.of(contentLength));
assertThat(headers.contentType()).isEqualTo(Optional.of(contentType));
assertThat(headers.asHttpHeaders()).isEqualTo(httpHeaders);
}
@Test
@@ -223,7 +222,7 @@ public class DefaultServerRequestTests {
MultiValueMap<String, HttpCookie> expected = new LinkedMultiValueMap<>();
expected.add("foo", cookie);
assertEquals(expected, request.cookies());
assertThat(request.cookies()).isEqualTo(expected);
}
@@ -244,7 +243,7 @@ public class DefaultServerRequestTests {
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
Mono<String> resultMono = request.body(toMono(String.class));
assertEquals("foo", resultMono.block());
assertThat(resultMono.block()).isEqualTo("foo");
}
@Test
@@ -263,7 +262,7 @@ public class DefaultServerRequestTests {
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
Mono<String> resultMono = request.bodyToMono(String.class);
assertEquals("foo", resultMono.block());
assertThat(resultMono.block()).isEqualTo("foo");
}
@Test
@@ -283,7 +282,7 @@ public class DefaultServerRequestTests {
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
Mono<String> resultMono = request.bodyToMono(typeReference);
assertEquals("foo", resultMono.block());
assertThat(resultMono.block()).isEqualTo("foo");
}
@Test
@@ -324,7 +323,7 @@ public class DefaultServerRequestTests {
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
Flux<String> resultFlux = request.bodyToFlux(String.class);
assertEquals(Collections.singletonList("foo"), resultFlux.collectList().block());
assertThat(resultFlux.collectList().block()).isEqualTo(Collections.singletonList("foo"));
}
@Test
@@ -344,7 +343,7 @@ public class DefaultServerRequestTests {
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
Flux<String> resultFlux = request.bodyToFlux(typeReference);
assertEquals(Collections.singletonList("foo"), resultFlux.collectList().block());
assertThat(resultFlux.collectList().block()).isEqualTo(Collections.singletonList("foo"));
}
@Test
@@ -386,9 +385,9 @@ public class DefaultServerRequestTests {
Mono<MultiValueMap<String, String>> resultData = request.formData();
StepVerifier.create(resultData)
.consumeNextWith(formData -> {
assertEquals(2, formData.size());
assertEquals("bar", formData.getFirst("foo"));
assertEquals("qux", formData.getFirst("baz"));
assertThat(formData.size()).isEqualTo(2);
assertThat(formData.getFirst("foo")).isEqualTo("bar");
assertThat(formData.getFirst("baz")).isEqualTo("qux");
})
.verifyComplete();
}
@@ -420,17 +419,19 @@ public class DefaultServerRequestTests {
Mono<MultiValueMap<String, Part>> resultData = request.multipartData();
StepVerifier.create(resultData)
.consumeNextWith(formData -> {
assertEquals(2, formData.size());
assertThat(formData.size()).isEqualTo(2);
Part part = formData.getFirst("foo");
assertTrue(part instanceof FormFieldPart);
boolean condition1 = part instanceof FormFieldPart;
assertThat(condition1).isTrue();
FormFieldPart formFieldPart = (FormFieldPart) part;
assertEquals("bar", formFieldPart.value());
assertThat(formFieldPart.value()).isEqualTo("bar");
part = formData.getFirst("baz");
assertTrue(part instanceof FormFieldPart);
boolean condition = part instanceof FormFieldPart;
assertThat(condition).isTrue();
formFieldPart = (FormFieldPart) part;
assertEquals("qux", formFieldPart.value());
assertThat(formFieldPart.value()).isEqualTo("qux");
})
.verifyComplete();
}

View File

@@ -44,9 +44,8 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.result.view.ViewResolver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* @author Arjen Poutsma
@@ -311,14 +310,14 @@ public class DefaultServerResponseBuilderTests {
.cookie(ResponseCookie.from("foo", "bar").build())
.syncBody("body");
assertFalse(serverResponse.block().cookies().isEmpty());
assertThat(serverResponse.block().cookies().isEmpty()).isFalse();
serverResponse = ServerResponse.ok()
.cookie(ResponseCookie.from("foo", "bar").build())
.body(BodyInserters.fromObject("body"));
assertFalse(serverResponse.block().cookies().isEmpty());
assertThat(serverResponse.block().cookies().isEmpty()).isFalse();
}
@@ -336,9 +335,9 @@ public class DefaultServerResponseBuilderTests {
result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.CREATED, response.getStatusCode());
assertEquals("MyValue", response.getHeaders().getFirst("MyKey"));
assertEquals("value", response.getCookies().getFirst("name").getValue());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(response.getHeaders().getFirst("MyKey")).isEqualTo("MyValue");
assertThat(response.getCookies().getFirst("name").getValue()).isEqualTo("value");
StepVerifier.create(response.getBody()).expectComplete().verify();
}
@@ -380,7 +379,7 @@ public class DefaultServerResponseBuilderTests {
responseMono.writeTo(exchange, EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();
@@ -405,7 +404,7 @@ public class DefaultServerResponseBuilderTests {
responseMono.writeTo(exchange, EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();

View File

@@ -42,9 +42,7 @@ import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import org.springframework.web.util.pattern.PathPattern;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;
import static org.springframework.web.reactive.function.server.RouterFunctions.nest;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
@@ -80,8 +78,8 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
ResponseEntity<Person> result =
this.restTemplate.getForEntity("http://localhost:" + this.port + "/mono", Person.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("John", result.getBody().getName());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody().getName()).isEqualTo("John");
}
@Test
@@ -91,11 +89,11 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
this.restTemplate
.exchange("http://localhost:" + this.port + "/flux", HttpMethod.GET, null, reference);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
List<Person> body = result.getBody();
assertEquals(2, body.size());
assertEquals("John", body.get(0).getName());
assertEquals("Jane", body.get(1).getName());
assertThat(body.size()).isEqualTo(2);
assertThat(body.get(0).getName()).isEqualTo("John");
assertThat(body.get(1).getName()).isEqualTo("Jane");
}
@Test
@@ -103,8 +101,8 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
ResponseEntity<Person> result =
this.restTemplate.getForEntity("http://localhost:" + this.port + "/controller", Person.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("John", result.getBody().getName());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody().getName()).isEqualTo("John");
}
@Test
@@ -113,7 +111,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
this.restTemplate
.getForEntity("http://localhost:" + this.port + "/attributes/bar", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@@ -174,31 +172,31 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
@SuppressWarnings("unchecked")
public Mono<ServerResponse> attributes(ServerRequest request) {
assertTrue(request.attributes().containsKey(RouterFunctions.REQUEST_ATTRIBUTE));
assertTrue(request.attributes().containsKey(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE));
assertThat(request.attributes().containsKey(RouterFunctions.REQUEST_ATTRIBUTE)).isTrue();
assertThat(request.attributes().containsKey(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE)).isTrue();
Map<String, String> pathVariables =
(Map<String, String>) request.attributes().get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
assertNotNull(pathVariables);
assertEquals(1, pathVariables.size());
assertEquals("bar", pathVariables.get("foo"));
assertThat(pathVariables).isNotNull();
assertThat(pathVariables.size()).isEqualTo(1);
assertThat(pathVariables.get("foo")).isEqualTo("bar");
pathVariables =
(Map<String, String>) request.attributes().get(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
assertNotNull(pathVariables);
assertEquals(1, pathVariables.size());
assertEquals("bar", pathVariables.get("foo"));
assertThat(pathVariables).isNotNull();
assertThat(pathVariables.size()).isEqualTo(1);
assertThat(pathVariables.get("foo")).isEqualTo("bar");
PathPattern pattern =
(PathPattern) request.attributes().get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
assertNotNull(pattern);
assertEquals("/attributes/{foo}", pattern.getPatternString());
assertThat(pattern).isNotNull();
assertThat(pattern.getPatternString()).isEqualTo("/attributes/{foo}");
pattern = (PathPattern) request.attributes()
.get(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
assertNotNull(pattern);
assertEquals("/attributes/{foo}", pattern.getPatternString());
assertThat(pattern).isNotNull();
assertThat(pattern.getPatternString()).isEqualTo("/attributes/{foo}");
return ServerResponse.ok().build();
}

View File

@@ -18,8 +18,7 @@ package org.springframework.web.reactive.function.server;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -29,17 +28,17 @@ public class HandlerStrategiesTests {
@Test
public void empty() {
HandlerStrategies strategies = HandlerStrategies.empty().build();
assertTrue(strategies.messageReaders().isEmpty());
assertTrue(strategies.messageWriters().isEmpty());
assertTrue(strategies.viewResolvers().isEmpty());
assertThat(strategies.messageReaders().isEmpty()).isTrue();
assertThat(strategies.messageWriters().isEmpty()).isTrue();
assertThat(strategies.viewResolvers().isEmpty()).isTrue();
}
@Test
public void withDefaults() {
HandlerStrategies strategies = HandlerStrategies.withDefaults();
assertFalse(strategies.messageReaders().isEmpty());
assertFalse(strategies.messageWriters().isEmpty());
assertTrue(strategies.viewResolvers().isEmpty());
assertThat(strategies.messageReaders().isEmpty()).isFalse();
assertThat(strategies.messageWriters().isEmpty()).isFalse();
assertThat(strategies.viewResolvers().isEmpty()).isTrue();
}
}

View File

@@ -32,7 +32,7 @@ import org.springframework.http.HttpRange;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.support.ServerRequestWrapper;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -58,7 +58,7 @@ public class HeadersWrapperTests {
List<MediaType> accept = Collections.singletonList(MediaType.APPLICATION_JSON);
given(mockHeaders.accept()).willReturn(accept);
assertSame(accept, wrapper.accept());
assertThat(wrapper.accept()).isSameAs(accept);
}
@Test
@@ -66,7 +66,7 @@ public class HeadersWrapperTests {
List<Charset> acceptCharset = Collections.singletonList(StandardCharsets.UTF_8);
given(mockHeaders.acceptCharset()).willReturn(acceptCharset);
assertSame(acceptCharset, wrapper.acceptCharset());
assertThat(wrapper.acceptCharset()).isSameAs(acceptCharset);
}
@Test
@@ -74,7 +74,7 @@ public class HeadersWrapperTests {
OptionalLong contentLength = OptionalLong.of(42L);
given(mockHeaders.contentLength()).willReturn(contentLength);
assertSame(contentLength, wrapper.contentLength());
assertThat(wrapper.contentLength()).isSameAs(contentLength);
}
@Test
@@ -82,7 +82,7 @@ public class HeadersWrapperTests {
Optional<MediaType> contentType = Optional.of(MediaType.APPLICATION_JSON);
given(mockHeaders.contentType()).willReturn(contentType);
assertSame(contentType, wrapper.contentType());
assertThat(wrapper.contentType()).isSameAs(contentType);
}
@Test
@@ -90,7 +90,7 @@ public class HeadersWrapperTests {
InetSocketAddress host = InetSocketAddress.createUnresolved("example.com", 42);
given(mockHeaders.host()).willReturn(host);
assertSame(host, wrapper.host());
assertThat(wrapper.host()).isSameAs(host);
}
@Test
@@ -98,7 +98,7 @@ public class HeadersWrapperTests {
List<HttpRange> range = Collections.singletonList(HttpRange.createByteRange(42));
given(mockHeaders.range()).willReturn(range);
assertSame(range, wrapper.range());
assertThat(wrapper.range()).isSameAs(range);
}
@Test
@@ -107,7 +107,7 @@ public class HeadersWrapperTests {
List<String> value = Collections.singletonList("bar");
given(mockHeaders.header(name)).willReturn(value);
assertSame(value, wrapper.header(name));
assertThat(wrapper.header(name)).isSameAs(value);
}
@Test
@@ -115,7 +115,7 @@ public class HeadersWrapperTests {
HttpHeaders httpHeaders = new HttpHeaders();
given(mockHeaders.asHttpHeaders()).willReturn(httpHeaders);
assertSame(httpHeaders, wrapper.asHttpHeaders());
assertThat(wrapper.asHttpHeaders()).isSameAs(httpHeaders);
}
}

View File

@@ -23,7 +23,7 @@ import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -47,7 +47,7 @@ public class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionInt
.build();
try (Response response = client.newCall(request).execute()) {
assertEquals("BAR", response.body().string());
assertThat(response.body().string()).isEqualTo("BAR");
}
}

View File

@@ -35,7 +35,7 @@ import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.i18n.FixedLocaleContextResolver;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Sebastien Deleuze
@@ -73,8 +73,8 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
StepVerifier
.create(result)
.consumeNextWith(response -> {
assertEquals(HttpStatus.OK, response.statusCode());
assertEquals(Locale.GERMANY, response.headers().asHttpHeaders().getContentLanguage());
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.headers().asHttpHeaders().getContentLanguage()).isEqualTo(Locale.GERMANY);
})
.verifyComplete();
}

View File

@@ -29,8 +29,7 @@ import org.springframework.lang.Nullable;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.pattern.PathPattern;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.all;
import static org.springframework.web.reactive.function.server.RequestPredicates.method;
@@ -66,8 +65,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/foo/bar", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("/foo/bar", result.getBody());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).isEqualTo("/foo/bar");
}
@Test
@@ -75,8 +74,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/foo/baz", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("/foo/baz", result.getBody());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).isEqualTo("/foo/baz");
}
@Test
@@ -84,8 +83,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/1/2/3", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("/{foo}/{bar}/{baz}\n{foo=1, bar=2, baz=3}", result.getBody());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).isEqualTo("/{foo}/{bar}/{baz}\n{foo=1, bar=2, baz=3}");
}
// SPR-16868
@@ -94,8 +93,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/1/bar", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("/{foo}/bar\n{foo=1}", result.getBody());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).isEqualTo("/{foo}/bar\n{foo=1}");
}
@@ -105,8 +104,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/qux/quux", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("/{qux}/quux\n{qux=qux}", result.getBody());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).isEqualTo("/{qux}/quux\n{qux=qux}");
}
@@ -116,8 +115,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
ResponseEntity<String> result =
restTemplate.postForEntity("http://localhost:" + port + "/qux/quux", "", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("{}", result.getBody());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).isEqualTo("{}");
}
@@ -134,8 +133,8 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
Map<String, String> pathVariables = request.pathVariables();
Map<String, String> attributePathVariables =
(Map<String, String>) request.attributes().get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
assertTrue( (pathVariables.equals(attributePathVariables))
|| (pathVariables.isEmpty() && (attributePathVariables == null)));
assertThat((pathVariables.equals(attributePathVariables))
|| (pathVariables.isEmpty() && (attributePathVariables == null))).isTrue();
PathPattern pathPattern = matchingPattern(request);
String pattern = pathPattern != null ? pathPattern.getPatternString() : "";

View File

@@ -30,7 +30,7 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
@@ -59,8 +59,8 @@ public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunc
ResponseEntity<Person> result =
restTemplate.getForEntity("http://localhost:" + port + "/mono", Person.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("John", result.getBody().getName());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody().getName()).isEqualTo("John");
}
@Test
@@ -69,11 +69,11 @@ public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunc
ResponseEntity<List<Person>> result =
restTemplate.exchange("http://localhost:" + port + "/flux", HttpMethod.GET, null, reference);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
List<Person> body = result.getBody();
assertEquals(2, body.size());
assertEquals("John", body.get(0).getName());
assertEquals("Jane", body.get(1).getName());
assertThat(body.size()).isEqualTo(2);
assertThat(body.get(0).getName()).isEqualTo("John");
assertThat(body.get(1).getName()).isEqualTo("Jane");
}
@Test
@@ -83,8 +83,8 @@ public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunc
RequestEntity<Person> requestEntity = RequestEntity.post(uri).body(person);
ResponseEntity<Person> result = restTemplate.exchange(requestEntity, Person.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Jack", result.getBody().getName());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody().getName()).isEqualTo("Jack");
}

View File

@@ -37,7 +37,7 @@ import org.springframework.web.reactive.result.view.View;
import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.server.HandlerFilterFunction.ofResponseProcessor;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
@@ -77,11 +77,11 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/normal", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
Map<String, String> body = parseBody(result.getBody());
assertEquals(2, body.size());
assertEquals("foo", body.get("name"));
assertEquals("baz", body.get("bar"));
assertThat(body.size()).isEqualTo(2);
assertThat(body.get("name")).isEqualTo("foo");
assertThat(body.get("bar")).isEqualTo("baz");
}
@Test
@@ -89,12 +89,12 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/filter", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
Map<String, String> body = parseBody(result.getBody());
assertEquals(3, body.size());
assertEquals("foo", body.get("name"));
assertEquals("baz", body.get("bar"));
assertEquals("quux", body.get("qux"));
assertThat(body.size()).isEqualTo(3);
assertThat(body.get("name")).isEqualTo("foo");
assertThat(body.get("bar")).isEqualTo("baz");
assertThat(body.get("qux")).isEqualTo("quux");
}
private Map<String, String> parseBody(String body) {

View File

@@ -26,9 +26,7 @@ import org.springframework.http.codec.DecoderHttpMessageReader;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -54,10 +52,10 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new AddAttributePredicate(false, "predicate", "baz").negate();
boolean result = predicate.test(this.request);
assertTrue(result);
assertThat(result).isTrue();
assertEquals("bar", this.request.attributes().get("exchange"));
assertEquals("baz", this.request.attributes().get("predicate"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().get("predicate")).isEqualTo("baz");
}
@Test
@@ -65,10 +63,10 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new AddAttributePredicate(true, "predicate", "baz").negate();
boolean result = predicate.test(this.request);
assertFalse(result);
assertThat(result).isFalse();
assertEquals("bar", this.request.attributes().get("exchange"));
assertFalse(this.request.attributes().containsKey("baz"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().containsKey("baz")).isFalse();
}
@Test
@@ -78,11 +76,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertTrue(result);
assertThat(result).isTrue();
assertEquals("bar", this.request.attributes().get("exchange"));
assertEquals("baz", this.request.attributes().get("left"));
assertEquals("qux", this.request.attributes().get("right"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().get("left")).isEqualTo("baz");
assertThat(this.request.attributes().get("right")).isEqualTo("qux");
}
@Test
@@ -92,11 +90,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertFalse(result);
assertThat(result).isFalse();
assertEquals("bar", this.request.attributes().get("exchange"));
assertFalse(this.request.attributes().containsKey("left"));
assertFalse(this.request.attributes().containsKey("right"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().containsKey("left")).isFalse();
assertThat(this.request.attributes().containsKey("right")).isFalse();
}
@Test
@@ -106,11 +104,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertFalse(result);
assertThat(result).isFalse();
assertEquals("bar", this.request.attributes().get("exchange"));
assertFalse(this.request.attributes().containsKey("left"));
assertFalse(this.request.attributes().containsKey("right"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().containsKey("left")).isFalse();
assertThat(this.request.attributes().containsKey("right")).isFalse();
}
@Test
@@ -120,11 +118,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.AndRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertFalse(result);
assertThat(result).isFalse();
assertEquals("bar", this.request.attributes().get("exchange"));
assertFalse(this.request.attributes().containsKey("left"));
assertFalse(this.request.attributes().containsKey("right"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().containsKey("left")).isFalse();
assertThat(this.request.attributes().containsKey("right")).isFalse();
}
@Test
@@ -134,11 +132,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertTrue(result);
assertThat(result).isTrue();
assertEquals("bar", this.request.attributes().get("exchange"));
assertEquals("baz", this.request.attributes().get("left"));
assertFalse(this.request.attributes().containsKey("right"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().get("left")).isEqualTo("baz");
assertThat(this.request.attributes().containsKey("right")).isFalse();
}
@Test
@@ -148,11 +146,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertTrue(result);
assertThat(result).isTrue();
assertEquals("bar", this.request.attributes().get("exchange"));
assertEquals("baz", this.request.attributes().get("left"));
assertFalse(this.request.attributes().containsKey("right"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().get("left")).isEqualTo("baz");
assertThat(this.request.attributes().containsKey("right")).isFalse();
}
@Test
@@ -162,11 +160,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertTrue(result);
assertThat(result).isTrue();
assertEquals("bar", this.request.attributes().get("exchange"));
assertFalse(this.request.attributes().containsKey("left"));
assertEquals("qux", this.request.attributes().get("right"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().containsKey("left")).isFalse();
assertThat(this.request.attributes().get("right")).isEqualTo("qux");
}
@Test
@@ -176,11 +174,11 @@ public class RequestPredicateAttributesTests {
RequestPredicate predicate = new RequestPredicates.OrRequestPredicate(left, right);
boolean result = predicate.test(this.request);
assertFalse(result);
assertThat(result).isFalse();
assertEquals("bar", this.request.attributes().get("exchange"));
assertFalse(this.request.attributes().containsKey("baz"));
assertFalse(this.request.attributes().containsKey("quux"));
assertThat(this.request.attributes().get("exchange")).isEqualTo("bar");
assertThat(this.request.attributes().containsKey("baz")).isFalse();
assertThat(this.request.attributes().containsKey("quux")).isFalse();
}

View File

@@ -18,8 +18,7 @@ package org.springframework.web.reactive.function.server;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -33,9 +32,9 @@ public class RequestPredicateTests {
RequestPredicate predicate3 = request -> false;
MockServerRequest request = MockServerRequest.builder().build();
assertTrue(predicate1.and(predicate2).test(request));
assertTrue(predicate2.and(predicate1).test(request));
assertFalse(predicate1.and(predicate3).test(request));
assertThat(predicate1.and(predicate2).test(request)).isTrue();
assertThat(predicate2.and(predicate1).test(request)).isTrue();
assertThat(predicate1.and(predicate3).test(request)).isFalse();
}
@Test
@@ -44,12 +43,12 @@ public class RequestPredicateTests {
RequestPredicate negated = predicate.negate();
MockServerRequest mockRequest = MockServerRequest.builder().build();
assertTrue(negated.test(mockRequest));
assertThat(negated.test(mockRequest)).isTrue();
predicate = request -> true;
negated = predicate.negate();
assertFalse(negated.test(mockRequest));
assertThat(negated.test(mockRequest)).isFalse();
}
@Test
@@ -59,9 +58,9 @@ public class RequestPredicateTests {
RequestPredicate predicate3 = request -> false;
MockServerRequest request = MockServerRequest.builder().build();
assertTrue(predicate1.or(predicate2).test(request));
assertTrue(predicate2.or(predicate1).test(request));
assertFalse(predicate2.or(predicate3).test(request));
assertThat(predicate1.or(predicate2).test(request)).isTrue();
assertThat(predicate2.or(predicate1).test(request)).isTrue();
assertThat(predicate2.or(predicate3).test(request)).isFalse();
}
}

View File

@@ -26,8 +26,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.util.pattern.PathPatternParser;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -38,7 +37,7 @@ public class RequestPredicatesTests {
public void all() {
RequestPredicate predicate = RequestPredicates.all();
MockServerRequest request = MockServerRequest.builder().build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
}
@Test
@@ -46,23 +45,23 @@ public class RequestPredicatesTests {
HttpMethod httpMethod = HttpMethod.GET;
RequestPredicate predicate = RequestPredicates.method(httpMethod);
MockServerRequest request = MockServerRequest.builder().method(httpMethod).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().method(HttpMethod.POST).build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
public void methods() {
RequestPredicate predicate = RequestPredicates.methods(HttpMethod.GET, HttpMethod.HEAD);
MockServerRequest request = MockServerRequest.builder().method(HttpMethod.GET).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().method(HttpMethod.HEAD).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().method(HttpMethod.POST).build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
@@ -71,31 +70,31 @@ public class RequestPredicatesTests {
RequestPredicate predicate = RequestPredicates.GET("/p*");
MockServerRequest request = MockServerRequest.builder().method(HttpMethod.GET).uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.HEAD("/p*");
request = MockServerRequest.builder().method(HttpMethod.HEAD).uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.POST("/p*");
request = MockServerRequest.builder().method(HttpMethod.POST).uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.PUT("/p*");
request = MockServerRequest.builder().method(HttpMethod.PUT).uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.PATCH("/p*");
request = MockServerRequest.builder().method(HttpMethod.PATCH).uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.DELETE("/p*");
request = MockServerRequest.builder().method(HttpMethod.DELETE).uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.OPTIONS("/p*");
request = MockServerRequest.builder().method(HttpMethod.OPTIONS).uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
}
@Test
@@ -103,10 +102,10 @@ public class RequestPredicatesTests {
URI uri = URI.create("http://localhost/path");
RequestPredicate predicate = RequestPredicates.path("/p*");
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
@@ -114,7 +113,7 @@ public class RequestPredicatesTests {
URI uri = URI.create("http://localhost/path");
RequestPredicate predicate = RequestPredicates.path("p*");
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
}
@Test
@@ -122,10 +121,10 @@ public class RequestPredicatesTests {
URI uri = URI.create("http://localhost/foo%20bar");
RequestPredicate predicate = RequestPredicates.path("/foo bar");
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
@@ -137,7 +136,7 @@ public class RequestPredicatesTests {
URI uri = URI.create("http://localhost/path");
RequestPredicate predicate = pathPredicates.apply("/P*");
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
}
@Test
@@ -148,10 +147,10 @@ public class RequestPredicatesTests {
RequestPredicates.headers(
headers -> headers.header(name).equals(Collections.singletonList(value)));
MockServerRequest request = MockServerRequest.builder().header(name, value).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
@@ -159,10 +158,10 @@ public class RequestPredicatesTests {
MediaType json = MediaType.APPLICATION_JSON;
RequestPredicate predicate = RequestPredicates.contentType(json);
MockServerRequest request = MockServerRequest.builder().header("Content-Type", json.toString()).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
@@ -170,10 +169,10 @@ public class RequestPredicatesTests {
MediaType json = MediaType.APPLICATION_JSON;
RequestPredicate predicate = RequestPredicates.accept(json);
MockServerRequest request = MockServerRequest.builder().header("Accept", json.toString()).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
request = MockServerRequest.builder().header("Accept", MediaType.TEXT_XML_VALUE).build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
@@ -182,28 +181,28 @@ public class RequestPredicatesTests {
URI uri = URI.create("http://localhost/file.txt");
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
uri = URI.create("http://localhost/FILE.TXT");
request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.pathExtension("bar");
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
uri = URI.create("http://localhost/file.foo");
request = MockServerRequest.builder().uri(uri).build();
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
@Test
public void queryParam() {
MockServerRequest request = MockServerRequest.builder().queryParam("foo", "bar").build();
RequestPredicate predicate = RequestPredicates.queryParam("foo", s -> s.equals("bar"));
assertTrue(predicate.test(request));
assertThat(predicate.test(request)).isTrue();
predicate = RequestPredicates.queryParam("foo", s -> s.equals("baz"));
assertFalse(predicate.test(request));
assertThat(predicate.test(request)).isFalse();
}
}

View File

@@ -37,9 +37,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.result.view.ViewResolver;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@@ -80,12 +78,13 @@ public class ResourceHandlerFunctionTests {
Mono<ServerResponse> responseMono = this.handlerFunction.handle(request);
Mono<Void> result = responseMono.flatMap(response -> {
assertEquals(HttpStatus.OK, response.statusCode());
assertTrue(response instanceof EntityResponse);
@SuppressWarnings("unchecked")
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
boolean condition = response instanceof EntityResponse;
assertThat(condition).isTrue();
@SuppressWarnings("unchecked")
EntityResponse<Resource> entityResponse = (EntityResponse<Resource>) response;
assertEquals(this.resource, entityResponse.entity());
return response.writeTo(exchange, context);
assertThat(entityResponse.entity()).isEqualTo(this.resource);
return response.writeTo(exchange, context);
});
StepVerifier.create(result)
@@ -98,12 +97,12 @@ public class ResourceHandlerFunctionTests {
.consumeNextWith(dataBuffer -> {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
assertArrayEquals(expectedBytes, resultBytes);
assertThat(resultBytes).isEqualTo(expectedBytes);
})
.expectComplete()
.verify();
assertEquals(MediaType.TEXT_PLAIN, mockResponse.getHeaders().getContentType());
assertEquals(this.resource.contentLength(), mockResponse.getHeaders().getContentLength());
assertThat(mockResponse.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(mockResponse.getHeaders().getContentLength()).isEqualTo(this.resource.contentLength());
}
@Test
@@ -116,19 +115,20 @@ public class ResourceHandlerFunctionTests {
Mono<ServerResponse> responseMono = this.handlerFunction.handle(request);
Mono<Void> result = responseMono.flatMap(response -> {
assertEquals(HttpStatus.OK, response.statusCode());
assertTrue(response instanceof EntityResponse);
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
boolean condition = response instanceof EntityResponse;
assertThat(condition).isTrue();
@SuppressWarnings("unchecked")
EntityResponse<Resource> entityResponse = (EntityResponse<Resource>) response;
assertEquals(this.resource.getFilename(), entityResponse.entity().getFilename());
assertThat(entityResponse.entity().getFilename()).isEqualTo(this.resource.getFilename());
return response.writeTo(exchange, context);
});
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(mockResponse.getBody()).expectComplete().verify();
assertEquals(MediaType.TEXT_PLAIN, mockResponse.getHeaders().getContentType());
assertEquals(this.resource.contentLength(), mockResponse.getHeaders().getContentLength());
assertThat(mockResponse.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(mockResponse.getHeaders().getContentLength()).isEqualTo(this.resource.contentLength());
}
@Test
@@ -140,9 +140,8 @@ public class ResourceHandlerFunctionTests {
Mono<ServerResponse> responseMono = this.handlerFunction.handle(request);
Mono<Void> result = responseMono.flatMap(response -> {
assertEquals(HttpStatus.OK, response.statusCode());
assertEquals(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS),
response.headers().getAllow());
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.headers().getAllow()).isEqualTo(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS));
return response.writeTo(exchange, context);
});
@@ -150,9 +149,8 @@ public class ResourceHandlerFunctionTests {
StepVerifier.create(result)
.expectComplete()
.verify();
assertEquals(HttpStatus.OK, mockResponse.getStatusCode());
assertEquals(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS),
mockResponse.getHeaders().getAllow());
assertThat(mockResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(mockResponse.getHeaders().getAllow()).isEqualTo(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS));
StepVerifier.create(mockResponse.getBody()).expectComplete().verify();
}

View File

@@ -29,8 +29,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.server.RequestPredicates.HEAD;
/**
@@ -107,7 +106,7 @@ public class RouterFunctionBuilderTests {
@Test
public void resources() {
Resource resource = new ClassPathResource("/org/springframework/web/reactive/function/server/");
assertTrue(resource.exists());
assertThat(resource.exists()).isTrue();
RouterFunction<ServerResponse> route = RouterFunctions.route()
.resources("/resources/**", resource)
@@ -175,20 +174,20 @@ public class RouterFunctionBuilderTests {
.GET("/bar", request -> Mono.error(new IllegalStateException()))
.before(request -> {
int count = filterCount.getAndIncrement();
assertEquals(0, count);
assertThat(count).isEqualTo(0);
return request;
})
.after((request, response) -> {
int count = filterCount.getAndIncrement();
assertEquals(3, count);
assertThat(count).isEqualTo(3);
return response;
})
.filter((request, next) -> {
int count = filterCount.getAndIncrement();
assertEquals(1, count);
assertThat(count).isEqualTo(1);
Mono<ServerResponse> responseMono = next.handle(request);
count = filterCount.getAndIncrement();
assertEquals(2, count);
assertThat(count).isEqualTo(2);
return responseMono;
})
.onError(IllegalStateException.class, (e, request) -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build())
@@ -204,8 +203,7 @@ public class RouterFunctionBuilderTests {
StepVerifier.create(fooResponseMono)
.consumeNextWith(serverResponse ->
assertEquals(4, filterCount.get())
.consumeNextWith(serverResponse -> assertThat(filterCount.get()).isEqualTo(4)
)
.verifyComplete();

View File

@@ -20,13 +20,12 @@ import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
/**
* @author Arjen Poutsma
*/
@SuppressWarnings("unchecked")
public class RouterFunctionTests {
@Test
@@ -36,7 +35,7 @@ public class RouterFunctionTests {
RouterFunction<ServerResponse> routerFunction2 = request -> Mono.just(handlerFunction);
RouterFunction<ServerResponse> result = routerFunction1.and(routerFunction2);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerRequest request = MockServerRequest.builder().build();
Mono<HandlerFunction<ServerResponse>> resultHandlerFunction = result.route(request);
@@ -56,7 +55,7 @@ public class RouterFunctionTests {
request -> Mono.just(handlerFunction);
RouterFunction<?> result = routerFunction1.andOther(routerFunction2);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerRequest request = MockServerRequest.builder().build();
Mono<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request);
@@ -73,7 +72,7 @@ public class RouterFunctionTests {
RequestPredicate requestPredicate = request -> true;
RouterFunction<ServerResponse> result = routerFunction1.andRoute(requestPredicate, this::handlerMethod);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerRequest request = MockServerRequest.builder().build();
Mono<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request);
@@ -101,7 +100,7 @@ public class RouterFunctionTests {
});
RouterFunction<EntityResponse<Mono<Integer>>> result = routerFunction.filter(filterFunction);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerRequest request = MockServerRequest.builder().build();
Mono<EntityResponse<Mono<Integer>>> responseMono =

View File

@@ -36,9 +36,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -46,7 +44,6 @@ import static org.mockito.Mockito.mock;
* @author Arjen Poutsma
* @since 5.0
*/
@SuppressWarnings("unchecked")
public class RouterFunctionsTests {
@Test
@@ -59,7 +56,7 @@ public class RouterFunctionsTests {
RouterFunction<ServerResponse>
result = RouterFunctions.route(requestPredicate, handlerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
Mono<HandlerFunction<ServerResponse>> resultHandlerFunction = result.route(request);
@@ -78,7 +75,7 @@ public class RouterFunctionsTests {
given(requestPredicate.test(request)).willReturn(false);
RouterFunction<ServerResponse> result = RouterFunctions.route(requestPredicate, handlerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
Mono<HandlerFunction<ServerResponse>> resultHandlerFunction = result.route(request);
StepVerifier.create(resultHandlerFunction)
@@ -96,7 +93,7 @@ public class RouterFunctionsTests {
given(requestPredicate.nest(request)).willReturn(Optional.of(request));
RouterFunction<ServerResponse> result = RouterFunctions.nest(requestPredicate, routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
Mono<HandlerFunction<ServerResponse>> resultHandlerFunction = result.route(request);
StepVerifier.create(resultHandlerFunction)
@@ -115,7 +112,7 @@ public class RouterFunctionsTests {
given(requestPredicate.nest(request)).willReturn(Optional.empty());
RouterFunction<ServerResponse> result = RouterFunctions.nest(requestPredicate, routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
Mono<HandlerFunction<ServerResponse>> resultHandlerFunction = result.route(request);
StepVerifier.create(resultHandlerFunction)
@@ -130,12 +127,12 @@ public class RouterFunctionsTests {
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.ACCEPTED, httpResponse.getStatusCode());
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
}
@Test
@@ -148,12 +145,12 @@ public class RouterFunctionsTests {
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpResponse.getStatusCode());
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
@Test
@@ -164,12 +161,12 @@ public class RouterFunctionsTests {
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpResponse.getStatusCode());
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
@Test
@@ -180,12 +177,12 @@ public class RouterFunctionsTests {
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.NOT_FOUND, httpResponse.getStatusCode());
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
@@ -214,12 +211,12 @@ public class RouterFunctionsTests {
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.NOT_FOUND, httpResponse.getStatusCode());
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
@@ -248,12 +245,12 @@ public class RouterFunctionsTests {
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.NOT_FOUND, httpResponse.getStatusCode());
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
@@ -276,14 +273,14 @@ public class RouterFunctionsTests {
.webFilter(webFilter).build();
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction, handlerStrategies);
assertNotNull(result);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.ACCEPTED, httpResponse.getStatusCode());
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
assertTrue(filterInvoked.get());
assertThat(filterInvoked.get()).isTrue();
}
}

View File

@@ -29,8 +29,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.reactive.function.client.WebClient;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
import static org.springframework.web.reactive.function.BodyInserters.fromServerSentEvents;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
@@ -98,18 +97,18 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
StepVerifier.create(result)
.consumeNextWith( event -> {
assertEquals("0", event.id());
assertEquals("foo", event.data());
assertEquals("bar", event.comment());
assertNull(event.event());
assertNull(event.retry());
assertThat(event.id()).isEqualTo("0");
assertThat(event.data()).isEqualTo("foo");
assertThat(event.comment()).isEqualTo("bar");
assertThat(event.event()).isNull();
assertThat(event.retry()).isNull();
})
.consumeNextWith( event -> {
assertEquals("1", event.id());
assertEquals("foo", event.data());
assertEquals("bar", event.comment());
assertNull(event.event());
assertNull(event.retry());
assertThat(event.id()).isEqualTo("1");
assertThat(event.data()).isEqualTo("foo");
assertThat(event.comment()).isEqualTo("bar");
assertThat(event.event()).isNull();
assertThat(event.retry()).isNull();
})
.expectComplete()
.verify(Duration.ofSeconds(5L));

View File

@@ -22,7 +22,7 @@ import reactor.core.publisher.Mono;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RequestPredicates.contentType;
@@ -58,7 +58,7 @@ public class ToStringVisitorTests {
" (GET && /baz) -> \n" +
" }\n" +
"}";
assertEquals(expected, result);
assertThat(result).isEqualTo(expected);
}
@Test
@@ -94,7 +94,7 @@ public class ToStringVisitorTests {
predicate.accept(visitor);
String result = visitor.toString();
assertEquals(expected, result);
assertThat(result).isEqualTo(expected);
}

View File

@@ -34,7 +34,7 @@ import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
@@ -61,7 +61,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
ResponseEntity<String> result = this.restTemplate
.getForEntity("http://localhost:" + this.port + "/foo/bar", String.class);
assertEquals(200, result.getStatusCodeValue());
assertThat(result.getStatusCodeValue()).isEqualTo(200);
}

View File

@@ -35,8 +35,7 @@ import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -52,7 +51,7 @@ public class ServerRequestWrapperTests {
@Test
public void request() {
assertSame(mockRequest, wrapper.request());
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
@@ -60,7 +59,7 @@ public class ServerRequestWrapperTests {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertSame(method, wrapper.method());
assertThat(wrapper.method()).isSameAs(method);
}
@Test
@@ -68,7 +67,7 @@ public class ServerRequestWrapperTests {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertSame(uri, wrapper.uri());
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
@@ -76,7 +75,7 @@ public class ServerRequestWrapperTests {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertSame(path, wrapper.path());
assertThat(wrapper.path()).isSameAs(path);
}
@Test
@@ -84,7 +83,7 @@ public class ServerRequestWrapperTests {
ServerRequest.Headers headers = mock(ServerRequest.Headers.class);
given(mockRequest.headers()).willReturn(headers);
assertSame(headers, wrapper.headers());
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
@@ -93,7 +92,7 @@ public class ServerRequestWrapperTests {
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertEquals(Optional.of(value), wrapper.attribute(name));
assertThat(wrapper.attribute(name)).isEqualTo(Optional.of(value));
}
@Test
@@ -102,7 +101,7 @@ public class ServerRequestWrapperTests {
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertEquals(Optional.of(value), wrapper.queryParam(name));
assertThat(wrapper.queryParam(name)).isEqualTo(Optional.of(value));
}
@Test
@@ -111,7 +110,7 @@ public class ServerRequestWrapperTests {
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertSame(value, wrapper.queryParams());
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
@@ -120,7 +119,7 @@ public class ServerRequestWrapperTests {
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertEquals(value, wrapper.pathVariable(name));
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
@@ -128,7 +127,7 @@ public class ServerRequestWrapperTests {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertSame(pathVariables, wrapper.pathVariables());
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
@@ -137,7 +136,7 @@ public class ServerRequestWrapperTests {
MultiValueMap<String, HttpCookie> cookies = mock(MultiValueMap.class);
given(mockRequest.cookies()).willReturn(cookies);
assertSame(cookies, wrapper.cookies());
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
@@ -146,7 +145,7 @@ public class ServerRequestWrapperTests {
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertSame(result, wrapper.body(extractor));
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
@@ -154,7 +153,7 @@ public class ServerRequestWrapperTests {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertSame(result, wrapper.bodyToMono(String.class));
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
@@ -163,7 +162,7 @@ public class ServerRequestWrapperTests {
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertSame(result, wrapper.bodyToMono(reference));
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
@@ -171,7 +170,7 @@ public class ServerRequestWrapperTests {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertSame(result, wrapper.bodyToFlux(String.class));
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
@@ -180,7 +179,7 @@ public class ServerRequestWrapperTests {
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertSame(result, wrapper.bodyToFlux(reference));
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}

View File

@@ -28,10 +28,7 @@ import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsConfigurationSource;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for CORS support at {@link AbstractUrlHandlerMapping} level.
@@ -62,8 +59,8 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertSame(this.welcomeController, actual);
assertThat(actual).isNotNull();
assertThat(actual).isSameAs(this.welcomeController);
}
@Test
@@ -72,8 +69,8 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertSame(this.welcomeController, actual);
assertThat(actual).isNotNull();
assertThat(actual).isSameAs(this.welcomeController);
}
@Test
@@ -82,9 +79,9 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/cors.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertSame(this.corsController, actual);
assertEquals("*", exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
assertThat(actual).isNotNull();
assertThat(actual).isSameAs(this.corsController);
assertThat(exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("*");
}
@Test
@@ -93,9 +90,9 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/cors.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertNotSame(this.corsController, actual);
assertEquals("*", exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
assertThat(actual).isNotNull();
assertThat(actual).isNotSameAs(this.corsController);
assertThat(exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("*");
}
@Test
@@ -108,9 +105,9 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertSame(this.welcomeController, actual);
assertEquals("*", exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
assertThat(actual).isNotNull();
assertThat(actual).isSameAs(this.welcomeController);
assertThat(exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("*");
}
@Test
@@ -123,9 +120,9 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertNotSame(this.welcomeController, actual);
assertEquals("*", exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
assertThat(actual).isNotNull();
assertThat(actual).isNotSameAs(this.welcomeController);
assertThat(exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("*");
}
@Test
@@ -136,12 +133,12 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.GET, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertSame(this.welcomeController, actual);
assertEquals("https://domain2.com", exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
assertEquals("true", exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
assertThat(actual).isNotNull();
assertThat(actual).isSameAs(this.welcomeController);
assertThat(exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("https://domain2.com");
assertThat(exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
}
@Test
@@ -152,12 +149,12 @@ public class CorsUrlHandlerMappingTests {
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertNotSame(this.welcomeController, actual);
assertEquals("https://domain2.com", exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
assertEquals("true", exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
assertThat(actual).isNotNull();
assertThat(actual).isNotSameAs(this.welcomeController);
assertThat(exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("https://domain2.com");
assertThat(exchange.getResponse().getHeaders()
.getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
}

View File

@@ -31,10 +31,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE;
/**
@@ -106,15 +103,15 @@ public class SimpleUrlHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(request);
Object actual = handlerMapping.getHandler(exchange).block();
if (bean != null) {
assertNotNull(actual);
assertSame(bean, actual);
assertThat(actual).isNotNull();
assertThat(actual).isSameAs(bean);
//noinspection OptionalGetWithoutIsPresent
PathContainer path = exchange.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
assertNotNull(path);
assertEquals(pathWithinMapping, path.value());
assertThat(path).isNotNull();
assertThat(path.value()).isEqualTo(pathWithinMapping);
}
else {
assertNull(actual);
assertThat(actual).isNull();
}
}

View File

@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
import org.springframework.web.server.handler.ResponseStatusExceptionHandlerTests;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link WebFluxResponseStatusExceptionHandler}.
@@ -45,14 +45,14 @@ public class WebFluxResponseStatusExceptionHandlerTests extends ResponseStatusEx
public void handleAnnotatedException() {
Throwable ex = new CustomException();
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.I_AM_A_TEAPOT, this.exchange.getResponse().getStatusCode());
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
}
@Test
public void handleNestedAnnotatedException() {
Throwable ex = new Exception(new CustomException());
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.I_AM_A_TEAPOT, this.exchange.getResponse().getStatusCode());
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
}

View File

@@ -30,9 +30,6 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -81,7 +78,7 @@ public class AppCacheManifestTransformerTests {
Resource expected = getResource("foo.css");
Resource actual = this.transformer.transform(exchange, expected, this.chain).block(TIMEOUT);
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
@Test
@@ -90,7 +87,7 @@ public class AppCacheManifestTransformerTests {
Resource expected = getResource("error.appcache");
Resource actual = this.transformer.transform(exchange, expected, this.chain).block(TIMEOUT);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}
@Test
@@ -99,7 +96,7 @@ public class AppCacheManifestTransformerTests {
Resource resource = getResource("test.appcache");
Resource actual = this.transformer.transform(exchange, resource, this.chain).block(TIMEOUT);
assertNotNull(actual);
assertThat(actual).isNotNull();
byte[] bytes = FileCopyUtils.copyToByteArray(actual.getInputStream());
String content = new String(bytes, "UTF-8");

View File

@@ -31,10 +31,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -75,8 +72,8 @@ public class CachingResourceResolverTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
Resource actual = this.chain.resolveResource(exchange, "bar.css", this.locations).block(TIMEOUT);
assertNotSame(expected, actual);
assertEquals(expected, actual);
assertThat(actual).isNotSameAs(expected);
assertThat(actual).isEqualTo(expected);
}
@Test
@@ -87,13 +84,13 @@ public class CachingResourceResolverTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
Resource actual = this.chain.resolveResource(exchange, "bar.css", this.locations).block(TIMEOUT);
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
@Test
public void resolveResourceInternalNoMatch() {
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
assertNull(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT));
assertThat(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT)).isNull();
}
@Test
@@ -101,7 +98,7 @@ public class CachingResourceResolverTests {
String expected = "/foo.css";
String actual = this.chain.resolveUrlPath(expected, this.locations).block(TIMEOUT);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}
@Test
@@ -110,12 +107,12 @@ public class CachingResourceResolverTests {
this.cache.put(CachingResourceResolver.RESOLVED_URL_PATH_CACHE_KEY_PREFIX + "imaginary.css", expected);
String actual = this.chain.resolveUrlPath("imaginary.css", this.locations).block(TIMEOUT);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}
@Test
public void resolverUrlPathNoMatch() {
assertNull(this.chain.resolveUrlPath("invalid.css", this.locations).block(TIMEOUT));
assertThat(this.chain.resolveUrlPath("invalid.css", this.locations).block(TIMEOUT)).isNull();
}
@Test
@@ -130,7 +127,7 @@ public class CachingResourceResolverTests {
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
String cacheKey = resourceKey(file);
assertSame(expected, this.cache.get(cacheKey).get());
assertThat(this.cache.get(cacheKey).get()).isSameAs(expected);
// 2. Resolve with Accept-Encoding
@@ -140,7 +137,7 @@ public class CachingResourceResolverTests {
expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
cacheKey = resourceKey(file + "+encoding=br,gzip");
assertSame(expected, this.cache.get(cacheKey).get());
assertThat(this.cache.get(cacheKey).get()).isSameAs(expected);
// 3. Resolve with Accept-Encoding but no matching codings
@@ -148,7 +145,7 @@ public class CachingResourceResolverTests {
expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
cacheKey = resourceKey(file);
assertSame(expected, this.cache.get(cacheKey).get());
assertThat(this.cache.get(cacheKey).get()).isSameAs(expected);
}
@Test
@@ -160,7 +157,7 @@ public class CachingResourceResolverTests {
String cacheKey = resourceKey(file);
Object actual = this.cache.get(cacheKey).get();
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}
@Test
@@ -172,10 +169,10 @@ public class CachingResourceResolverTests {
String file = "bar.css";
MockServerWebExchange exchange = MockServerWebExchange.from(get(file));
assertSame(resource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
assertThat(this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT)).isSameAs(resource);
exchange = MockServerWebExchange.from(get(file).header("Accept-Encoding", "gzip"));
assertSame(gzipped, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
assertThat(this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT)).isSameAs(gzipped);
}
private static String resourceKey(String key) {

View File

@@ -26,8 +26,7 @@ import org.springframework.core.io.Resource;
import org.springframework.util.DigestUtils;
import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link ContentVersionStrategy}.
@@ -50,8 +49,8 @@ public class ContentBasedVersionStrategyTests {
String hash = "7fbe76cdac6093784895bb4989203e5a";
String path = "font-awesome/css/font-awesome.min-" + hash + ".css";
assertEquals(hash, this.strategy.extractVersion(path));
assertNull(this.strategy.extractVersion("foo/bar.css"));
assertThat(this.strategy.extractVersion(path)).isEqualTo(hash);
assertThat(this.strategy.extractVersion("foo/bar.css")).isNull();
}
@Test
@@ -59,8 +58,7 @@ public class ContentBasedVersionStrategyTests {
String hash = "7fbe76cdac6093784895bb4989203e5a";
String path = "font-awesome/css/font-awesome.min%s%s.css";
assertEquals(String.format(path, "", ""),
this.strategy.removeVersion(String.format(path, "-", hash), hash));
assertThat(this.strategy.removeVersion(String.format(path, "-", hash), hash)).isEqualTo(String.format(path, "", ""));
}
@Test
@@ -68,12 +66,12 @@ public class ContentBasedVersionStrategyTests {
Resource expected = new ClassPathResource("test/bar.css", getClass());
String hash = DigestUtils.md5DigestAsHex(FileCopyUtils.copyToByteArray(expected.getInputStream()));
assertEquals(hash, this.strategy.getResourceVersion(expected).block());
assertThat(this.strategy.getResourceVersion(expected).block()).isEqualTo(hash);
}
@Test
public void addVersionToUrl() {
assertEquals("test/bar-123.css", this.strategy.addVersion("test/bar.css", "123"));
assertThat(this.strategy.addVersion("test/bar.css", "123")).isEqualTo("test/bar-123.css");
}
}

View File

@@ -32,8 +32,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.resource.EncodedResourceResolver.EncodedResource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -91,7 +90,7 @@ public class CssLinkResourceTransformerTests {
.consumeNextWith(transformedResource -> {
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
assertThat(result).isEqualTo(expected);
})
.expectComplete()
.verify();
@@ -103,7 +102,7 @@ public class CssLinkResourceTransformerTests {
Resource expected = getResource("foo.css");
StepVerifier.create(this.transformerChain.transform(exchange, expected))
.consumeNextWith(resource -> assertSame(expected, resource))
.consumeNextWith(resource -> assertThat(resource).isSameAs(expected))
.expectComplete().verify();
}
@@ -125,7 +124,7 @@ public class CssLinkResourceTransformerTests {
.consumeNextWith(transformedResource -> {
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
assertThat(result).isEqualTo(expected);
})
.expectComplete()
.verify();
@@ -176,7 +175,7 @@ public class CssLinkResourceTransformerTests {
.consumeNextWith(transformedResource -> {
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
assertThat(result).isEqualTo(expected);
})
.expectComplete()
.verify();

View File

@@ -42,9 +42,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link EncodedResourceResolver}.
@@ -110,13 +108,14 @@ public class EncodedResourceResolverTests {
String file = "js/foo.js";
Resource actual = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertEquals(getResource(file + ".gz").getDescription(), actual.getDescription());
assertEquals(getResource(file).getFilename(), actual.getFilename());
assertThat(actual.getDescription()).isEqualTo(getResource(file + ".gz").getDescription());
assertThat(actual.getFilename()).isEqualTo(getResource(file).getFilename());
assertTrue(actual instanceof HttpResource);
boolean condition = actual instanceof HttpResource;
assertThat(condition).isTrue();
HttpHeaders headers = ((HttpResource) actual).getResponseHeaders();
assertEquals("gzip", headers.getFirst(HttpHeaders.CONTENT_ENCODING));
assertEquals("Accept-Encoding", headers.getFirst(HttpHeaders.VARY));
assertThat(headers.getFirst(HttpHeaders.CONTENT_ENCODING)).isEqualTo("gzip");
assertThat(headers.getFirst(HttpHeaders.VARY)).isEqualTo("Accept-Encoding");
}
@Test
@@ -128,9 +127,10 @@ public class EncodedResourceResolverTests {
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
Resource actual = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertEquals(getResource("foo.css.gz").getDescription(), actual.getDescription());
assertEquals(getResource("foo.css").getFilename(), actual.getFilename());
assertTrue(actual instanceof HttpResource);
assertThat(actual.getDescription()).isEqualTo(getResource("foo.css.gz").getDescription());
assertThat(actual.getFilename()).isEqualTo(getResource("foo.css").getFilename());
boolean condition = actual instanceof HttpResource;
assertThat(condition).isTrue();
}
@Test
@@ -144,18 +144,20 @@ public class EncodedResourceResolverTests {
String file = "js/foo.js";
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertEquals(getResource(file + ".gz").getDescription(), resolved.getDescription());
assertEquals(getResource(file).getFilename(), resolved.getFilename());
assertTrue(resolved instanceof HttpResource);
assertThat(resolved.getDescription()).isEqualTo(getResource(file + ".gz").getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource(file).getFilename());
boolean condition = resolved instanceof HttpResource;
assertThat(condition).isTrue();
// 2. Resolve unencoded resource
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/js/foo.js"));
resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertEquals(getResource(file).getDescription(), resolved.getDescription());
assertEquals(getResource(file).getFilename(), resolved.getFilename());
assertFalse(resolved instanceof HttpResource);
assertThat(resolved.getDescription()).isEqualTo(getResource(file).getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource(file).getFilename());
boolean condition1 = resolved instanceof HttpResource;
assertThat(condition1).isFalse();
}
@Test // SPR-13149
@@ -164,8 +166,8 @@ public class EncodedResourceResolverTests {
String file = "js/foo.js";
Resource resolved = this.resolver.resolveResource(null, file, this.locations).block(TIMEOUT);
assertEquals(getResource(file).getDescription(), resolved.getDescription());
assertEquals(getResource(file).getFilename(), resolved.getFilename());
assertThat(resolved.getDescription()).isEqualTo(getResource(file).getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource(file).getFilename());
}
private Resource getResource(String filePath) {

View File

@@ -19,9 +19,8 @@ package org.springframework.web.reactive.resource;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/**
* Unit tests for {@link FixedVersionStrategy}.
@@ -52,24 +51,24 @@ public class FixedVersionStrategyTests {
@Test
public void extractVersion() {
assertEquals(VERSION, this.strategy.extractVersion(VERSION + "/" + PATH));
assertNull(this.strategy.extractVersion(PATH));
assertThat(this.strategy.extractVersion(VERSION + "/" + PATH)).isEqualTo(VERSION);
assertThat(this.strategy.extractVersion(PATH)).isNull();
}
@Test
public void removeVersion() {
assertEquals("/" + PATH, this.strategy.removeVersion(VERSION + "/" + PATH, VERSION));
assertThat(this.strategy.removeVersion(VERSION + "/" + PATH, VERSION)).isEqualTo(("/" + PATH));
}
@Test
public void addVersion() {
assertEquals(VERSION + "/" + PATH, this.strategy.addVersion("/" + PATH, VERSION));
assertThat(this.strategy.addVersion("/" + PATH, VERSION)).isEqualTo((VERSION + "/" + PATH));
}
@Test // SPR-13727
public void addVersionRelativePath() {
String relativePath = "../" + PATH;
assertEquals(relativePath, this.strategy.addVersion(relativePath, VERSION));
assertThat(this.strategy.addVersion(relativePath, VERSION)).isEqualTo(relativePath);
}
}

View File

@@ -27,11 +27,8 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* Unit tests for {@link PathResourceResolver}.
@@ -52,7 +49,7 @@ public class PathResourceResolverTests {
List<Resource> locations = singletonList(location);
Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT);
assertEquals(location.createRelative(path), actual);
assertThat(actual).isEqualTo(location.createRelative(path));
}
@Test
@@ -62,7 +59,7 @@ public class PathResourceResolverTests {
List<Resource> locations = singletonList(location);
Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT);
assertNotNull(actual);
assertThat(actual).isNotNull();
}
@Test // gh-22272
@@ -77,8 +74,8 @@ public class PathResourceResolverTests {
List<Resource> locations = singletonList(location);
Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT);
assertNotNull(actual);
assertEquals("foo foo.txt", actual.getFile().getName());
assertThat(actual).isNotNull();
assertThat(actual.getFile().getName()).isEqualTo("foo foo.txt");
}
@Test
@@ -106,7 +103,7 @@ public class PathResourceResolverTests {
if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) {
fail(requestPath + " doesn't actually exist as a relative path");
}
assertNull(actual);
assertThat(actual).isNull();
}
@Test
@@ -120,7 +117,7 @@ public class PathResourceResolverTests {
String actual = this.resolver.resolveUrlPath("../testalternatepath/bar.css",
singletonList(location), null).block(TIMEOUT);
assertEquals("../testalternatepath/bar.css", actual);
assertThat(actual).isEqualTo("../testalternatepath/bar.css");
}
@Test // SPR-12624
@@ -128,13 +125,13 @@ public class PathResourceResolverTests {
String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework"));
List<Resource> locations = singletonList(location);
assertNotNull(this.resolver.resolveResource(null, "main.css", locations, null).block(TIMEOUT));
assertThat(this.resolver.resolveResource(null, "main.css", locations, null).block(TIMEOUT)).isNotNull();
}
@Test // SPR-12747
public void checkFileLocation() throws Exception {
Resource resource = getResource("main.css");
assertTrue(this.resolver.checkResource(resource, resource));
assertThat(this.resolver.checkResource(resource, resource)).isTrue();
}
@Test // SPR-13241
@@ -143,7 +140,7 @@ public class PathResourceResolverTests {
String path = this.resolver.resolveUrlPathInternal(
"", singletonList(webjarsLocation), null).block(TIMEOUT);
assertNull(path);
assertThat(path).isNull();
}
private Resource getResource(String filePath) {

View File

@@ -31,7 +31,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@code ResourceTransformerSupport}.
@@ -84,8 +84,8 @@ public class ResourceTransformerSupportTests {
Resource resource = getResource("main.css");
String actual = this.transformer.resolveUrlPath(resourcePath, exchange, resource, this.chain).block(TIMEOUT);
assertEquals("/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
assertEquals("/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
assertThat(actual).isEqualTo("/resources/bar-11e16cf79faee7ac698c805cf28248d2.css");
assertThat(actual).isEqualTo("/resources/bar-11e16cf79faee7ac698c805cf28248d2.css");
}
@Test
@@ -94,7 +94,7 @@ public class ResourceTransformerSupportTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
String actual = this.transformer.resolveUrlPath("bar.css", exchange, resource, this.chain).block(TIMEOUT);
assertEquals("bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
assertThat(actual).isEqualTo("bar-11e16cf79faee7ac698c805cf28248d2.css");
}
@Test
@@ -103,17 +103,17 @@ public class ResourceTransformerSupportTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
String actual = this.transformer.resolveUrlPath("../bar.css", exchange, resource, this.chain).block(TIMEOUT);
assertEquals("../bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
assertThat(actual).isEqualTo("../bar-11e16cf79faee7ac698c805cf28248d2.css");
}
@Test
public void toAbsolutePath() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
String absolute = this.transformer.toAbsolutePath("img/image.png", exchange);
assertEquals("/resources/img/image.png", absolute);
assertThat(absolute).isEqualTo("/resources/img/image.png");
absolute = this.transformer.toAbsolutePath("/img/image.png", exchange);
assertEquals("/img/image.png", absolute);
assertThat(absolute).isEqualTo("/img/image.png");
}
private Resource getResource(String filePath) {

View File

@@ -38,7 +38,6 @@ import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
import org.springframework.web.util.pattern.PathPattern;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -78,7 +77,7 @@ public class ResourceUrlProviderTests {
String expected = "/resources/foo.css";
String actual = this.urlProvider.getForUriString(expected, this.exchange).block(TIMEOUT);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}
@Test // SPR-13374
@@ -86,11 +85,11 @@ public class ResourceUrlProviderTests {
String url = "/resources/foo.css?foo=bar&url=https://example.org";
String resolvedUrl = this.urlProvider.getForUriString(url, this.exchange).block(TIMEOUT);
assertEquals(url, resolvedUrl);
assertThat(resolvedUrl).isEqualTo(url);
url = "/resources/foo.css#hash";
resolvedUrl = this.urlProvider.getForUriString(url, this.exchange).block(TIMEOUT);
assertEquals(url, resolvedUrl);
assertThat(resolvedUrl).isEqualTo(url);
}
@Test
@@ -105,7 +104,7 @@ public class ResourceUrlProviderTests {
String path = "/resources/foo.css";
String url = this.urlProvider.getForUriString(path, this.exchange).block(TIMEOUT);
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
assertThat(url).isEqualTo("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css");
}
@Test // SPR-12647
@@ -125,7 +124,7 @@ public class ResourceUrlProviderTests {
String path = "/resources/foo.css";
String url = this.urlProvider.getForUriString(path, this.exchange).block(TIMEOUT);
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
assertThat(url).isEqualTo("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css");
}
@Test // SPR-12592

View File

@@ -58,12 +58,7 @@ import org.springframework.web.server.ServerWebExchange;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -104,13 +99,13 @@ public class ResourceWebHandlerTests {
this.handler.handle(exchange).block(TIMEOUT);
HttpHeaders headers = exchange.getResponse().getHeaders();
assertEquals(MediaType.parseMediaType("text/css"), headers.getContentType());
assertEquals(17, headers.getContentLength());
assertEquals("max-age=3600", headers.getCacheControl());
assertTrue(headers.containsKey("Last-Modified"));
assertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("test/foo.css") / 1000);
assertEquals("bytes", headers.getFirst("Accept-Ranges"));
assertEquals(1, headers.get("Accept-Ranges").size());
assertThat(headers.getContentType()).isEqualTo(MediaType.parseMediaType("text/css"));
assertThat(headers.getContentLength()).isEqualTo(17);
assertThat(headers.getCacheControl()).isEqualTo("max-age=3600");
assertThat(headers.containsKey("Last-Modified")).isTrue();
assertThat(resourceLastModifiedDate("test/foo.css") / 1000).isEqualTo(headers.getLastModified() / 1000);
assertThat(headers.getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(headers.get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, "h1 { color:red; }");
}
@@ -120,15 +115,15 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertNull(exchange.getResponse().getStatusCode());
assertThat((Object) exchange.getResponse().getStatusCode()).isNull();
HttpHeaders headers = exchange.getResponse().getHeaders();
assertEquals(MediaType.parseMediaType("text/css"), headers.getContentType());
assertEquals(17, headers.getContentLength());
assertEquals("max-age=3600", headers.getCacheControl());
assertTrue(headers.containsKey("Last-Modified"));
assertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("test/foo.css") / 1000);
assertEquals("bytes", headers.getFirst("Accept-Ranges"));
assertEquals(1, headers.get("Accept-Ranges").size());
assertThat(headers.getContentType()).isEqualTo(MediaType.parseMediaType("text/css"));
assertThat(headers.getContentLength()).isEqualTo(17);
assertThat(headers.getCacheControl()).isEqualTo("max-age=3600");
assertThat(headers.containsKey("Last-Modified")).isTrue();
assertThat(resourceLastModifiedDate("test/foo.css") / 1000).isEqualTo(headers.getLastModified() / 1000);
assertThat(headers.getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(headers.get("Accept-Ranges").size()).isEqualTo(1);
StepVerifier.create(exchange.getResponse().getBody())
.expectErrorMatches(ex -> ex.getMessage().startsWith("No content was written"))
@@ -141,8 +136,8 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertNull(exchange.getResponse().getStatusCode());
assertEquals("GET,HEAD,OPTIONS", exchange.getResponse().getHeaders().getFirst("Allow"));
assertThat(exchange.getResponse().getStatusCode()).isNull();
assertThat(exchange.getResponse().getHeaders().getFirst("Allow")).isEqualTo("GET,HEAD,OPTIONS");
}
@Test
@@ -153,11 +148,11 @@ public class ResourceWebHandlerTests {
this.handler.handle(exchange).block(TIMEOUT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals("no-store", response.getHeaders().getCacheControl());
assertTrue(response.getHeaders().containsKey("Last-Modified"));
assertEquals(response.getHeaders().getLastModified() / 1000, resourceLastModifiedDate("test/foo.css") / 1000);
assertEquals("bytes", response.getHeaders().getFirst("Accept-Ranges"));
assertEquals(1, response.getHeaders().get("Accept-Ranges").size());
assertThat(response.getHeaders().getCacheControl()).isEqualTo("no-store");
assertThat(response.getHeaders().containsKey("Last-Modified")).isTrue();
assertThat(resourceLastModifiedDate("test/foo.css") / 1000).isEqualTo(response.getHeaders().getLastModified() / 1000);
assertThat(response.getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(response.getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
}
@Test
@@ -171,9 +166,9 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "versionString/foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals("\"versionString\"", exchange.getResponse().getHeaders().getETag());
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
assertEquals(1, exchange.getResponse().getHeaders().get("Accept-Ranges").size());
assertThat(exchange.getResponse().getHeaders().getETag()).isEqualTo("\"versionString\"");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
}
@Test
@@ -183,12 +178,12 @@ public class ResourceWebHandlerTests {
this.handler.handle(exchange).block(TIMEOUT);
HttpHeaders headers = exchange.getResponse().getHeaders();
assertEquals(MediaType.TEXT_HTML, headers.getContentType());
assertEquals("max-age=3600", headers.getCacheControl());
assertTrue(headers.containsKey("Last-Modified"));
assertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("test/foo.html") / 1000);
assertEquals("bytes", headers.getFirst("Accept-Ranges"));
assertEquals(1, headers.get("Accept-Ranges").size());
assertThat(headers.getContentType()).isEqualTo(MediaType.TEXT_HTML);
assertThat(headers.getCacheControl()).isEqualTo("max-age=3600");
assertThat(headers.containsKey("Last-Modified")).isTrue();
assertThat(resourceLastModifiedDate("test/foo.html") / 1000).isEqualTo(headers.getLastModified() / 1000);
assertThat(headers.getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(headers.get("Accept-Ranges").size()).isEqualTo(1);
}
@Test
@@ -198,13 +193,13 @@ public class ResourceWebHandlerTests {
this.handler.handle(exchange).block(TIMEOUT);
HttpHeaders headers = exchange.getResponse().getHeaders();
assertEquals(MediaType.parseMediaType("text/css"), headers.getContentType());
assertEquals(17, headers.getContentLength());
assertEquals("max-age=3600", headers.getCacheControl());
assertTrue(headers.containsKey("Last-Modified"));
assertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("testalternatepath/baz.css") / 1000);
assertEquals("bytes", headers.getFirst("Accept-Ranges"));
assertEquals(1, headers.get("Accept-Ranges").size());
assertThat(headers.getContentType()).isEqualTo(MediaType.parseMediaType("text/css"));
assertThat(headers.getContentLength()).isEqualTo(17);
assertThat(headers.getCacheControl()).isEqualTo("max-age=3600");
assertThat(headers.containsKey("Last-Modified")).isTrue();
assertThat(resourceLastModifiedDate("testalternatepath/baz.css") / 1000).isEqualTo(headers.getLastModified() / 1000);
assertThat(headers.getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(headers.get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, "h1 { color:red; }");
}
@@ -214,8 +209,7 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "js/foo.js");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(MediaType.parseMediaType("application/javascript"),
exchange.getResponse().getHeaders().getContentType());
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.parseMediaType("application/javascript"));
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
}
@@ -226,7 +220,7 @@ public class ResourceWebHandlerTests {
this.handler.handle(exchange).block(TIMEOUT);
HttpHeaders headers = exchange.getResponse().getHeaders();
assertEquals(MediaType.parseMediaType("application/javascript"), headers.getContentType());
assertThat(headers.getContentType()).isEqualTo(MediaType.parseMediaType("application/javascript"));
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
}
@@ -242,7 +236,7 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.html");
handler.handle(exchange).block(TIMEOUT);
assertEquals(MediaType.TEXT_HTML, exchange.getResponse().getHeaders().getContentType());
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_HTML);
}
@Test
@@ -287,7 +281,7 @@ public class ResourceWebHandlerTests {
StepVerifier.create(handler.handle(exchange))
.expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertEquals(HttpStatus.NOT_FOUND, ((ResponseStatusException) err).getStatus());
assertThat(((ResponseStatusException) err).getStatus()).isEqualTo(HttpStatus.NOT_FOUND);
}).verify(TIMEOUT);
}
@@ -333,7 +327,7 @@ public class ResourceWebHandlerTests {
StepVerifier.create(this.handler.handle(exchange))
.expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertEquals(HttpStatus.NOT_FOUND, ((ResponseStatusException) err).getStatus());
assertThat(((ResponseStatusException) err).getStatus()).isEqualTo(HttpStatus.NOT_FOUND);
})
.verify(TIMEOUT);
if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) {
@@ -343,31 +337,31 @@ public class ResourceWebHandlerTests {
@Test
public void processPath() {
assertSame("/foo/bar", this.handler.processPath("/foo/bar"));
assertSame("foo/bar", this.handler.processPath("foo/bar"));
assertThat(this.handler.processPath("/foo/bar")).isSameAs("/foo/bar");
assertThat(this.handler.processPath("foo/bar")).isSameAs("foo/bar");
// leading whitespace control characters (00-1F)
assertEquals("/foo/bar", this.handler.processPath(" /foo/bar"));
assertEquals("/foo/bar", this.handler.processPath((char) 1 + "/foo/bar"));
assertEquals("/foo/bar", this.handler.processPath((char) 31 + "/foo/bar"));
assertEquals("foo/bar", this.handler.processPath(" foo/bar"));
assertEquals("foo/bar", this.handler.processPath((char) 31 + "foo/bar"));
assertThat(this.handler.processPath(" /foo/bar")).isEqualTo("/foo/bar");
assertThat(this.handler.processPath((char) 1 + "/foo/bar")).isEqualTo("/foo/bar");
assertThat(this.handler.processPath((char) 31 + "/foo/bar")).isEqualTo("/foo/bar");
assertThat(this.handler.processPath(" foo/bar")).isEqualTo("foo/bar");
assertThat(this.handler.processPath((char) 31 + "foo/bar")).isEqualTo("foo/bar");
// leading control character 0x7F (DEL)
assertEquals("/foo/bar", this.handler.processPath((char) 127 + "/foo/bar"));
assertEquals("/foo/bar", this.handler.processPath((char) 127 + "/foo/bar"));
assertThat(this.handler.processPath((char) 127 + "/foo/bar")).isEqualTo("/foo/bar");
assertThat(this.handler.processPath((char) 127 + "/foo/bar")).isEqualTo("/foo/bar");
// leading control and '/' characters
assertEquals("/foo/bar", this.handler.processPath(" / foo/bar"));
assertEquals("/foo/bar", this.handler.processPath(" / / foo/bar"));
assertEquals("/foo/bar", this.handler.processPath(" // /// //// foo/bar"));
assertEquals("/foo/bar", this.handler.processPath((char) 1 + " / " + (char) 127 + " // foo/bar"));
assertThat(this.handler.processPath(" / foo/bar")).isEqualTo("/foo/bar");
assertThat(this.handler.processPath(" / / foo/bar")).isEqualTo("/foo/bar");
assertThat(this.handler.processPath(" // /// //// foo/bar")).isEqualTo("/foo/bar");
assertThat(this.handler.processPath((char) 1 + " / " + (char) 127 + " // foo/bar")).isEqualTo("/foo/bar");
// root or empty path
assertEquals("", this.handler.processPath(" "));
assertEquals("/", this.handler.processPath("/"));
assertEquals("/", this.handler.processPath("///"));
assertEquals("/", this.handler.processPath("/ / / "));
assertThat(this.handler.processPath(" ")).isEqualTo("");
assertThat(this.handler.processPath("/")).isEqualTo("/");
assertThat(this.handler.processPath("///")).isEqualTo("/");
assertThat(this.handler.processPath("/ / / ")).isEqualTo("/");
}
@Test
@@ -375,10 +369,10 @@ public class ResourceWebHandlerTests {
PathResourceResolver resolver = (PathResourceResolver) this.handler.getResourceResolvers().get(0);
Resource[] locations = resolver.getAllowedLocations();
assertEquals(3, locations.length);
assertEquals("test/", ((ClassPathResource) locations[0]).getPath());
assertEquals("testalternatepath/", ((ClassPathResource) locations[1]).getPath());
assertEquals("META-INF/resources/webjars/", ((ClassPathResource) locations[2]).getPath());
assertThat(locations.length).isEqualTo(3);
assertThat(((ClassPathResource) locations[0]).getPath()).isEqualTo("test/");
assertThat(((ClassPathResource) locations[1]).getPath()).isEqualTo("testalternatepath/");
assertThat(((ClassPathResource) locations[2]).getPath()).isEqualTo("META-INF/resources/webjars/");
}
@Test
@@ -395,8 +389,8 @@ public class ResourceWebHandlerTests {
handler.afterPropertiesSet();
Resource[] locations = pathResolver.getAllowedLocations();
assertEquals(1, locations.length);
assertEquals("test/", ((ClassPathResource) locations[0]).getPath());
assertThat(locations.length).isEqualTo(1);
assertThat(((ClassPathResource) locations[0]).getPath()).isEqualTo("test/");
}
@Test
@@ -406,7 +400,7 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.NOT_MODIFIED, exchange.getResponse().getStatusCode());
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
}
@Test
@@ -417,7 +411,7 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertNull(exchange.getResponse().getStatusCode());
assertThat((Object) exchange.getResponse().getStatusCode()).isNull();
assertResponseBody(exchange, "h1 { color:red; }");
}
@@ -428,7 +422,7 @@ public class ResourceWebHandlerTests {
StepVerifier.create(this.handler.handle(exchange))
.expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertEquals(HttpStatus.NOT_FOUND, ((ResponseStatusException) err).getStatus());
assertThat(((ResponseStatusException) err).getStatus()).isEqualTo(HttpStatus.NOT_FOUND);
}).verify(TIMEOUT);
}
@@ -439,7 +433,7 @@ public class ResourceWebHandlerTests {
StepVerifier.create(this.handler.handle(exchange))
.expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertEquals(HttpStatus.NOT_FOUND, ((ResponseStatusException) err).getStatus());
assertThat(((ResponseStatusException) err).getStatus()).isEqualTo(HttpStatus.NOT_FOUND);
}).verify(TIMEOUT);
}
@@ -450,7 +444,7 @@ public class ResourceWebHandlerTests {
StepVerifier.create(this.handler.handle(exchange))
.expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertEquals(HttpStatus.NOT_FOUND, ((ResponseStatusException) err).getStatus());
assertThat(((ResponseStatusException) err).getStatus()).isEqualTo(HttpStatus.NOT_FOUND);
}).verify(TIMEOUT);
}
@@ -485,13 +479,13 @@ public class ResourceWebHandlerTests {
StepVerifier.create(mono)
.expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertEquals(HttpStatus.NOT_FOUND, ((ResponseStatusException) err).getStatus());
assertThat(((ResponseStatusException) err).getStatus()).isEqualTo(HttpStatus.NOT_FOUND);
}).verify(TIMEOUT);
// SPR-17475
AtomicReference<Throwable> exceptionRef = new AtomicReference<>();
StepVerifier.create(mono).consumeErrorWith(exceptionRef::set).verify();
StepVerifier.create(mono).consumeErrorWith(ex -> assertNotSame(exceptionRef.get(), ex)).verify();
StepVerifier.create(mono).consumeErrorWith(ex -> assertThat(ex).isNotSameAs(exceptionRef.get())).verify();
}
@Test
@@ -501,12 +495,12 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.PARTIAL_CONTENT, exchange.getResponse().getStatusCode());
assertEquals(MediaType.TEXT_PLAIN, exchange.getResponse().getHeaders().getContentType());
assertEquals(2, exchange.getResponse().getHeaders().getContentLength());
assertEquals("bytes 0-1/10", exchange.getResponse().getHeaders().getFirst("Content-Range"));
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
assertEquals(1, exchange.getResponse().getHeaders().get("Accept-Ranges").size());
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(2);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 0-1/10");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, "So");
}
@@ -517,12 +511,12 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.PARTIAL_CONTENT, exchange.getResponse().getStatusCode());
assertEquals(MediaType.TEXT_PLAIN, exchange.getResponse().getHeaders().getContentType());
assertEquals(1, exchange.getResponse().getHeaders().getContentLength());
assertEquals("bytes 9-9/10", exchange.getResponse().getHeaders().getFirst("Content-Range"));
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
assertEquals(1, exchange.getResponse().getHeaders().get("Accept-Ranges").size());
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(1);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 9-9/10");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, ".");
}
@@ -533,12 +527,12 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.PARTIAL_CONTENT, exchange.getResponse().getStatusCode());
assertEquals(MediaType.TEXT_PLAIN, exchange.getResponse().getHeaders().getContentType());
assertEquals(1, exchange.getResponse().getHeaders().getContentLength());
assertEquals("bytes 9-9/10", exchange.getResponse().getHeaders().getFirst("Content-Range"));
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
assertEquals(1, exchange.getResponse().getHeaders().get("Accept-Ranges").size());
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(1);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 9-9/10");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, ".");
}
@@ -549,12 +543,12 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.PARTIAL_CONTENT, exchange.getResponse().getStatusCode());
assertEquals(MediaType.TEXT_PLAIN, exchange.getResponse().getHeaders().getContentType());
assertEquals(1, exchange.getResponse().getHeaders().getContentLength());
assertEquals("bytes 9-9/10", exchange.getResponse().getHeaders().getFirst("Content-Range"));
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
assertEquals(1, exchange.getResponse().getHeaders().get("Accept-Ranges").size());
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(1);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 9-9/10");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, ".");
}
@@ -565,12 +559,12 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.PARTIAL_CONTENT, exchange.getResponse().getStatusCode());
assertEquals(MediaType.TEXT_PLAIN, exchange.getResponse().getHeaders().getContentType());
assertEquals(10, exchange.getResponse().getHeaders().getContentLength());
assertEquals("bytes 0-9/10", exchange.getResponse().getHeaders().getFirst("Content-Range"));
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
assertEquals(1, exchange.getResponse().getHeaders().get("Accept-Ranges").size());
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(10);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 0-9/10");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, "Some text.");
}
@@ -585,8 +579,8 @@ public class ResourceWebHandlerTests {
.expectComplete()
.verify();
assertEquals(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE, exchange.getResponse().getStatusCode());
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE);
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
}
@Test
@@ -596,9 +590,9 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.PARTIAL_CONTENT, exchange.getResponse().getStatusCode());
assertTrue(exchange.getResponse().getHeaders().getContentType().toString()
.startsWith("multipart/byteranges;boundary="));
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType().toString()
.startsWith("multipart/byteranges;boundary=")).isTrue();
String boundary = "--" + exchange.getResponse().getHeaders().getContentType().toString().substring(30);
@@ -614,20 +608,20 @@ public class ResourceWebHandlerTests {
String content = DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8);
String[] ranges = StringUtils.tokenizeToStringArray(content, "\r\n", false, true);
assertEquals(boundary, ranges[0]);
assertEquals("Content-Type: text/plain", ranges[1]);
assertEquals("Content-Range: bytes 0-1/10", ranges[2]);
assertEquals("So", ranges[3]);
assertThat(ranges[0]).isEqualTo(boundary);
assertThat(ranges[1]).isEqualTo("Content-Type: text/plain");
assertThat(ranges[2]).isEqualTo("Content-Range: bytes 0-1/10");
assertThat(ranges[3]).isEqualTo("So");
assertEquals(boundary, ranges[4]);
assertEquals("Content-Type: text/plain", ranges[5]);
assertEquals("Content-Range: bytes 4-5/10", ranges[6]);
assertEquals(" t", ranges[7]);
assertThat(ranges[4]).isEqualTo(boundary);
assertThat(ranges[5]).isEqualTo("Content-Type: text/plain");
assertThat(ranges[6]).isEqualTo("Content-Range: bytes 4-5/10");
assertThat(ranges[7]).isEqualTo(" t");
assertEquals(boundary, ranges[8]);
assertEquals("Content-Type: text/plain", ranges[9]);
assertEquals("Content-Range: bytes 8-9/10", ranges[10]);
assertEquals("t.", ranges[11]);
assertThat(ranges[8]).isEqualTo(boundary);
assertThat(ranges[9]).isEqualTo("Content-Type: text/plain");
assertThat(ranges[10]).isEqualTo("Content-Range: bytes 8-9/10");
assertThat(ranges[11]).isEqualTo("t.");
})
.expectComplete()
.verify();
@@ -640,7 +634,7 @@ public class ResourceWebHandlerTests {
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals("max-age=3600", exchange.getResponse().getHeaders().getCacheControl());
assertThat(exchange.getResponse().getHeaders().getCacheControl()).isEqualTo("max-age=3600");
}
@@ -659,8 +653,7 @@ public class ResourceWebHandlerTests {
private void assertResponseBody(MockServerWebExchange exchange, String responseBody) {
StepVerifier.create(exchange.getResponse().getBody())
.consumeNextWith(buf -> assertEquals(responseBody,
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
.consumeNextWith(buf -> assertThat(DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)).isEqualTo(responseBody))
.expectComplete()
.verify();
}

View File

@@ -34,8 +34,6 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -80,7 +78,7 @@ public class VersionResourceResolverTests {
.resolveResourceInternal(null, file, this.locations, this.chain)
.block(Duration.ofMillis(5000));
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveResource(null, file, this.locations);
verify(this.versionStrategy, never()).extractVersion(file);
}
@@ -95,7 +93,7 @@ public class VersionResourceResolverTests {
.resolveResourceInternal(null, file, this.locations, this.chain)
.block(Duration.ofMillis(5000));
assertNull(actual);
assertThat((Object) actual).isNull();
verify(this.chain, times(1)).resolveResource(null, file, this.locations);
}
@@ -110,7 +108,7 @@ public class VersionResourceResolverTests {
.resolveResourceInternal(null, file, this.locations, this.chain)
.block(Duration.ofMillis(5000));
assertNull(actual);
assertThat((Object) actual).isNull();
verify(this.chain, times(1)).resolveResource(null, file, this.locations);
verify(this.versionStrategy, times(1)).extractVersion(file);
}
@@ -130,7 +128,7 @@ public class VersionResourceResolverTests {
.resolveResourceInternal(null, versionFile, this.locations, this.chain)
.block(Duration.ofMillis(5000));
assertNull(actual);
assertThat((Object) actual).isNull();
verify(this.versionStrategy, times(1)).removeVersion(versionFile, version);
}
@@ -151,7 +149,7 @@ public class VersionResourceResolverTests {
.resolveResourceInternal(null, versionFile, this.locations, this.chain)
.block(Duration.ofMillis(5000));
assertNull(actual);
assertThat((Object) actual).isNull();
verify(this.versionStrategy, times(1)).getResourceVersion(expected);
}
@@ -174,10 +172,10 @@ public class VersionResourceResolverTests {
.resolveResourceInternal(exchange, versionFile, this.locations, this.chain)
.block(Duration.ofMillis(5000));
assertEquals(expected.getFilename(), actual.getFilename());
assertThat(actual.getFilename()).isEqualTo(expected.getFilename());
verify(this.versionStrategy, times(1)).getResourceVersion(expected);
assertThat(actual).isInstanceOf(HttpResource.class);
assertEquals("\"" + version + "\"", ((HttpResource)actual).getResponseHeaders().getETag());
assertThat(((HttpResource) actual).getResponseHeaders().getETag()).isEqualTo(("\"" + version + "\""));
}
@Test
@@ -189,10 +187,10 @@ public class VersionResourceResolverTests {
strategies.put("/**/*.js", jsStrategy);
this.resolver.setStrategyMap(strategies);
assertEquals(catchAllStrategy, this.resolver.getStrategyForPath("foo.css"));
assertEquals(catchAllStrategy, this.resolver.getStrategyForPath("foo-js.css"));
assertEquals(jsStrategy, this.resolver.getStrategyForPath("foo.js"));
assertEquals(jsStrategy, this.resolver.getStrategyForPath("bar/foo.js"));
assertThat(this.resolver.getStrategyForPath("foo.css")).isEqualTo(catchAllStrategy);
assertThat(this.resolver.getStrategyForPath("foo-js.css")).isEqualTo(catchAllStrategy);
assertThat(this.resolver.getStrategyForPath("foo.js")).isEqualTo(jsStrategy);
assertThat(this.resolver.getStrategyForPath("bar/foo.js")).isEqualTo(jsStrategy);
}
@Test // SPR-13883

View File

@@ -30,8 +30,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -76,7 +75,7 @@ public class WebJarsResourceResolverTests {
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertEquals(file, actual);
assertThat(actual).isEqualTo(file);
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
}
@@ -88,7 +87,7 @@ public class WebJarsResourceResolverTests {
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertNull(actual);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, never()).resolveUrlPath("foo/2.3/foo.txt", this.locations);
}
@@ -102,7 +101,7 @@ public class WebJarsResourceResolverTests {
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, times(1)).resolveUrlPath(expected, this.locations);
}
@@ -114,7 +113,7 @@ public class WebJarsResourceResolverTests {
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertNull(actual);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, never()).resolveUrlPath(null, this.locations);
}
@@ -130,7 +129,7 @@ public class WebJarsResourceResolverTests {
.resolveResource(this.exchange, file, this.locations, this.chain)
.block(TIMEOUT);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
}
@@ -143,7 +142,7 @@ public class WebJarsResourceResolverTests {
.resolveResource(this.exchange, file, this.locations, this.chain)
.block(TIMEOUT);
assertNull(actual);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
verify(this.chain, never()).resolveResource(this.exchange, null, this.locations);
}
@@ -165,7 +164,7 @@ public class WebJarsResourceResolverTests {
.resolveResource(this.exchange, file, this.locations, this.chain)
.block(TIMEOUT);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
}

View File

@@ -31,7 +31,7 @@ import org.springframework.web.reactive.accept.FixedContentTypeResolver;
import org.springframework.web.reactive.accept.HeaderContentTypeResolver;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.MediaType.ALL;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
@@ -57,7 +57,7 @@ public class HandlerResultHandlerTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes);
assertEquals(IMAGE_GIF, actual);
assertThat(actual).isEqualTo(IMAGE_GIF);
}
@Test
@@ -68,7 +68,7 @@ public class HandlerResultHandlerTests {
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes);
assertEquals(IMAGE_GIF, actual);
assertThat(actual).isEqualTo(IMAGE_GIF);
}
@Test // SPR-9160
@@ -79,7 +79,7 @@ public class HandlerResultHandlerTests {
List<MediaType> mediaTypes = Arrays.asList(TEXT_PLAIN, APPLICATION_JSON);
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> mediaTypes);
assertEquals(APPLICATION_JSON, actual);
assertThat(actual).isEqualTo(APPLICATION_JSON);
}
@Test
@@ -89,7 +89,7 @@ public class HandlerResultHandlerTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").accept(text8859));
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> Collections.singletonList(textUtf8));
assertEquals(text8859, actual);
assertThat(actual).isEqualTo(text8859);
}
@Test // SPR-12894
@@ -98,7 +98,7 @@ public class HandlerResultHandlerTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> producible);
assertEquals(APPLICATION_OCTET_STREAM, actual);
assertThat(actual).isEqualTo(APPLICATION_OCTET_STREAM);
}

View File

@@ -44,8 +44,7 @@ import org.springframework.web.server.WebHandler;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests with requests mapped via
@@ -73,8 +72,8 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
RequestEntity<Void> request = RequestEntity.get(url).build();
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertArrayEquals("foo".getBytes("UTF-8"), response.getBody());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isEqualTo("foo".getBytes("UTF-8"));
}
@Test
@@ -83,8 +82,8 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
RequestEntity<Void> request = RequestEntity.get(url).build();
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertArrayEquals("bar".getBytes("UTF-8"), response.getBody());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isEqualTo("bar".getBytes("UTF-8"));
}
@Test
@@ -93,8 +92,8 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
RequestEntity<Void> request = RequestEntity.get(url).build();
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals("bar", response.getHeaders().getFirst("foo"));
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().getFirst("foo")).isEqualTo("bar");
}
@Test
@@ -105,7 +104,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
new RestTemplate().exchange(request, byte[].class);
}
catch (HttpClientErrorException ex) {
assertEquals(HttpStatus.NOT_FOUND, ex.getStatusCode());
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
}

View File

@@ -23,10 +23,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.bind.annotation.RequestMethod;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* Unit tests for {@link CompositeRequestCondition}.
@@ -62,7 +60,7 @@ public class CompositeRequestConditionTests {
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param2, this.header2);
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3, this.header3);
assertEquals(cond3, cond1.combine(cond2));
assertThat(cond1.combine(cond2)).isEqualTo(cond3);
}
@Test
@@ -70,9 +68,9 @@ public class CompositeRequestConditionTests {
CompositeRequestCondition empty = new CompositeRequestCondition();
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
assertSame(empty, empty.combine(empty));
assertSame(notEmpty, notEmpty.combine(empty));
assertSame(notEmpty, empty.combine(notEmpty));
assertThat(empty.combine(empty)).isSameAs(empty);
assertThat(notEmpty.combine(empty)).isSameAs(notEmpty);
assertThat(empty.combine(notEmpty)).isSameAs(notEmpty);
}
@Test
@@ -94,19 +92,19 @@ public class CompositeRequestConditionTests {
CompositeRequestCondition composite1 = new CompositeRequestCondition(this.param1, condition1);
CompositeRequestCondition composite2 = new CompositeRequestCondition(this.param1, condition2);
assertEquals(composite2, composite1.getMatchingCondition(exchange));
assertThat(composite1.getMatchingCondition(exchange)).isEqualTo(composite2);
}
@Test
public void noMatch() {
CompositeRequestCondition cond = new CompositeRequestCondition(this.param1);
assertNull(cond.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/"))));
assertThat(cond.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isNull();
}
@Test
public void matchEmpty() {
CompositeRequestCondition empty = new CompositeRequestCondition();
assertSame(empty, empty.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/"))));
assertThat(empty.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isSameAs(empty);
}
@Test
@@ -115,8 +113,8 @@ public class CompositeRequestConditionTests {
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3);
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
assertEquals(1, cond1.compareTo(cond3, exchange));
assertEquals(-1, cond3.compareTo(cond1, exchange));
assertThat(cond1.compareTo(cond3, exchange)).isEqualTo(1);
assertThat(cond3.compareTo(cond1, exchange)).isEqualTo(-1);
}
@Test
@@ -125,9 +123,9 @@ public class CompositeRequestConditionTests {
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
assertEquals(0, empty.compareTo(empty, exchange));
assertEquals(-1, notEmpty.compareTo(empty, exchange));
assertEquals(1, empty.compareTo(notEmpty, exchange));
assertThat(empty.compareTo(empty, exchange)).isEqualTo(0);
assertThat(notEmpty.compareTo(empty, exchange)).isEqualTo(-1);
assertThat(empty.compareTo(notEmpty, exchange)).isEqualTo(1);
}
@Test

View File

@@ -26,11 +26,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.reactive.result.condition.ConsumesRequestCondition.ConsumeMediaTypeExpression;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* @author Arjen Poutsma
@@ -42,7 +39,7 @@ public class ConsumesRequestConditionTests {
MockServerWebExchange exchange = postExchange("text/plain");
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -50,13 +47,13 @@ public class ConsumesRequestConditionTests {
MockServerWebExchange exchange = postExchange("text/plain");
ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
public void getConsumableMediaTypesNegatedExpression() throws Exception {
ConsumesRequestCondition condition = new ConsumesRequestCondition("!application/xml");
assertEquals(Collections.emptySet(), condition.getConsumableMediaTypes());
assertThat(condition.getConsumableMediaTypes()).isEqualTo(Collections.emptySet());
}
@Test
@@ -64,7 +61,7 @@ public class ConsumesRequestConditionTests {
MockServerWebExchange exchange = postExchange("text/plain");
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/*");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -72,7 +69,7 @@ public class ConsumesRequestConditionTests {
MockServerWebExchange exchange = postExchange("text/plain");
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -80,7 +77,7 @@ public class ConsumesRequestConditionTests {
MockServerWebExchange exchange = postExchange("application/xml");
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
@@ -88,7 +85,7 @@ public class ConsumesRequestConditionTests {
MockServerWebExchange exchange = postExchange("01");
ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
@@ -96,7 +93,7 @@ public class ConsumesRequestConditionTests {
MockServerWebExchange exchange = postExchange("01");
ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test // gh-22010
@@ -105,16 +102,16 @@ public class ConsumesRequestConditionTests {
condition.setBodyRequired(false);
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(request)));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(request))).isNotNull();
request = MockServerHttpRequest.get("/").header(HttpHeaders.CONTENT_LENGTH, "0").build();
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(request)));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(request))).isNotNull();
request = MockServerHttpRequest.get("/").header(HttpHeaders.CONTENT_LENGTH, "21").build();
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(request)));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(request))).isNull();
request = MockServerHttpRequest.get("/").header(HttpHeaders.TRANSFER_ENCODING, "chunked").build();
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(request)));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(request))).isNull();
}
@Test
@@ -125,10 +122,10 @@ public class ConsumesRequestConditionTests {
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
}
@Test
@@ -139,10 +136,10 @@ public class ConsumesRequestConditionTests {
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*", "text/plain;q=0.7");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
}
@@ -152,7 +149,7 @@ public class ConsumesRequestConditionTests {
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("application/xml");
ConsumesRequestCondition result = condition1.combine(condition2);
assertEquals(condition2, result);
assertThat(result).isEqualTo(condition2);
}
@Test
@@ -161,7 +158,7 @@ public class ConsumesRequestConditionTests {
ConsumesRequestCondition condition2 = new ConsumesRequestCondition();
ConsumesRequestCondition result = condition1.combine(condition2);
assertEquals(condition1, result);
assertThat(result).isEqualTo(condition1);
}
@Test
@@ -183,12 +180,12 @@ public class ConsumesRequestConditionTests {
condition = new ConsumesRequestCondition("application/xml");
result = condition.getMatchingCondition(exchange);
assertNull(result);
assertThat(result).isNull();
}
private void assertConditions(ConsumesRequestCondition condition, String... expected) {
Collection<ConsumeMediaTypeExpression> expressions = condition.getContent();
assertEquals("Invalid amount of conditions", expressions.size(), expected.length);
assertThat(expected.length).as("Invalid amount of conditions").isEqualTo(expressions.size());
for (String s : expected) {
boolean found = false;
for (ConsumeMediaTypeExpression expr : expressions) {

View File

@@ -23,11 +23,7 @@ import org.junit.Test;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -39,11 +35,11 @@ public class HeadersRequestConditionTests {
@Test
public void headerEquals() {
assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("foo"));
assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("FOO"));
assertNotEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("bar"));
assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("foo=bar"));
assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("FOO=bar"));
assertThat(new HeadersRequestCondition("foo")).isEqualTo(new HeadersRequestCondition("foo"));
assertThat(new HeadersRequestCondition("FOO")).isEqualTo(new HeadersRequestCondition("foo"));
assertThat(new HeadersRequestCondition("bar")).isNotEqualTo(new HeadersRequestCondition("foo"));
assertThat(new HeadersRequestCondition("foo=bar")).isEqualTo(new HeadersRequestCondition("foo=bar"));
assertThat(new HeadersRequestCondition("FOO=bar")).isEqualTo(new HeadersRequestCondition("foo=bar"));
}
@Test
@@ -51,7 +47,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", ""));
HeadersRequestCondition condition = new HeadersRequestCondition("accept");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -59,7 +55,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("bar", ""));
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
@@ -67,7 +63,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -75,7 +71,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -83,7 +79,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bazz"));
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
@@ -91,7 +87,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
@@ -99,7 +95,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "baz"));
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -107,7 +103,7 @@ public class HeadersRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "bar"));
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
@@ -118,10 +114,10 @@ public class HeadersRequestConditionTests {
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo=a", "bar");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
}
@Test // SPR-16674
@@ -132,7 +128,7 @@ public class HeadersRequestConditionTests {
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
}
@Test
@@ -142,8 +138,7 @@ public class HeadersRequestConditionTests {
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo!=a");
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo");
assertEquals("Negated match should not count as more specific",
0, condition1.compareTo(condition2, exchange));
assertThat(condition1.compareTo(condition2, exchange)).as("Negated match should not count as more specific").isEqualTo(0);
}
@Test
@@ -153,7 +148,7 @@ public class HeadersRequestConditionTests {
HeadersRequestCondition result = condition1.combine(condition2);
Collection<?> conditions = result.getContent();
assertEquals(2, conditions.size());
assertThat(conditions.size()).isEqualTo(2);
}
@Test
@@ -162,12 +157,12 @@ public class HeadersRequestConditionTests {
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
HeadersRequestCondition result = condition.getMatchingCondition(exchange);
assertEquals(condition, result);
assertThat(result).isEqualTo(condition);
condition = new HeadersRequestCondition("bar");
result = condition.getMatchingCondition(exchange);
assertNull(result);
assertThat(result).isNull();
}
}

View File

@@ -23,11 +23,7 @@ import org.junit.Test;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -38,47 +34,47 @@ public class ParamsRequestConditionTests {
@Test
public void paramEquals() {
assertEquals(new ParamsRequestCondition("foo"), new ParamsRequestCondition("foo"));
assertFalse(new ParamsRequestCondition("foo").equals(new ParamsRequestCondition("bar")));
assertFalse(new ParamsRequestCondition("foo").equals(new ParamsRequestCondition("FOO")));
assertEquals(new ParamsRequestCondition("foo=bar"), new ParamsRequestCondition("foo=bar"));
assertFalse(new ParamsRequestCondition("foo=bar").equals(new ParamsRequestCondition("FOO=bar")));
assertThat(new ParamsRequestCondition("foo")).isEqualTo(new ParamsRequestCondition("foo"));
assertThat(new ParamsRequestCondition("foo").equals(new ParamsRequestCondition("bar"))).isFalse();
assertThat(new ParamsRequestCondition("foo").equals(new ParamsRequestCondition("FOO"))).isFalse();
assertThat(new ParamsRequestCondition("foo=bar")).isEqualTo(new ParamsRequestCondition("foo=bar"));
assertThat(new ParamsRequestCondition("foo=bar").equals(new ParamsRequestCondition("FOO=bar"))).isFalse();
}
@Test
public void paramPresent() throws Exception {
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo="))));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=")))).isNotNull();
}
@Test // SPR-15831
public void paramPresentNullValue() throws Exception {
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo"))));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo")))).isNotNull();
}
@Test
public void paramPresentNoMatch() throws Exception {
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?bar="))));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?bar=")))).isNull();
}
@Test
public void paramNotPresent() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
assertNotNull(new ParamsRequestCondition("!foo").getMatchingCondition(exchange));
assertThat(new ParamsRequestCondition("!foo").getMatchingCondition(exchange)).isNotNull();
}
@Test
public void paramValueMatch() throws Exception {
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bar"))));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bar")))).isNotNull();
}
@Test
public void paramValueNoMatch() throws Exception {
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bazz"))));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bazz")))).isNull();
}
@Test
@@ -89,10 +85,10 @@ public class ParamsRequestConditionTests {
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo", "bar");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
}
@Test // SPR-16674
@@ -103,7 +99,7 @@ public class ParamsRequestConditionTests {
ParamsRequestCondition condition2 = new ParamsRequestCondition("response_type");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
}
@Test
@@ -113,8 +109,7 @@ public class ParamsRequestConditionTests {
ParamsRequestCondition condition1 = new ParamsRequestCondition("response_type!=code");
ParamsRequestCondition condition2 = new ParamsRequestCondition("response_type");
assertEquals("Negated match should not count as more specific",
0, condition1.compareTo(condition2, exchange));
assertThat(condition1.compareTo(condition2, exchange)).as("Negated match should not count as more specific").isEqualTo(0);
}
@Test
@@ -124,7 +119,7 @@ public class ParamsRequestConditionTests {
ParamsRequestCondition result = condition1.combine(condition2);
Collection<?> conditions = result.getContent();
assertEquals(2, conditions.size());
assertThat(conditions.size()).isEqualTo(2);
}
}

View File

@@ -27,9 +27,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.pattern.PathPattern;
import org.springframework.web.util.pattern.PathPatternParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -44,8 +42,7 @@ public class PatternsRequestConditionTests {
@Test
public void prependNonEmptyPatternsOnly() {
PatternsRequestCondition c = createPatternsCondition("");
assertEquals("Do not prepend empty patterns (SPR-8255)", "",
c.getPatterns().iterator().next().getPatternString());
assertThat(c.getPatterns().iterator().next().getPatternString()).as("Do not prepend empty patterns (SPR-8255)").isEqualTo("");
}
@Test
@@ -53,7 +50,7 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition c1 = new PatternsRequestCondition();
PatternsRequestCondition c2 = new PatternsRequestCondition();
assertEquals(createPatternsCondition(), c1.combine(c2));
assertThat(c1.combine(c2)).isEqualTo(createPatternsCondition());
}
@Test
@@ -61,12 +58,12 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition c1 = createPatternsCondition("/type1", "/type2");
PatternsRequestCondition c2 = new PatternsRequestCondition();
assertEquals(createPatternsCondition("/type1", "/type2"), c1.combine(c2));
assertThat(c1.combine(c2)).isEqualTo(createPatternsCondition("/type1", "/type2"));
c1 = new PatternsRequestCondition();
c2 = createPatternsCondition("/method1", "/method2");
assertEquals(createPatternsCondition("/method1", "/method2"), c1.combine(c2));
assertThat(c1.combine(c2)).isEqualTo(createPatternsCondition("/method1", "/method2"));
}
@Test
@@ -74,7 +71,7 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition c1 = createPatternsCondition("/t1", "/t2");
PatternsRequestCondition c2 = createPatternsCondition("/m1", "/m2");
assertEquals(createPatternsCondition("/t1/m1", "/t1/m2", "/t2/m1", "/t2/m2"), c1.combine(c2));
assertThat(c1.combine(c2)).isEqualTo(createPatternsCondition("/t1/m1", "/t1/m2", "/t2/m1", "/t2/m2"));
}
@Test
@@ -83,7 +80,7 @@ public class PatternsRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
}
@Test
@@ -92,7 +89,7 @@ public class PatternsRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
}
@Test
@@ -102,7 +99,7 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
PatternsRequestCondition expected = createPatternsCondition("/foo/bar", "/foo/*", "/*/*");
assertEquals(expected, match);
assertThat(match).isEqualTo(expected);
}
@Test
@@ -112,23 +109,21 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition condition = createPatternsCondition("/foo");
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertNotNull(match);
assertEquals("Should match by default", "/foo",
match.getPatterns().iterator().next().getPatternString());
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next().getPatternString()).as("Should match by default").isEqualTo("/foo");
condition = createPatternsCondition("/foo");
match = condition.getMatchingCondition(exchange);
assertNotNull(match);
assertEquals("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)",
"/foo", match.getPatterns().iterator().next().getPatternString());
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next().getPatternString()).as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)").isEqualTo("/foo");
PathPatternParser parser = new PathPatternParser();
parser.setMatchOptionalTrailingSeparator(false);
condition = new PatternsRequestCondition(parser.parse("/foo"));
match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));
assertNull(match);
assertThat(match).isNull();
}
@Test
@@ -137,20 +132,20 @@ public class PatternsRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertNull(match);
assertThat(match).isNull();
}
@Test // gh-22543
public void matchWithEmptyPatterns() {
PatternsRequestCondition condition = new PatternsRequestCondition();
assertEquals(new PatternsRequestCondition(this.parser.parse("")), condition);
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get(""))));
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/anything"))));
assertThat(condition).isEqualTo(new PatternsRequestCondition(this.parser.parse("")));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("")))).isNotNull();
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/anything")))).isNull();
condition = condition.combine(new PatternsRequestCondition());
assertEquals(new PatternsRequestCondition(this.parser.parse("")), condition);
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get(""))));
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/anything"))));
assertThat(condition).isEqualTo(new PatternsRequestCondition(this.parser.parse("")));
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("")))).isNotNull();
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/anything")))).isNull();
}
@Test
@@ -158,16 +153,16 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition c1 = createPatternsCondition("/foo*");
PatternsRequestCondition c2 = createPatternsCondition("/foo*");
assertEquals(0, c1.compareTo(c2, MockServerWebExchange.from(get("/foo"))));
assertThat(c1.compareTo(c2, MockServerWebExchange.from(get("/foo")))).isEqualTo(0);
}
@Test
public void equallyMatchingPatternsAreBothPresent() throws Exception {
PatternsRequestCondition c = createPatternsCondition("/a", "/b");
assertEquals(2, c.getPatterns().size());
assertThat(c.getPatterns().size()).isEqualTo(2);
Iterator<PathPattern> itr = c.getPatterns().iterator();
assertEquals("/a", itr.next().getPatternString());
assertEquals("/b", itr.next().getPatternString());
assertThat(itr.next().getPatternString()).isEqualTo("/a");
assertThat(itr.next().getPatternString()).isEqualTo("/b");
}
@Test
@@ -177,12 +172,12 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition c1 = createPatternsCondition("/fo*");
PatternsRequestCondition c2 = createPatternsCondition("/foo");
assertEquals(1, c1.compareTo(c2, exchange));
assertThat(c1.compareTo(c2, exchange)).isEqualTo(1);
c1 = createPatternsCondition("/fo*");
c2 = createPatternsCondition("/*oo");
assertEquals("Patterns are equally specific even if not the same", 0, c1.compareTo(c2, exchange));
assertThat(c1.compareTo(c2, exchange)).as("Patterns are equally specific even if not the same").isEqualTo(0);
}
@Test
@@ -195,8 +190,8 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition match1 = c1.getMatchingCondition(exchange);
PatternsRequestCondition match2 = c2.getMatchingCondition(exchange);
assertNotNull(match1);
assertEquals(1, match1.compareTo(match2, exchange));
assertThat(match1).isNotNull();
assertThat(match1.compareTo(match2, exchange)).isEqualTo(1);
}
private PatternsRequestCondition createPatternsCondition(String... patterns) {

View File

@@ -27,11 +27,8 @@ import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -46,7 +43,7 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -54,13 +51,13 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
public void getProducibleMediaTypes() {
ProducesRequestCondition condition = new ProducesRequestCondition("!application/xml");
assertEquals(Collections.emptySet(), condition.getProducibleMediaTypes());
assertThat(condition.getProducibleMediaTypes()).isEqualTo(Collections.emptySet());
}
@Test
@@ -68,7 +65,7 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
ProducesRequestCondition condition = new ProducesRequestCondition("text/*");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -76,7 +73,7 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test
@@ -84,7 +81,7 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "application/xml"));
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test // gh-21670
@@ -92,22 +89,19 @@ public class ProducesRequestConditionTests {
String base = "application/atom+xml";
ProducesRequestCondition condition = new ProducesRequestCondition(base + ";type=feed");
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", base + ";type=feed"));
assertNotNull("Declared parameter value must match if present in request",
condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).as("Declared parameter value must match if present in request").isNotNull();
condition = new ProducesRequestCondition(base + ";type=feed");
exchange = MockServerWebExchange.from(get("/").header("Accept", base + ";type=entry"));
assertNull("Declared parameter value must match if present in request",
condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).as("Declared parameter value must match if present in request").isNull();
condition = new ProducesRequestCondition(base + ";type=feed");
exchange = MockServerWebExchange.from(get("/").header("Accept", base));
assertNotNull("Declared parameter has no impact if not present in request",
condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).as("Declared parameter has no impact if not present in request").isNotNull();
condition = new ProducesRequestCondition(base);
exchange = MockServerWebExchange.from(get("/").header("Accept", base + ";type=feed"));
assertNotNull("No impact from other parameters in request", condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).as("No impact from other parameters in request").isNotNull();
}
@Test
@@ -115,7 +109,7 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "bogus"));
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test
@@ -123,7 +117,7 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "bogus"));
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
@Test // SPR-17550
@@ -133,7 +127,7 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"));
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test // gh-22853
@@ -151,7 +145,7 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition noneMatch = none.getMatchingCondition(exchange);
ProducesRequestCondition htmlMatch = html.getMatchingCondition(exchange);
assertEquals(1, noneMatch.compareTo(htmlMatch, exchange));
assertThat(noneMatch.compareTo(htmlMatch, exchange)).isEqualTo(1);
}
@Test
@@ -163,31 +157,31 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/")
.header("Accept", "application/xml, text/html"));
assertTrue(html.compareTo(xml, exchange) > 0);
assertTrue(xml.compareTo(html, exchange) < 0);
assertTrue(xml.compareTo(none, exchange) < 0);
assertTrue(none.compareTo(xml, exchange) > 0);
assertTrue(html.compareTo(none, exchange) < 0);
assertTrue(none.compareTo(html, exchange) > 0);
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
assertThat(xml.compareTo(none, exchange) < 0).isTrue();
assertThat(none.compareTo(xml, exchange) > 0).isTrue();
assertThat(html.compareTo(none, exchange) < 0).isTrue();
assertThat(none.compareTo(html, exchange) > 0).isTrue();
exchange = MockServerWebExchange.from(
get("/").header("Accept", "application/xml, text/*"));
assertTrue(html.compareTo(xml, exchange) > 0);
assertTrue(xml.compareTo(html, exchange) < 0);
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
exchange = MockServerWebExchange.from(
get("/").header("Accept", "application/pdf"));
assertEquals(0, html.compareTo(xml, exchange));
assertEquals(0, xml.compareTo(html, exchange));
assertThat(html.compareTo(xml, exchange)).isEqualTo(0);
assertThat(xml.compareTo(html, exchange)).isEqualTo(0);
// See SPR-7000
exchange = MockServerWebExchange.from(
get("/").header("Accept", "text/html;q=0.9,application/xml"));
assertTrue(html.compareTo(xml, exchange) > 0);
assertTrue(xml.compareTo(html, exchange) < 0);
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
}
@Test
@@ -198,10 +192,10 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
}
@Test
@@ -212,10 +206,10 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
}
@Test
@@ -227,19 +221,19 @@ public class ProducesRequestConditionTests {
get("/").header("Accept", "text/plain", "application/xml"));
int result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
exchange = MockServerWebExchange.from(
get("/").header("Accept", "application/xml", "text/plain"));
result = condition1.compareTo(condition2, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
}
// SPR-8536
@@ -251,16 +245,14 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition1 = new ProducesRequestCondition();
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
assertTrue("Should have picked '*/*' condition as an exact match",
condition1.compareTo(condition2, exchange) < 0);
assertTrue("Should have picked '*/*' condition as an exact match",
condition2.compareTo(condition1, exchange) > 0);
assertThat(condition1.compareTo(condition2, exchange) < 0).as("Should have picked '*/*' condition as an exact match").isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).as("Should have picked '*/*' condition as an exact match").isTrue();
condition1 = new ProducesRequestCondition("*/*");
condition2 = new ProducesRequestCondition("application/json");
assertTrue(condition1.compareTo(condition2, exchange) < 0);
assertTrue(condition2.compareTo(condition1, exchange) > 0);
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
exchange = MockServerWebExchange.from(
get("/").header("Accept", "*/*"));
@@ -268,14 +260,14 @@ public class ProducesRequestConditionTests {
condition1 = new ProducesRequestCondition();
condition2 = new ProducesRequestCondition("application/json");
assertTrue(condition1.compareTo(condition2, exchange) < 0);
assertTrue(condition2.compareTo(condition1, exchange) > 0);
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
condition1 = new ProducesRequestCondition("*/*");
condition2 = new ProducesRequestCondition("application/json");
assertTrue(condition1.compareTo(condition2, exchange) < 0);
assertTrue(condition2.compareTo(condition1, exchange) > 0);
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
}
// SPR-9021
@@ -287,8 +279,8 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition1 = new ProducesRequestCondition();
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
assertTrue(condition1.compareTo(condition2, exchange) < 0);
assertTrue(condition2.compareTo(condition1, exchange) > 0);
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
}
@Test
@@ -299,10 +291,10 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/xhtml");
int result = condition1.compareTo(condition2, exchange);
assertTrue("Should have used MediaType.equals(Object) to break the match", result < 0);
assertThat(result < 0).as("Should have used MediaType.equals(Object) to break the match").isTrue();
result = condition2.compareTo(condition1, exchange);
assertTrue("Should have used MediaType.equals(Object) to break the match", result > 0);
assertThat(result > 0).as("Should have used MediaType.equals(Object) to break the match").isTrue();
}
@Test
@@ -311,7 +303,7 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/xml");
ProducesRequestCondition result = condition1.combine(condition2);
assertEquals(condition2, result);
assertThat(result).isEqualTo(condition2);
}
@Test
@@ -320,7 +312,7 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition2 = new ProducesRequestCondition();
ProducesRequestCondition result = condition1.combine(condition2);
assertEquals(condition1, result);
assertThat(result).isEqualTo(condition1);
}
@Test
@@ -344,12 +336,12 @@ public class ProducesRequestConditionTests {
condition = new ProducesRequestCondition("application/xml");
result = condition.getMatchingCondition(exchange);
assertNull(result);
assertThat(result).isNull();
}
private void assertConditions(ProducesRequestCondition condition, String... expected) {
Collection<ProducesRequestCondition.ProduceMediaTypeExpression> expressions = condition.getContent();
assertEquals("Invalid number of conditions", expressions.size(), expected.length);
assertThat(expected.length).as("Invalid number of conditions").isEqualTo(expressions.size());
for (String s : expected) {
boolean found = false;
for (ProducesRequestCondition.ProduceMediaTypeExpression expr : expressions) {

View File

@@ -22,11 +22,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.bind.annotation.RequestMethod;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* Unit tests for {@link RequestConditionHolder}.
@@ -44,7 +41,7 @@ public class RequestConditionHolderTests {
RequestConditionHolder params2 = new RequestConditionHolder(new ParamsRequestCondition("name2"));
RequestConditionHolder expected = new RequestConditionHolder(new ParamsRequestCondition("name1", "name2"));
assertEquals(expected, params1.combine(params2));
assertThat(params1.combine(params2)).isEqualTo(expected);
}
@Test
@@ -52,9 +49,9 @@ public class RequestConditionHolderTests {
RequestConditionHolder empty = new RequestConditionHolder(null);
RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name"));
assertSame(empty, empty.combine(empty));
assertSame(notEmpty, notEmpty.combine(empty));
assertSame(notEmpty, empty.combine(notEmpty));
assertThat(empty.combine(empty)).isSameAs(empty);
assertThat(notEmpty.combine(empty)).isSameAs(notEmpty);
assertThat(empty.combine(notEmpty)).isSameAs(notEmpty);
}
@Test
@@ -72,8 +69,8 @@ public class RequestConditionHolderTests {
RequestMethodsRequestCondition expected = new RequestMethodsRequestCondition(RequestMethod.GET);
RequestConditionHolder holder = custom.getMatchingCondition(this.exchange);
assertNotNull(holder);
assertEquals(expected, holder.getCondition());
assertThat(holder).isNotNull();
assertThat(holder.getCondition()).isEqualTo(expected);
}
@Test
@@ -81,13 +78,13 @@ public class RequestConditionHolderTests {
RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.POST);
RequestConditionHolder custom = new RequestConditionHolder(rm);
assertNull(custom.getMatchingCondition(this.exchange));
assertThat(custom.getMatchingCondition(this.exchange)).isNull();
}
@Test
public void matchEmpty() {
RequestConditionHolder empty = new RequestConditionHolder(null);
assertSame(empty, empty.getMatchingCondition(this.exchange));
assertThat(empty.getMatchingCondition(this.exchange)).isSameAs(empty);
}
@Test
@@ -95,8 +92,8 @@ public class RequestConditionHolderTests {
RequestConditionHolder params11 = new RequestConditionHolder(new ParamsRequestCondition("1"));
RequestConditionHolder params12 = new RequestConditionHolder(new ParamsRequestCondition("1", "2"));
assertEquals(1, params11.compareTo(params12, this.exchange));
assertEquals(-1, params12.compareTo(params11, this.exchange));
assertThat(params11.compareTo(params12, this.exchange)).isEqualTo(1);
assertThat(params12.compareTo(params11, this.exchange)).isEqualTo(-1);
}
@Test
@@ -105,9 +102,9 @@ public class RequestConditionHolderTests {
RequestConditionHolder empty2 = new RequestConditionHolder(null);
RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name"));
assertEquals(0, empty.compareTo(empty2, this.exchange));
assertEquals(-1, notEmpty.compareTo(empty, this.exchange));
assertEquals(1, empty.compareTo(notEmpty, this.exchange));
assertThat(empty.compareTo(empty2, this.exchange)).isEqualTo(0);
assertThat(notEmpty.compareTo(empty, this.exchange)).isEqualTo(-1);
assertThat(empty.compareTo(notEmpty, this.exchange)).isEqualTo(1);
}
@Test

View File

@@ -36,12 +36,8 @@ import org.springframework.web.util.pattern.PathPatternParser;
import org.springframework.web.util.pattern.PatternParseException;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.springframework.web.reactive.result.method.RequestMappingInfo.paths;
/**
@@ -59,13 +55,13 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths().build();
PathPattern emptyPattern = (new PathPatternParser()).parse("");
assertEquals(Collections.singleton(emptyPattern), info.getPatternsCondition().getPatterns());
assertEquals(0, info.getMethodsCondition().getMethods().size());
assertEquals(true, info.getConsumesCondition().isEmpty());
assertEquals(true, info.getProducesCondition().isEmpty());
assertNotNull(info.getParamsCondition());
assertNotNull(info.getHeadersCondition());
assertNull(info.getCustomCondition());
assertThat(info.getPatternsCondition().getPatterns()).isEqualTo(Collections.singleton(emptyPattern));
assertThat(info.getMethodsCondition().getMethods().size()).isEqualTo(0);
assertThat(info.getConsumesCondition().isEmpty()).isEqualTo(true);
assertThat(info.getProducesCondition().isEmpty()).isEqualTo(true);
assertThat(info.getParamsCondition()).isNotNull();
assertThat(info.getHeadersCondition()).isNotNull();
assertThat(info.getCustomCondition()).isNull();
}
@Test
@@ -79,8 +75,8 @@ public class RequestMappingInfoTests {
public void prependPatternWithSlash() {
RequestMappingInfo actual = paths("foo").build();
List<PathPattern> patterns = new ArrayList<>(actual.getPatternsCondition().getPatterns());
assertEquals(1, patterns.size());
assertEquals("/foo", patterns.get(0).getPatternString());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.get(0).getPatternString()).isEqualTo("/foo");
}
@Test
@@ -90,12 +86,12 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths("/foo*", "/bar").build();
RequestMappingInfo expected = paths("/foo*").build();
assertEquals(expected, info.getMatchingCondition(exchange));
assertThat(info.getMatchingCondition(exchange)).isEqualTo(expected);
info = paths("/**", "/foo*", "/foo").build();
expected = paths("/foo", "/foo*", "/**").build();
assertEquals(expected, info.getMatchingCondition(exchange));
assertThat(info.getMatchingCondition(exchange)).isEqualTo(expected);
}
@Test
@@ -105,12 +101,12 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
info = paths("/foo").params("foo!=bar").build();
match = info.getMatchingCondition(exchange);
assertNull(match);
assertThat(match).isNull();
}
@Test
@@ -121,12 +117,12 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths("/foo").headers("foo=bar").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
info = paths("/foo").headers("foo!=bar").build();
match = info.getMatchingCondition(exchange);
assertNull(match);
assertThat(match).isNull();
}
@Test
@@ -137,12 +133,12 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths("/foo").consumes("text/plain").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
info = paths("/foo").consumes("application/xml").build();
match = info.getMatchingCondition(exchange);
assertNull(match);
assertThat(match).isNull();
}
@Test
@@ -153,12 +149,12 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths("/foo").produces("text/plain").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
info = paths("/foo").produces("application/xml").build();
match = info.getMatchingCondition(exchange);
assertNull(match);
assertThat(match).isNull();
}
@Test
@@ -168,14 +164,14 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
info = paths("/foo").params("foo!=bar")
.customCondition(new ParamsRequestCondition("foo!=bar")).build();
match = info.getMatchingCondition(exchange);
assertNull(match);
assertThat(match).isNull();
}
@Test
@@ -191,9 +187,9 @@ public class RequestMappingInfoTests {
Collections.shuffle(list);
list.sort(comparator);
assertEquals(oneMethodOneParam, list.get(0));
assertEquals(oneMethod, list.get(1));
assertEquals(none, list.get(2));
assertThat(list.get(0)).isEqualTo(oneMethodOneParam);
assertThat(list.get(1)).isEqualTo(oneMethod);
assertThat(list.get(2)).isEqualTo(none);
}
@Test
@@ -210,8 +206,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=customBar"))
.build();
assertEquals(info1, info2);
assertEquals(info1.hashCode(), info2.hashCode());
assertThat(info2).isEqualTo(info1);
assertThat(info2.hashCode()).isEqualTo(info1.hashCode());
info2 = paths("/foo", "/NOOOOOO").methods(RequestMethod.GET)
.params("foo=bar").headers("foo=bar")
@@ -219,8 +215,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=customBar"))
.build();
assertFalse(info1.equals(info2));
assertNotEquals(info1.hashCode(), info2.hashCode());
assertThat(info1.equals(info2)).isFalse();
assertThat(info2.hashCode()).isNotEqualTo((long) info1.hashCode());
info2 = paths("/foo").methods(RequestMethod.GET, RequestMethod.POST)
.params("foo=bar").headers("foo=bar")
@@ -228,8 +224,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=customBar"))
.build();
assertFalse(info1.equals(info2));
assertNotEquals(info1.hashCode(), info2.hashCode());
assertThat(info1.equals(info2)).isFalse();
assertThat(info2.hashCode()).isNotEqualTo((long) info1.hashCode());
info2 = paths("/foo").methods(RequestMethod.GET)
.params("/NOOOOOO").headers("foo=bar")
@@ -237,8 +233,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=customBar"))
.build();
assertFalse(info1.equals(info2));
assertNotEquals(info1.hashCode(), info2.hashCode());
assertThat(info1.equals(info2)).isFalse();
assertThat(info2.hashCode()).isNotEqualTo((long) info1.hashCode());
info2 = paths("/foo").methods(RequestMethod.GET)
.params("foo=bar").headers("/NOOOOOO")
@@ -246,8 +242,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=customBar"))
.build();
assertFalse(info1.equals(info2));
assertNotEquals(info1.hashCode(), info2.hashCode());
assertThat(info1.equals(info2)).isFalse();
assertThat(info2.hashCode()).isNotEqualTo((long) info1.hashCode());
info2 = paths("/foo").methods(RequestMethod.GET)
.params("foo=bar").headers("foo=bar")
@@ -255,8 +251,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=customBar"))
.build();
assertFalse(info1.equals(info2));
assertNotEquals(info1.hashCode(), info2.hashCode());
assertThat(info1.equals(info2)).isFalse();
assertThat(info2.hashCode()).isNotEqualTo((long) info1.hashCode());
info2 = paths("/foo").methods(RequestMethod.GET)
.params("foo=bar").headers("foo=bar")
@@ -264,8 +260,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=customBar"))
.build();
assertFalse(info1.equals(info2));
assertNotEquals(info1.hashCode(), info2.hashCode());
assertThat(info1.equals(info2)).isFalse();
assertThat(info2.hashCode()).isNotEqualTo((long) info1.hashCode());
info2 = paths("/foo").methods(RequestMethod.GET)
.params("foo=bar").headers("foo=bar")
@@ -273,8 +269,8 @@ public class RequestMappingInfoTests {
.customCondition(new ParamsRequestCondition("customFoo=NOOOOOO"))
.build();
assertFalse(info1.equals(info2));
assertNotEquals(info1.hashCode(), info2.hashCode());
assertThat(info1.equals(info2)).isFalse();
assertThat(info2.hashCode()).isNotEqualTo((long) info1.hashCode());
}
@Test
@@ -287,11 +283,11 @@ public class RequestMappingInfoTests {
RequestMappingInfo info = paths("/foo").methods(RequestMethod.POST).build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
assertThat(match).isNotNull();
info = paths("/foo").methods(RequestMethod.OPTIONS).build();
match = info.getMatchingCondition(exchange);
assertNull("Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD", match);
assertThat(match).as("Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD").isNull();
}
}

View File

@@ -29,10 +29,7 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
@@ -69,7 +66,7 @@ public class RequestMethodsRequestConditionTests {
for (RequestMethod method : RequestMethod.values()) {
if (method != OPTIONS) {
ServerWebExchange exchange = getExchange(method.name());
assertNotNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
}
testNoMatch(condition, OPTIONS);
@@ -79,8 +76,8 @@ public class RequestMethodsRequestConditionTests {
@Ignore
public void getMatchingConditionWithCustomMethod() throws Exception {
ServerWebExchange exchange = getExchange("PROPFIND");
assertNotNull(new RequestMethodsRequestCondition().getMatchingCondition(exchange));
assertNull(new RequestMethodsRequestCondition(GET, POST).getMatchingCondition(exchange));
assertThat(new RequestMethodsRequestCondition().getMatchingCondition(exchange)).isNotNull();
assertThat(new RequestMethodsRequestCondition(GET, POST).getMatchingCondition(exchange)).isNull();
}
@Test
@@ -90,9 +87,9 @@ public class RequestMethodsRequestConditionTests {
exchange.getRequest().getHeaders().add("Origin", "https://example.com");
exchange.getRequest().getHeaders().add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PUT");
assertNotNull(new RequestMethodsRequestCondition().getMatchingCondition(exchange));
assertNotNull(new RequestMethodsRequestCondition(PUT).getMatchingCondition(exchange));
assertNull(new RequestMethodsRequestCondition(DELETE).getMatchingCondition(exchange));
assertThat(new RequestMethodsRequestCondition().getMatchingCondition(exchange)).isNotNull();
assertThat(new RequestMethodsRequestCondition(PUT).getMatchingCondition(exchange)).isNotNull();
assertThat(new RequestMethodsRequestCondition(DELETE).getMatchingCondition(exchange)).isNull();
}
@Test
@@ -104,16 +101,16 @@ public class RequestMethodsRequestConditionTests {
ServerWebExchange exchange = getExchange("GET");
int result = c1.compareTo(c2, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = c2.compareTo(c1, exchange);
assertTrue("Invalid comparison result: " + result, result > 0);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
result = c2.compareTo(c3, exchange);
assertTrue("Invalid comparison result: " + result, result < 0);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
result = c1.compareTo(c1, exchange);
assertEquals("Invalid comparison result ", 0, result);
assertThat(result).as("Invalid comparison result ").isEqualTo(0);
}
@Test
@@ -122,20 +119,20 @@ public class RequestMethodsRequestConditionTests {
RequestMethodsRequestCondition condition2 = new RequestMethodsRequestCondition(POST);
RequestMethodsRequestCondition result = condition1.combine(condition2);
assertEquals(2, result.getContent().size());
assertThat(result.getContent().size()).isEqualTo(2);
}
private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
ServerWebExchange exchange = getExchange(method.name());
RequestMethodsRequestCondition actual = condition.getMatchingCondition(exchange);
assertNotNull(actual);
assertEquals(Collections.singleton(method), actual.getContent());
assertThat(actual).isNotNull();
assertThat(actual.getContent()).isEqualTo(Collections.singleton(method));
}
private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
ServerWebExchange exchange = getExchange(method.name());
assertNull(condition.getMatchingCondition(exchange));
assertThat(condition.getMatchingCondition(exchange)).isNull();
}
private ServerWebExchange getExchange(String method) throws URISyntaxException {

View File

@@ -37,9 +37,6 @@ import org.springframework.web.util.pattern.PathPatternParser;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* Unit tests for {@link AbstractHandlerMethodMapping}.
@@ -81,7 +78,7 @@ public class HandlerMethodMappingTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(key));
Mono<Object> result = this.mapping.getHandler(exchange);
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
assertThat(((HandlerMethod) result.block()).getMethod()).isEqualTo(this.method1);
}
@Test
@@ -91,7 +88,7 @@ public class HandlerMethodMappingTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
Mono<Object> result = this.mapping.getHandler(exchange);
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
assertThat(((HandlerMethod) result.block()).getMethod()).isEqualTo(this.method1);
}
@Test
@@ -134,12 +131,12 @@ public class HandlerMethodMappingTests {
this.mapping.registerMapping(key, this.handler, this.method1);
Mono<Object> result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key)));
assertNotNull(result.block());
assertThat(result.block()).isNotNull();
this.mapping.unregisterMapping(key);
result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key)));
assertNull(result.block());
assertThat(result.block()).isNull();
assertThat(this.mapping.getMappingRegistry().getMappings().keySet()).isNotEqualTo(Matchers.contains(key));
}

View File

@@ -45,8 +45,6 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -167,8 +165,8 @@ public class InvocableHandlerMethodTests {
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.response(response)).method();
HandlerResult result = invokeForResult(new TestController(), method);
assertNull("Expected no result (i.e. fully handled)", result);
assertEquals("bar", this.exchange.getResponse().getHeaders().getFirst("foo"));
assertThat(result).as("Expected no result (i.e. fully handled)").isNull();
assertThat(this.exchange.getResponse().getHeaders().getFirst("foo")).isEqualTo("bar");
}
@Test
@@ -178,8 +176,8 @@ public class InvocableHandlerMethodTests {
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.responseMonoVoid(response)).method();
HandlerResult result = invokeForResult(new TestController(), method);
assertNull("Expected no result (i.e. fully handled)", result);
assertEquals("body", this.exchange.getResponse().getBodyAsString().block(Duration.ZERO));
assertThat(result).as("Expected no result (i.e. fully handled)").isNull();
assertThat(this.exchange.getResponse().getBodyAsString().block(Duration.ZERO)).isEqualTo("body");
}
@Test
@@ -188,8 +186,8 @@ public class InvocableHandlerMethodTests {
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.exchange(exchange)).method();
HandlerResult result = invokeForResult(new TestController(), method);
assertNull("Expected no result (i.e. fully handled)", result);
assertEquals("bar", this.exchange.getResponse().getHeaders().getFirst("foo"));
assertThat(result).as("Expected no result (i.e. fully handled)").isNull();
assertThat(this.exchange.getResponse().getHeaders().getFirst("foo")).isEqualTo("bar");
}
@Test
@@ -198,8 +196,8 @@ public class InvocableHandlerMethodTests {
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.exchangeMonoVoid(exchange)).method();
HandlerResult result = invokeForResult(new TestController(), method);
assertNull("Expected no result (i.e. fully handled)", result);
assertEquals("body", this.exchange.getResponse().getBodyAsString().block(Duration.ZERO));
assertThat(result).as("Expected no result (i.e. fully handled)").isNull();
assertThat(this.exchange.getResponse().getBodyAsString().block(Duration.ZERO)).isEqualTo("body");
}
@Test
@@ -210,7 +208,7 @@ public class InvocableHandlerMethodTests {
Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.notModified(exchange)).method();
HandlerResult result = invokeForResult(new TestController(), method);
assertNull("Expected no result (i.e. fully handled)", result);
assertThat(result).as("Expected no result (i.e. fully handled)").isNull();
}
@@ -238,7 +236,7 @@ public class InvocableHandlerMethodTests {
private void assertHandlerResultValue(Mono<HandlerResult> mono, String expected) {
StepVerifier.create(mono)
.consumeNextWith(result -> assertEquals(expected, result.getReturnValue()))
.consumeNextWith(result -> assertThat(result.getReturnValue()).isEqualTo(expected))
.expectComplete()
.verify();
}

View File

@@ -59,10 +59,6 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import org.springframework.web.util.pattern.PathPattern;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.method;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.post;
@@ -104,7 +100,7 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertEquals(expected, hm.getMethod());
assertThat(hm.getMethod()).isEqualTo(expected);
}
@Test
@@ -113,7 +109,7 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(get("/bar"));
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertEquals(expected, hm.getMethod());
assertThat(hm.getMethod()).isEqualTo(expected);
}
@Test
@@ -121,11 +117,11 @@ public class RequestMappingInfoHandlerMappingTests {
Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
ServerWebExchange exchange = MockServerWebExchange.from(get(""));
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertEquals(expected, hm.getMethod());
assertThat(hm.getMethod()).isEqualTo(expected);
exchange = MockServerWebExchange.from(get("/"));
hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertEquals(expected, hm.getMethod());
assertThat(hm.getMethod()).isEqualTo(expected);
}
@Test
@@ -134,7 +130,7 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo?p=anything"));
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertEquals(expected, hm.getMethod());
assertThat(hm.getMethod()).isEqualTo(expected);
}
@Test
@@ -143,7 +139,7 @@ public class RequestMappingInfoHandlerMappingTests {
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, MethodNotAllowedException.class,
ex -> assertEquals(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD), ex.getSupportedMethods()));
ex -> assertThat(ex.getSupportedMethods()).isEqualTo(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD)));
}
@Test // SPR-9603
@@ -171,8 +167,8 @@ public class RequestMappingInfoHandlerMappingTests {
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, UnsupportedMediaTypeStatusException.class,
ex -> assertEquals("415 UNSUPPORTED_MEDIA_TYPE " +
"\"Invalid mime type \"bogus\": does not contain '/'\"", ex.getMessage()));
ex -> assertThat(ex.getMessage()).isEqualTo(("415 UNSUPPORTED_MEDIA_TYPE " +
"\"Invalid mime type \"bogus\": does not contain '/'\"")));
}
@Test // SPR-8462
@@ -208,13 +204,12 @@ public class RequestMappingInfoHandlerMappingTests {
this.handlerMapping.getHandler(exchange).block();
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
assertEquals(Collections.singleton(MediaType.APPLICATION_XML), exchange.getAttributes().get(name));
assertThat(exchange.getAttributes().get(name)).isEqualTo(Collections.singleton(MediaType.APPLICATION_XML));
exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_JSON));
this.handlerMapping.getHandler(exchange).block();
assertNull("Negated expression shouldn't be listed as producible type",
exchange.getAttributes().get(name));
assertThat(exchange.getAttributes().get(name)).as("Negated expression shouldn't be listed as producible type").isNull();
}
@Test
@@ -228,9 +223,9 @@ public class RequestMappingInfoHandlerMappingTests {
String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
Map<String, String> uriVariables = (Map<String, String>) exchange.getAttributes().get(name);
assertNotNull(uriVariables);
assertEquals("1", uriVariables.get("path1"));
assertEquals("2", uriVariables.get("path2"));
assertThat(uriVariables).isNotNull();
assertThat(uriVariables.get("path1")).isEqualTo("1");
assertThat(uriVariables.get("path2")).isEqualTo("2");
}
@Test // SPR-9098
@@ -245,9 +240,9 @@ public class RequestMappingInfoHandlerMappingTests {
@SuppressWarnings("unchecked")
Map<String, String> uriVariables = (Map<String, String>) exchange.getAttributes().get(name);
assertNotNull(uriVariables);
assertEquals("group", uriVariables.get("group"));
assertEquals("a/b", uriVariables.get("identifier"));
assertThat(uriVariables).isNotNull();
assertThat(uriVariables.get("group")).isEqualTo("group");
assertThat(uriVariables.get("identifier")).isEqualTo("a/b");
}
@Test
@@ -257,10 +252,10 @@ public class RequestMappingInfoHandlerMappingTests {
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
PathPattern bestMatch = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
assertEquals("/{path1}/2", bestMatch.getPatternString());
assertThat(bestMatch.getPatternString()).isEqualTo("/{path1}/2");
HandlerMethod mapped = (HandlerMethod) exchange.getAttributes().get(BEST_MATCHING_HANDLER_ATTRIBUTE);
assertSame(handlerMethod, mapped);
assertThat(mapped).isSameAs(handlerMethod);
}
@Test // gh-22543
@@ -268,7 +263,7 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(get(""));
this.handlerMapping.handleMatch(paths().build(), handlerMethod, exchange);
PathPattern pattern = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
assertEquals("", pattern.getPatternString());
assertThat(pattern.getPatternString()).isEqualTo("");
}
@Test
@@ -282,10 +277,10 @@ public class RequestMappingInfoHandlerMappingTests {
matrixVariables = getMatrixVariables(exchange, "cars");
uriVariables = getUriTemplateVariables(exchange);
assertNotNull(matrixVariables);
assertEquals(Arrays.asList("red", "blue", "green"), matrixVariables.get("colors"));
assertEquals("2012", matrixVariables.getFirst("year"));
assertEquals("cars", uriVariables.get("cars"));
assertThat(matrixVariables).isNotNull();
assertThat(matrixVariables.get("colors")).isEqualTo(Arrays.asList("red", "blue", "green"));
assertThat(matrixVariables.getFirst("year")).isEqualTo("2012");
assertThat(uriVariables.get("cars")).isEqualTo("cars");
// SPR-11897
exchange = MockServerWebExchange.from(get("/a=42;b=c"));
@@ -298,10 +293,10 @@ public class RequestMappingInfoHandlerMappingTests {
// "/foo/{ids}" and URL "/foo/id=1;id=2;id=3" where the whole path
// segment is a sequence of name-value pairs.
assertNotNull(matrixVariables);
assertEquals(1, matrixVariables.size());
assertEquals("c", matrixVariables.getFirst("b"));
assertEquals("a=42", uriVariables.get("foo"));
assertThat(matrixVariables).isNotNull();
assertThat(matrixVariables.size()).isEqualTo(1);
assertThat(matrixVariables.getFirst("b")).isEqualTo("c");
assertThat(uriVariables.get("foo")).isEqualTo("a=42");
}
@Test
@@ -313,9 +308,9 @@ public class RequestMappingInfoHandlerMappingTests {
MultiValueMap<String, String> matrixVariables = getMatrixVariables(exchange, "cars");
Map<String, String> uriVariables = getUriTemplateVariables(exchange);
assertNotNull(matrixVariables);
assertEquals(Collections.singletonList("a/b"), matrixVariables.get("mvar"));
assertEquals("cars", uriVariables.get("cars"));
assertThat(matrixVariables).isNotNull();
assertThat(matrixVariables.get("mvar")).isEqualTo(Collections.singletonList("a/b"));
assertThat(uriVariables.get("cars")).isEqualTo("cars");
}
@@ -323,7 +318,7 @@ public class RequestMappingInfoHandlerMappingTests {
private <T> void assertError(Mono<Object> mono, final Class<T> exceptionClass, final Consumer<T> consumer) {
StepVerifier.create(mono)
.consumeErrorWith(error -> {
assertEquals(exceptionClass, error.getClass());
assertThat(error.getClass()).isEqualTo(exceptionClass);
consumer.accept((T) error);
})
.verify();
@@ -334,10 +329,7 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(request);
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, UnsupportedMediaTypeStatusException.class, ex ->
assertEquals("Invalid supported consumable media types",
Collections.singletonList(new MediaType("application", "xml")),
ex.getSupportedMediaTypes()));
assertError(mono, UnsupportedMediaTypeStatusException.class, ex -> assertThat(ex.getSupportedMediaTypes()).as("Invalid supported consumable media types").isEqualTo(Collections.singletonList(new MediaType("application", "xml"))));
}
private void testHttpOptions(String requestURI, Set<HttpMethod> allowedMethods) {
@@ -349,22 +341,19 @@ public class RequestMappingInfoHandlerMappingTests {
Mono<HandlerResult> mono = invocable.invoke(exchange, bindingContext);
HandlerResult result = mono.block();
assertNotNull(result);
assertThat(result).isNotNull();
Object value = result.getReturnValue();
assertNotNull(value);
assertEquals(HttpHeaders.class, value.getClass());
assertEquals(allowedMethods, ((HttpHeaders) value).getAllow());
assertThat(value).isNotNull();
assertThat(value.getClass()).isEqualTo(HttpHeaders.class);
assertThat(((HttpHeaders) value).getAllow()).isEqualTo(allowedMethods);
}
private void testMediaTypeNotAcceptable(String url) {
ServerWebExchange exchange = MockServerWebExchange.from(get(url).accept(MediaType.APPLICATION_JSON));
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
assertError(mono, NotAcceptableStatusException.class, ex ->
assertEquals("Invalid supported producible media types",
Collections.singletonList(new MediaType("application", "xml")),
ex.getSupportedMediaTypes()));
assertError(mono, NotAcceptableStatusException.class, ex -> assertThat(ex.getSupportedMediaTypes()).as("Invalid supported producible media types").isEqualTo(Collections.singletonList(new MediaType("application", "xml"))));
}
private void handleMatch(ServerWebExchange exchange, String pattern) {

View File

@@ -32,7 +32,7 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests related to the use of context paths.
@@ -67,11 +67,11 @@ public class ContextPathIntegrationTests {
String url = "http://localhost:" + server.getPort() + "/webApp1/test";
actual = restTemplate.getForObject(url, String.class);
assertEquals("Tested in /webApp1", actual);
assertThat(actual).isEqualTo("Tested in /webApp1");
url = "http://localhost:" + server.getPort() + "/webApp2/test";
actual = restTemplate.getForObject(url, String.class);
assertEquals("Tested in /webApp2", actual);
assertThat(actual).isEqualTo("Tested in /webApp2");
}
finally {
server.stop();
@@ -101,7 +101,7 @@ public class ContextPathIntegrationTests {
String url = "http://localhost:" + server.getPort() + "/app/api/test";
actual = restTemplate.getForObject(url, String.class);
assertEquals("Tested in /app/api", actual);
assertThat(actual).isEqualTo("Tested in /app/api");
}
finally {
server.stop();

View File

@@ -45,7 +45,7 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.HandlerResult;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
@@ -95,7 +95,7 @@ public class ControllerAdviceTests {
controller.setException(exception);
Object actual = handle(adapter, controller, "handle").getReturnValue();
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}
@Test
@@ -106,9 +106,9 @@ public class ControllerAdviceTests {
Model model = handle(adapter, controller, "handle").getModel();
assertEquals(2, model.asMap().size());
assertEquals("lAttr1", model.asMap().get("attr1"));
assertEquals("gAttr2", model.asMap().get("attr2"));
assertThat(model.asMap().size()).isEqualTo(2);
assertThat(model.asMap().get("attr1")).isEqualTo("lAttr1");
assertThat(model.asMap().get("attr2")).isEqualTo("gAttr2");
}
@Test
@@ -123,7 +123,7 @@ public class ControllerAdviceTests {
BindingContext bindingContext = handle(adapter, controller, "handle").getBindingContext();
WebExchangeDataBinder binder = bindingContext.createDataBinder(this.exchange, "name");
assertEquals(Collections.singletonList(validator), binder.getValidators());
assertThat(binder.getValidators()).isEqualTo(Collections.singletonList(validator));
}

View File

@@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebFlux;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* {@code @RequestMapping} integration focusing on controller method parameters.
@@ -55,20 +55,20 @@ public class ControllerInputIntegrationTests extends AbstractRequestMappingInteg
@Test
public void handleWithParam() throws Exception {
String expected = "Hello George!";
assertEquals(expected, performGet("/param?name=George", new HttpHeaders(), String.class).getBody());
assertThat(performGet("/param?name=George", new HttpHeaders(), String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-15140
public void handleWithEncodedParam() throws Exception {
String expected = "Hello + \u00e0!";
assertEquals(expected, performGet("/param?name=%20%2B+%C3%A0", new HttpHeaders(), String.class).getBody());
assertThat(performGet("/param?name=%20%2B+%C3%A0", new HttpHeaders(), String.class).getBody()).isEqualTo(expected);
}
@Test
public void matrixVariable() throws Exception {
String expected = "p=11, q2=22, q4=44";
String url = "/first;p=11/second;q=22/third-fourth;q=44";
assertEquals(expected, performGet(url, new HttpHeaders(), String.class).getBody());
assertThat(performGet(url, new HttpHeaders(), String.class).getBody()).isEqualTo(expected);
}

View File

@@ -47,8 +47,7 @@ import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link ControllerMethodResolver}.
@@ -90,73 +89,73 @@ public class ControllerMethodResolverTests {
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
AtomicInteger index = new AtomicInteger(-1);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestParamMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestBodyMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestPartMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ModelAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(CookieValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ExpressionValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(SessionAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestBodyMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestPartMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CookieValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ExpressionValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(SessionAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestAttributeMethodArgumentResolver.class);
assertEquals(ContinuationHandlerMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(HttpEntityMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ErrorsMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PrincipalMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(SessionStatusMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(WebSessionMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(ContinuationHandlerMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(HttpEntityMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ErrorsMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ServerWebExchangeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PrincipalMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(SessionStatusMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(WebSessionMethodArgumentResolver.class);
assertEquals(CustomArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomSyncArgumentResolver.class);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ModelAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
}
@Test
public void modelAttributeArgumentResolvers() {
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod);
assertEquals("Expected one each from Controller + ControllerAdvice", 2, methods.size());
assertThat(methods.size()).as("Expected one each from Controller + ControllerAdvice").isEqualTo(2);
InvocableHandlerMethod invocable = methods.get(0);
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
AtomicInteger index = new AtomicInteger(-1);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestParamMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ModelAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(CookieValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ExpressionValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(SessionAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CookieValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ExpressionValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(SessionAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestAttributeMethodArgumentResolver.class);
assertEquals(ContinuationHandlerMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ErrorsMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PrincipalMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(WebSessionMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(ContinuationHandlerMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ErrorsMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ServerWebExchangeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PrincipalMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(WebSessionMethodArgumentResolver.class);
assertEquals(CustomArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomSyncArgumentResolver.class);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ModelAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelAttributeMethodArgumentResolver.class);
}
@Test
@@ -164,29 +163,29 @@ public class ControllerMethodResolverTests {
List<SyncInvocableHandlerMethod> methods =
this.methodResolver.getInitBinderMethods(this.handlerMethod);
assertEquals("Expected one each from Controller + ControllerAdvice", 2, methods.size());
assertThat(methods.size()).as("Expected one each from Controller + ControllerAdvice").isEqualTo(2);
SyncInvocableHandlerMethod invocable = methods.get(0);
List<SyncHandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
AtomicInteger index = new AtomicInteger(-1);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestParamMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(CookieValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ExpressionValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CookieValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ExpressionValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestAttributeMethodArgumentResolver.class);
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ServerWebExchangeMethodArgumentResolver.class);
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomSyncArgumentResolver.class);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
}
@Test
@@ -194,34 +193,34 @@ public class ControllerMethodResolverTests {
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod);
assertNotNull("No match", invocable);
assertEquals(TestController.class, invocable.getBeanType());
assertThat(invocable).as("No match").isNotNull();
assertThat(invocable.getBeanType()).isEqualTo(TestController.class);
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
AtomicInteger index = new AtomicInteger(-1);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestParamMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PathVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(MatrixVariableMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestHeaderMapMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(CookieValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ExpressionValueMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(SessionAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(RequestAttributeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PathVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(MatrixVariableMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestHeaderMapMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CookieValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ExpressionValueMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(SessionAttributeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestAttributeMethodArgumentResolver.class);
assertEquals(ContinuationHandlerMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ModelMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(ServerWebExchangeMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(PrincipalMethodArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(WebSessionMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(ContinuationHandlerMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ModelMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(ServerWebExchangeMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(PrincipalMethodArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(WebSessionMethodArgumentResolver.class);
assertEquals(CustomArgumentResolver.class, next(resolvers, index).getClass());
assertEquals(CustomSyncArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomArgumentResolver.class);
assertThat(next(resolvers, index).getClass()).isEqualTo(CustomSyncArgumentResolver.class);
assertEquals(RequestParamMethodArgumentResolver.class, next(resolvers, index).getClass());
assertThat(next(resolvers, index).getClass()).isEqualTo(RequestParamMethodArgumentResolver.class);
}
@Test
@@ -229,8 +228,8 @@ public class ControllerMethodResolverTests {
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
new IllegalStateException("reason"), this.handlerMethod);
assertNotNull(invocable);
assertEquals(TestControllerAdvice.class, invocable.getBeanType());
assertThat(invocable).isNotNull();
assertThat(invocable.getBeanType()).isEqualTo(TestControllerAdvice.class);
}

View File

@@ -35,10 +35,8 @@ import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.server.ServerWebInputException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Test fixture with {@link CookieValueMethodArgumentResolver}.
@@ -77,13 +75,13 @@ public class CookieValueMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertTrue(this.resolver.supportsParameter(this.cookieParameter));
assertTrue(this.resolver.supportsParameter(this.cookieStringParameter));
assertThat(this.resolver.supportsParameter(this.cookieParameter)).isTrue();
assertThat(this.resolver.supportsParameter(this.cookieStringParameter)).isTrue();
}
@Test
public void doesNotSupportParameter() {
assertFalse(this.resolver.supportsParameter(this.stringParameter));
assertThat(this.resolver.supportsParameter(this.stringParameter)).isFalse();
assertThatIllegalStateException().isThrownBy(() ->
this.resolver.supportsParameter(this.cookieMonoParameter))
.withMessageStartingWith("CookieValueMethodArgumentResolver does not support reactive type wrapper");
@@ -97,7 +95,7 @@ public class CookieValueMethodArgumentResolverTests {
Mono<Object> mono = this.resolver.resolveArgument(
this.cookieParameter, this.bindingContext, exchange);
assertEquals(expected, mono.block());
assertThat(mono.block()).isEqualTo(expected);
}
@Test
@@ -108,7 +106,7 @@ public class CookieValueMethodArgumentResolverTests {
Mono<Object> mono = this.resolver.resolveArgument(
this.cookieStringParameter, this.bindingContext, exchange);
assertEquals("Invalid result", cookie.getValue(), mono.block());
assertThat(mono.block()).as("Invalid result").isEqualTo(cookie.getValue());
}
@Test
@@ -116,8 +114,9 @@ public class CookieValueMethodArgumentResolverTests {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
Object result = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange).block();
assertTrue(result instanceof String);
assertEquals("bar", result);
boolean condition = result instanceof String;
assertThat(condition).isTrue();
assertThat(result).isEqualTo("bar");
}
@Test

View File

@@ -41,11 +41,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.config.EnableWebFlux;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests with {@code @CrossOrigin} and {@code @RequestMapping}
@@ -89,55 +85,55 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
@Test
public void actualGetRequestWithoutAnnotation() throws Exception {
ResponseEntity<String> entity = performGet("/no", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertNull(entity.getHeaders().getAccessControlAllowOrigin());
assertEquals("no", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isNull();
assertThat(entity.getBody()).isEqualTo("no");
}
@Test
public void actualPostRequestWithoutAnnotation() throws Exception {
ResponseEntity<String> entity = performPost("/no", this.headers, null, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertNull(entity.getHeaders().getAccessControlAllowOrigin());
assertEquals("no-post", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isNull();
assertThat(entity.getBody()).isEqualTo("no-post");
}
@Test
public void actualRequestWithDefaultAnnotation() throws Exception {
ResponseEntity<String> entity = performGet("/default", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin());
assertFalse(entity.getHeaders().getAccessControlAllowCredentials());
assertEquals("default", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isFalse();
assertThat(entity.getBody()).isEqualTo("default");
}
@Test
public void preflightRequestWithDefaultAnnotation() throws Exception {
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<Void> entity = performOptions("/default", this.headers, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin());
assertEquals(1800, entity.getHeaders().getAccessControlMaxAge());
assertFalse(entity.getHeaders().getAccessControlAllowCredentials());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
assertThat(entity.getHeaders().getAccessControlMaxAge()).isEqualTo(1800);
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isFalse();
}
@Test
public void actualRequestWithDefaultAnnotationAndNoOrigin() throws Exception {
HttpHeaders headers = new HttpHeaders();
ResponseEntity<String> entity = performGet("/default", headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertNull(entity.getHeaders().getAccessControlAllowOrigin());
assertEquals("default", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isNull();
assertThat(entity.getBody()).isEqualTo("default");
}
@Test
public void actualRequestWithCustomizedAnnotation() throws Exception {
ResponseEntity<String> entity = performGet("/customized", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
assertFalse(entity.getHeaders().getAccessControlAllowCredentials());
assertEquals(-1, entity.getHeaders().getAccessControlMaxAge());
assertEquals("customized", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isFalse();
assertThat(entity.getHeaders().getAccessControlMaxAge()).isEqualTo(-1);
assertThat(entity.getBody()).isEqualTo("customized");
}
@Test
@@ -146,53 +142,50 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2");
ResponseEntity<String> entity = performOptions("/customized", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
assertArrayEquals(new HttpMethod[] {HttpMethod.GET},
entity.getHeaders().getAccessControlAllowMethods().toArray());
assertArrayEquals(new String[] {"header1", "header2"},
entity.getHeaders().getAccessControlAllowHeaders().toArray());
assertArrayEquals(new String[] {"header3", "header4"},
entity.getHeaders().getAccessControlExposeHeaders().toArray());
assertFalse(entity.getHeaders().getAccessControlAllowCredentials());
assertEquals(123, entity.getHeaders().getAccessControlMaxAge());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getHeaders().getAccessControlAllowMethods().toArray()).isEqualTo(new HttpMethod[] {HttpMethod.GET});
assertThat(entity.getHeaders().getAccessControlAllowHeaders().toArray()).isEqualTo(new String[] {"header1", "header2"});
assertThat(entity.getHeaders().getAccessControlExposeHeaders().toArray()).isEqualTo(new String[] {"header3", "header4"});
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isFalse();
assertThat(entity.getHeaders().getAccessControlMaxAge()).isEqualTo(123);
}
@Test
public void customOriginDefinedViaValueAttribute() throws Exception {
ResponseEntity<String> entity = performGet("/origin-value-attribute", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
assertEquals("value-attribute", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getBody()).isEqualTo("value-attribute");
}
@Test
public void customOriginDefinedViaPlaceholder() throws Exception {
ResponseEntity<String> entity = performGet("/origin-placeholder", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
assertEquals("placeholder", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getBody()).isEqualTo("placeholder");
}
@Test
public void classLevel() throws Exception {
ResponseEntity<String> entity = performGet("/foo", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin());
assertFalse(entity.getHeaders().getAccessControlAllowCredentials());
assertEquals("foo", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isFalse();
assertThat(entity.getBody()).isEqualTo("foo");
entity = performGet("/bar", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin());
assertFalse(entity.getHeaders().getAccessControlAllowCredentials());
assertEquals("bar", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isFalse();
assertThat(entity.getBody()).isEqualTo("bar");
entity = performGet("/baz", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
assertTrue(entity.getHeaders().getAccessControlAllowCredentials());
assertEquals("baz", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isTrue();
assertThat(entity.getBody()).isEqualTo("baz");
}
@Test
@@ -201,13 +194,11 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "header1");
ResponseEntity<String> entity = performOptions("/ambiguous-header", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
assertArrayEquals(new HttpMethod[] {HttpMethod.GET},
entity.getHeaders().getAccessControlAllowMethods().toArray());
assertArrayEquals(new String[] {"header1"},
entity.getHeaders().getAccessControlAllowHeaders().toArray());
assertTrue(entity.getHeaders().getAccessControlAllowCredentials());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getHeaders().getAccessControlAllowMethods().toArray()).isEqualTo(new HttpMethod[] {HttpMethod.GET});
assertThat(entity.getHeaders().getAccessControlAllowHeaders().toArray()).isEqualTo(new String[] {"header1"});
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isTrue();
}
@Test
@@ -215,11 +206,10 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/ambiguous-produces", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
assertArrayEquals(new HttpMethod[] {HttpMethod.GET},
entity.getHeaders().getAccessControlAllowMethods().toArray());
assertTrue(entity.getHeaders().getAccessControlAllowCredentials());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getHeaders().getAccessControlAllowMethods().toArray()).isEqualTo(new HttpMethod[] {HttpMethod.GET});
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isTrue();
}

View File

@@ -34,10 +34,8 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.method.ResolvableMethod;
import org.springframework.web.reactive.BindingContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link ErrorsMethodArgumentResolver}.
@@ -60,16 +58,16 @@ public class ErrorsMethodArgumentResolverTests {
@Test
public void supports() {
MethodParameter parameter = this.testMethod.arg(Errors.class);
assertTrue(this.resolver.supportsParameter(parameter));
assertThat(this.resolver.supportsParameter(parameter)).isTrue();
parameter = this.testMethod.arg(BindingResult.class);
assertTrue(this.resolver.supportsParameter(parameter));
assertThat(this.resolver.supportsParameter(parameter)).isTrue();
parameter = this.testMethod.arg(ResolvableType.forClassWithGenerics(Mono.class, Errors.class));
assertTrue(this.resolver.supportsParameter(parameter));
assertThat(this.resolver.supportsParameter(parameter)).isTrue();
parameter = this.testMethod.arg(String.class);
assertFalse(this.resolver.supportsParameter(parameter));
assertThat(this.resolver.supportsParameter(parameter)).isFalse();
}
@Test
@@ -81,7 +79,7 @@ public class ErrorsMethodArgumentResolverTests {
Object actual = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.block(Duration.ofMillis(5000));
assertSame(bindingResult, actual);
assertThat(actual).isSameAs(bindingResult);
}
private BindingResult createBindingResult(Foo target, String name) {
@@ -100,7 +98,7 @@ public class ErrorsMethodArgumentResolverTests {
Object actual = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.block(Duration.ofMillis(5000));
assertSame(bindingResult, actual);
assertThat(actual).isSameAs(bindingResult);
}
@Test

View File

@@ -31,10 +31,8 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.reactive.BindingContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link ExpressionValueMethodArgumentResolver}.
@@ -69,12 +67,12 @@ public class ExpressionValueMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertTrue(this.resolver.supportsParameter(this.paramSystemProperty));
assertThat(this.resolver.supportsParameter(this.paramSystemProperty)).isTrue();
}
@Test
public void doesNotSupport() {
assertFalse(this.resolver.supportsParameter(this.paramNotSupported));
assertThat(this.resolver.supportsParameter(this.paramNotSupported)).isFalse();
assertThatIllegalStateException().isThrownBy(() ->
this.resolver.supportsParameter(this.paramAlsoNotSupported))
.withMessageStartingWith("ExpressionValueMethodArgumentResolver does not support reactive type wrapper");
@@ -88,7 +86,7 @@ public class ExpressionValueMethodArgumentResolverTests {
this.paramSystemProperty, new BindingContext(), this.exchange);
Object value = mono.block();
assertEquals(22, value);
assertThat(value).isEqualTo(22);
}
finally {
System.clearProperty("systemProperty");

View File

@@ -38,8 +38,6 @@ import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/**
*
@@ -80,9 +78,9 @@ public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingInte
@Test
public void actualRequestWithCorsEnabled() throws Exception {
ResponseEntity<String> entity = performGet("/cors", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin());
assertEquals("cors", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
assertThat(entity.getBody()).isEqualTo("cors");
}
@Test
@@ -95,25 +93,25 @@ public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingInte
@Test
public void actualRequestWithoutCorsEnabled() throws Exception {
ResponseEntity<String> entity = performGet("/welcome", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertNull(entity.getHeaders().getAccessControlAllowOrigin());
assertEquals("welcome", entity.getBody());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isNull();
assertThat(entity.getBody()).isEqualTo("welcome");
}
@Test
public void actualRequestWithAmbiguousMapping() throws Exception {
this.headers.add(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE);
ResponseEntity<String> entity = performGet("/ambiguous", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
}
@Test
public void preFlightRequestWithCorsEnabled() throws Exception {
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/cors", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
assertThat(entity.getHeaders().getAccessControlAllowMethods())
.containsExactly(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.POST);
}
@@ -139,8 +137,8 @@ public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingInte
this.headers.set(HttpHeaders.ORIGIN, "https://foo");
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/cors-restricted", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("https://foo", entity.getHeaders().getAccessControlAllowOrigin());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://foo");
assertThat(entity.getHeaders().getAccessControlAllowMethods())
.containsExactly(HttpMethod.GET, HttpMethod.POST);
}
@@ -149,11 +147,11 @@ public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingInte
public void preFlightRequestWithAmbiguousMapping() throws Exception {
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/ambiguous", this.headers, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("http://localhost:9000", entity.getHeaders().getAccessControlAllowOrigin());
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("http://localhost:9000");
assertThat(entity.getHeaders().getAccessControlAllowMethods())
.containsExactly(HttpMethod.GET);
assertEquals(true, entity.getHeaders().getAccessControlAllowCredentials());
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isEqualTo(true);
assertThat(entity.getHeaders().get(HttpHeaders.VARY))
.containsExactly(HttpHeaders.ORIGIN, HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD,
HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);

View File

@@ -47,12 +47,8 @@ import org.springframework.web.reactive.BindingContext;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebInputException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.core.ResolvableType.forClassWithGenerics;
import static org.springframework.http.MediaType.TEXT_PLAIN;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.post;
@@ -95,13 +91,13 @@ public class HttpEntityMethodArgumentResolverTests {
}
private void testSupports(MethodParameter parameter) {
assertTrue(this.resolver.supportsParameter(parameter));
assertThat(this.resolver.supportsParameter(parameter)).isTrue();
}
@Test
public void doesNotSupport() {
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, String.class)));
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, String.class))).isFalse();
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
assertThatIllegalStateException().isThrownBy(() ->
this.resolver.supportsParameter(this.testMethod.arg(Mono.class, httpEntityType(String.class))))
.withMessageStartingWith("HttpEntityMethodArgumentResolver does not support reactive type wrapper");
@@ -112,7 +108,7 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(String.class);
HttpEntity<Object> entity = resolveValueWithEmptyBody(type);
assertNull(entity.getBody());
assertThat(entity.getBody()).isNull();
}
@Test
@@ -203,8 +199,8 @@ public class HttpEntityMethodArgumentResolverTests {
HttpEntity<CompletableFuture<String>> entity = resolveValueWithEmptyBody(type);
entity.getBody().whenComplete((body, ex) -> {
assertNull(body);
assertNull(ex);
assertThat(body).isNull();
assertThat(ex).isNull();
});
}
@@ -214,8 +210,8 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(String.class);
HttpEntity<String> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
assertThat(httpEntity.getBody()).isEqualTo("line1");
}
@Test
@@ -224,8 +220,8 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(Mono.class, String.class);
HttpEntity<Mono<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody().block());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
assertThat(httpEntity.getBody().block()).isEqualTo("line1");
}
@Test
@@ -234,8 +230,8 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(Single.class, String.class);
HttpEntity<Single<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody().toBlocking().value());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
assertThat(httpEntity.getBody().toBlocking().value()).isEqualTo("line1");
}
@Test
@@ -244,8 +240,8 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(io.reactivex.Single.class, String.class);
HttpEntity<io.reactivex.Single<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody().blockingGet());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
assertThat(httpEntity.getBody().blockingGet()).isEqualTo("line1");
}
@Test
@@ -254,8 +250,8 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(Maybe.class, String.class);
HttpEntity<Maybe<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody().blockingGet());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
assertThat(httpEntity.getBody().blockingGet()).isEqualTo("line1");
}
@Test
@@ -264,8 +260,8 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(CompletableFuture.class, String.class);
HttpEntity<CompletableFuture<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody().get());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
assertThat(httpEntity.getBody().get()).isEqualTo("line1");
}
@Test
@@ -274,7 +270,7 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = httpEntityType(Flux.class, String.class);
HttpEntity<Flux<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
StepVerifier.create(httpEntity.getBody())
.expectNext("line1")
.expectNext("line2")
@@ -289,10 +285,10 @@ public class HttpEntityMethodArgumentResolverTests {
ResolvableType type = forClassWithGenerics(RequestEntity.class, String.class);
RequestEntity<String> requestEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getMethod(), requestEntity.getMethod());
assertEquals(exchange.getRequest().getURI(), requestEntity.getUrl());
assertEquals(exchange.getRequest().getHeaders(), requestEntity.getHeaders());
assertEquals("line1", requestEntity.getBody());
assertThat(requestEntity.getMethod()).isEqualTo(exchange.getRequest().getMethod());
assertThat(requestEntity.getUrl()).isEqualTo(exchange.getRequest().getURI());
assertThat(requestEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
assertThat(requestEntity.getBody()).isEqualTo("line1");
}
@@ -313,9 +309,8 @@ public class HttpEntityMethodArgumentResolverTests {
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
Object value = result.block(Duration.ofSeconds(5));
assertNotNull(value);
assertTrue("Unexpected return value type: " + value.getClass(),
param.getParameterType().isAssignableFrom(value.getClass()));
assertThat(value).isNotNull();
assertThat(param.getParameterType().isAssignableFrom(value.getClass())).as("Unexpected return value type: " + value.getClass()).isTrue();
return (T) value;
}
@@ -327,7 +322,7 @@ public class HttpEntityMethodArgumentResolverTests {
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
HttpEntity<String> httpEntity = (HttpEntity<String>) result.block(Duration.ofSeconds(5));
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
return (HttpEntity<T>) httpEntity;
}

View File

@@ -37,11 +37,8 @@ import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver;
import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* Unit tests for {@link InitBinderBindingContext}.
@@ -61,8 +58,8 @@ public class InitBinderBindingContextTests {
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("id", dataBinder.getDisallowedFields()[0]);
assertThat(dataBinder.getDisallowedFields()).isNotNull();
assertThat(dataBinder.getDisallowedFields()[0]).isEqualTo("id");
}
@Test
@@ -74,7 +71,7 @@ public class InitBinderBindingContextTests {
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
assertSame(conversionService, dataBinder.getConversionService());
assertThat(dataBinder.getConversionService()).isSameAs(conversionService);
}
@Test
@@ -83,8 +80,8 @@ public class InitBinderBindingContextTests {
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("id", dataBinder.getDisallowedFields()[0]);
assertThat(dataBinder.getDisallowedFields()).isNotNull();
assertThat(dataBinder.getDisallowedFields()[0]).isEqualTo("id");
}
@Test
@@ -93,7 +90,7 @@ public class InitBinderBindingContextTests {
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "invalidName");
assertNull(dataBinder.getDisallowedFields());
assertThat(dataBinder.getDisallowedFields()).isNull();
}
@Test
@@ -102,7 +99,7 @@ public class InitBinderBindingContextTests {
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
assertNull(dataBinder.getDisallowedFields());
assertThat(dataBinder.getDisallowedFields()).isNull();
}
@Test
@@ -123,8 +120,8 @@ public class InitBinderBindingContextTests {
BindingContext context = createBindingContext("initBinderTypeConversion", WebDataBinder.class, int.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]);
assertThat(dataBinder.getDisallowedFields()).isNotNull();
assertThat(dataBinder.getDisallowedFields()[0]).isEqualTo("requestParam-22");
}

View File

@@ -37,7 +37,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebFlux;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Sebastien Deleuze
@@ -56,47 +56,47 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
@Test
public void jsonViewResponse() throws Exception {
String expected = "{\"withView1\":\"with\"}";
assertEquals(expected, performGet("/response/raw", MediaType.APPLICATION_JSON, String.class).getBody());
assertThat(performGet("/response/raw", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithMonoResponse() throws Exception {
String expected = "{\"withView1\":\"with\"}";
assertEquals(expected, performGet("/response/mono", MediaType.APPLICATION_JSON, String.class).getBody());
assertThat(performGet("/response/mono", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-16098
public void jsonViewWithMonoResponseEntity() throws Exception {
String expected = "{\"withView1\":\"with\"}";
assertEquals(expected, performGet("/response/entity", MediaType.APPLICATION_JSON, String.class).getBody());
assertThat(performGet("/response/entity", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithFluxResponse() throws Exception {
String expected = "[{\"withView1\":\"with\"},{\"withView1\":\"with\"}]";
assertEquals(expected, performGet("/response/flux", MediaType.APPLICATION_JSON, String.class).getBody());
assertThat(performGet("/response/flux", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithRequest() throws Exception {
String expected = "{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}";
assertEquals(expected, performPost("/request/raw", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"), MediaType.APPLICATION_JSON, String.class).getBody());
assertThat(performPost("/request/raw", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"), MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithMonoRequest() throws Exception {
String expected = "{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}";
assertEquals(expected, performPost("/request/mono", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"), MediaType.APPLICATION_JSON, String.class).getBody());
assertThat(performPost("/request/mono", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"), MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-16098
public void jsonViewWithEntityMonoRequest() throws Exception {
String expected = "{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}";
assertEquals(expected, performPost("/request/entity/mono", MediaType.APPLICATION_JSON,
assertThat(performPost("/request/entity/mono", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"),
MediaType.APPLICATION_JSON, String.class).getBody());
MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-16098
@@ -104,10 +104,10 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
String expected = "[" +
"{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}," +
"{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}]";
assertEquals(expected, performPost("/request/entity/flux", MediaType.APPLICATION_JSON,
assertThat(performPost("/request/entity/flux", MediaType.APPLICATION_JSON,
Arrays.asList(new JacksonViewBean("with", "with", "without"),
new JacksonViewBean("with", "with", "without")),
MediaType.APPLICATION_JSON, String.class).getBody());
MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
@@ -118,8 +118,8 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
List<JacksonViewBean> beans = Arrays.asList(
new JacksonViewBean("with", "with", "without"),
new JacksonViewBean("with", "with", "without"));
assertEquals(expected, performPost("/request/flux", MediaType.APPLICATION_JSON, beans,
MediaType.APPLICATION_JSON, String.class).getBody());
assertThat(performPost("/request/flux", MediaType.APPLICATION_JSON, beans,
MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}

View File

@@ -35,10 +35,7 @@ import org.springframework.web.method.ResolvableMethod;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.HandlerMapping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.method.MvcAnnotationPredicates.matrixAttribute;
/**
@@ -65,19 +62,19 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
assertTrue(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().noName())
.arg(Map.class, String.class, String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().noName())
.arg(Map.class, String.class, String.class))).isTrue();
assertTrue(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().noPathVar())
.arg(MultiValueMap.class, String.class, String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().noPathVar())
.arg(MultiValueMap.class, String.class, String.class))).isTrue();
assertTrue(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().pathVar("cars"))
.arg(MultiValueMap.class, String.class, String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().pathVar("cars"))
.arg(MultiValueMap.class, String.class, String.class))).isTrue();
assertFalse(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().name("name"))
.arg(Map.class, String.class, String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.annot(matrixAttribute().name("name"))
.arg(Map.class, String.class, String.class))).isFalse();
}
@Test
@@ -96,8 +93,8 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
(Map<String, String>) this.resolver.resolveArgument(
param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertNotNull(map);
assertEquals("red", map.get("colors"));
assertThat(map).isNotNull();
assertThat(map.get("colors")).isEqualTo("red");
param = this.testMethod
.annot(matrixAttribute().noPathVar())
@@ -108,7 +105,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
(MultiValueMap<String, String>) this.resolver.resolveArgument(
param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertEquals(Arrays.asList("red", "green", "blue"), multivalueMap.get("colors"));
assertThat(multivalueMap.get("colors")).isEqualTo(Arrays.asList("red", "green", "blue"));
}
@Test
@@ -125,11 +122,11 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
.arg(MultiValueMap.class, String.class, String.class);
@SuppressWarnings("unchecked")
Map<String, String> mapForPathVar = (Map<String, String>)
Map<String, ?> mapForPathVar = (Map<String, ?>)
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertNotNull(mapForPathVar);
assertEquals(Arrays.asList("red", "purple"), mapForPathVar.get("colors"));
assertThat(mapForPathVar).isNotNull();
assertThat(mapForPathVar.get("colors")).isEqualTo(Arrays.asList("red", "purple"));
param = this.testMethod.annot(matrixAttribute().noName()).arg(Map.class, String.class, String.class);
@@ -137,8 +134,8 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
Map<String, String> mapAll = (Map<String, String>)
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertNotNull(mapAll);
assertEquals("red", mapAll.get("colors"));
assertThat(mapAll).isNotNull();
assertThat(mapAll.get("colors")).isEqualTo("red");
}
@Test
@@ -151,7 +148,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
Map<String, String> map = (Map<String, String>)
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertEquals(Collections.emptyMap(), map);
assertThat(map).isEqualTo(Collections.emptyMap());
}
@Test
@@ -167,11 +164,10 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
Map<String, String> map = (Map<String, String>) this.resolver.resolveArgument(
param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertEquals(Collections.emptyMap(), map);
assertThat(map).isEqualTo(Collections.emptyMap());
}
@SuppressWarnings("unchecked")
private MultiValueMap<String, String> getMatrixVariables(String pathVarName) {
Map<String, MultiValueMap<String, String>> matrixVariables =
this.exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

View File

@@ -37,10 +37,8 @@ import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.ServerErrorException;
import org.springframework.web.server.ServerWebInputException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.springframework.web.method.MvcAnnotationPredicates.matrixAttribute;
/**
@@ -67,13 +65,13 @@ public class MatrixVariablesMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse();
assertTrue(this.resolver.supportsParameter(this.testMethod
.annot(matrixAttribute().noName()).arg(List.class, String.class)));
assertThat(this.resolver.supportsParameter(this.testMethod
.annot(matrixAttribute().noName()).arg(List.class, String.class))).isTrue();
assertTrue(this.resolver.supportsParameter(this.testMethod
.annot(matrixAttribute().name("year")).arg(int.class)));
assertThat(this.resolver.supportsParameter(this.testMethod
.annot(matrixAttribute().name("year")).arg(int.class))).isTrue();
}
@Test
@@ -84,8 +82,7 @@ public class MatrixVariablesMethodArgumentResolverTests {
params.add("colors", "blue");
MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class);
assertEquals(Arrays.asList("red", "green", "blue"),
this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO));
assertThat(this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO)).isEqualTo(Arrays.asList("red", "green", "blue"));
}
@Test
@@ -95,14 +92,14 @@ public class MatrixVariablesMethodArgumentResolverTests {
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertEquals(2006, actual);
assertThat(actual).isEqualTo(2006);
}
@Test
public void resolveArgumentDefaultValue() throws Exception {
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertEquals(2013, actual);
assertThat(actual).isEqualTo(2013);
}
@Test
@@ -129,10 +126,9 @@ public class MatrixVariablesMethodArgumentResolverTests {
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);
Object actual = this.resolver.resolveArgument(param, new BindingContext(), this.exchange).block(Duration.ZERO);
assertEquals(2013, actual);
assertThat(actual).isEqualTo(2013);
}
@SuppressWarnings("unchecked")
private MultiValueMap<String, String> getVariablesFor(String pathVarName) {
Map<String, MultiValueMap<String, String>> matrixVariables =
this.exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

View File

@@ -59,10 +59,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebInputException;
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.ResolvableType.forClassWithGenerics;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.post;
@@ -122,7 +119,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
Mono<Object> mono = resolveValue(param, body);
assertEquals(new TestBean("FOOFOO", "BARBAR"), mono.block());
assertThat(mono.block()).isEqualTo(new TestBean("FOOFOO", "BARBAR"));
}
@Test
@@ -132,8 +129,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
Flux<TestBean> flux = resolveValue(param, body);
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")),
flux.collectList().block());
assertThat(flux.collectList().block()).isEqualTo(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")));
}
@Test
@@ -143,7 +139,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
Single<TestBean> single = resolveValue(param, body);
assertEquals(new TestBean("f1", "b1"), single.toBlocking().value());
assertThat(single.toBlocking().value()).isEqualTo(new TestBean("f1", "b1"));
}
@Test
@@ -153,7 +149,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
io.reactivex.Single<TestBean> single = resolveValue(param, body);
assertEquals(new TestBean("f1", "b1"), single.blockingGet());
assertThat(single.blockingGet()).isEqualTo(new TestBean("f1", "b1"));
}
@Test
@@ -163,7 +159,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
Maybe<TestBean> maybe = resolveValue(param, body);
assertEquals(new TestBean("f1", "b1"), maybe.blockingGet());
assertThat(maybe.blockingGet()).isEqualTo(new TestBean("f1", "b1"));
}
@Test
@@ -173,8 +169,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
Observable<?> observable = resolveValue(param, body);
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")),
observable.toList().toBlocking().first());
assertThat(observable.toList().toBlocking().first()).isEqualTo(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")));
}
@Test
@@ -184,8 +179,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
io.reactivex.Observable<?> observable = resolveValue(param, body);
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")),
observable.toList().blockingGet());
assertThat(observable.toList().blockingGet()).isEqualTo(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")));
}
@Test
@@ -195,8 +189,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
Flowable<?> flowable = resolveValue(param, body);
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")),
flowable.toList().blockingGet());
assertThat(flowable.toList().blockingGet()).isEqualTo(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")));
}
@Test
@@ -206,7 +199,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
CompletableFuture<?> future = resolveValue(param, body);
assertEquals(new TestBean("f1", "b1"), future.get());
assertThat(future.get()).isEqualTo(new TestBean("f1", "b1"));
}
@Test
@@ -215,7 +208,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(TestBean.class);
TestBean value = resolveValue(param, body);
assertEquals(new TestBean("f1", "b1"), value);
assertThat(value).isEqualTo(new TestBean("f1", "b1"));
}
@Test
@@ -228,7 +221,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
Map<String, String> actual = resolveValue(param, body);
assertEquals(map, actual);
assertThat(actual).isEqualTo(map);
}
@Test
@@ -238,7 +231,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(type);
List<?> list = resolveValue(param, body);
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")), list);
assertThat(list).isEqualTo(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")));
}
@Test
@@ -249,7 +242,7 @@ public class MessageReaderArgumentResolverTests {
Mono<?> mono = resolveValue(param, body);
List<?> list = (List<?>) mono.block(Duration.ofSeconds(5));
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")), list);
assertThat(list).isEqualTo(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")));
}
@Test
@@ -258,11 +251,10 @@ public class MessageReaderArgumentResolverTests {
MethodParameter param = this.testMethod.arg(TestBean[].class);
TestBean[] value = resolveValue(param, body);
assertArrayEquals(new TestBean[] {new TestBean("f1", "b1"), new TestBean("f2", "b2")}, value);
assertThat(value).isEqualTo(new TestBean[] {new TestBean("f1", "b1"), new TestBean("f2", "b2")});
}
@Test
@SuppressWarnings("unchecked")
public void validateMonoTestBean() throws Exception {
String body = "{\"bar\":\"b1\"}";
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
@@ -273,7 +265,6 @@ public class MessageReaderArgumentResolverTests {
}
@Test
@SuppressWarnings("unchecked")
public void validateFluxTestBean() throws Exception {
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\"}]";
ResolvableType type = forClassWithGenerics(Flux.class, TestBean.class);
@@ -293,7 +284,7 @@ public class MessageReaderArgumentResolverTests {
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
SimpleBean simpleBean = resolveValue(methodParam, "{\"name\" : \"Jad\"}");
assertEquals("Jad", simpleBean.getName());
assertThat(simpleBean.getName()).isEqualTo("Jad");
}
@@ -304,9 +295,8 @@ public class MessageReaderArgumentResolverTests {
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
Object value = result.block(Duration.ofSeconds(5));
assertNotNull(value);
assertTrue("Unexpected return value type: " + value,
param.getParameterType().isAssignableFrom(value.getClass()));
assertThat(value).isNotNull();
assertThat(param.getParameterType().isAssignableFrom(value.getClass())).as("Unexpected return value type: " + value).isTrue();
return (T) value;
}

View File

@@ -53,8 +53,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.io.buffer.support.DataBufferTestUtils.dumpString;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.web.method.ResolvableMethod.on;
@@ -96,7 +95,7 @@ public class MessageWriterResultHandlerTests {
MethodParameter type = on(TestController.class).resolveReturnType(Resource.class);
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
assertEquals("image/png", this.exchange.getResponse().getHeaders().getFirst("Content-Type"));
assertThat(this.exchange.getResponse().getHeaders().getFirst("Content-Type")).isEqualTo("image/png");
}
@Test // SPR-13631
@@ -108,7 +107,7 @@ public class MessageWriterResultHandlerTests {
MethodParameter type = on(TestController.class).resolveReturnType(String.class);
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
assertEquals(MediaType.parseMediaType("application/json;charset=UTF-8"), this.exchange.getResponse().getHeaders().getContentType());
assertThat(this.exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.parseMediaType("application/json;charset=UTF-8"));
}
@Test
@@ -132,7 +131,7 @@ public class MessageWriterResultHandlerTests {
private void testVoid(Object body, MethodParameter returnType) {
this.resultHandler.writeBody(body, returnType, this.exchange).block(Duration.ofSeconds(5));
assertNull(this.exchange.getResponse().getHeaders().get("Content-Type"));
assertThat(this.exchange.getResponse().getHeaders().get("Content-Type")).isNull();
StepVerifier.create(this.exchange.getResponse().getBody())
.expectErrorMatches(ex -> ex.getMessage().startsWith("No content was written")).verify();
}
@@ -155,7 +154,7 @@ public class MessageWriterResultHandlerTests {
List<ParentClass> body = Arrays.asList(new Foo("foo"), new Bar("bar"));
this.resultHandler.writeBody(body, returnType, this.exchange).block(Duration.ofSeconds(5));
assertEquals(APPLICATION_JSON, this.exchange.getResponse().getHeaders().getContentType());
assertThat(this.exchange.getResponse().getHeaders().getContentType()).isEqualTo(APPLICATION_JSON);
assertResponseBody("[{\"type\":\"foo\",\"parentProperty\":\"foo\"}," +
"{\"type\":\"bar\",\"parentProperty\":\"bar\"}]");
}
@@ -166,7 +165,7 @@ public class MessageWriterResultHandlerTests {
MethodParameter type = on(TestController.class).resolveReturnType(Identifiable.class);
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
assertEquals(APPLICATION_JSON, this.exchange.getResponse().getHeaders().getContentType());
assertThat(this.exchange.getResponse().getHeaders().getContentType()).isEqualTo(APPLICATION_JSON);
assertResponseBody("{\"id\":123,\"name\":\"foo\"}");
}
@@ -178,14 +177,14 @@ public class MessageWriterResultHandlerTests {
List<SimpleBean> body = Arrays.asList(new SimpleBean(123L, "foo"), new SimpleBean(456L, "bar"));
this.resultHandler.writeBody(body, returnType, this.exchange).block(Duration.ofSeconds(5));
assertEquals(APPLICATION_JSON, this.exchange.getResponse().getHeaders().getContentType());
assertThat(this.exchange.getResponse().getHeaders().getContentType()).isEqualTo(APPLICATION_JSON);
assertResponseBody("[{\"id\":123,\"name\":\"foo\"},{\"id\":456,\"name\":\"bar\"}]");
}
private void assertResponseBody(String responseBody) {
StepVerifier.create(this.exchange.getResponse().getBody())
.consumeNextWith(buf -> assertEquals(responseBody, dumpString(buf, StandardCharsets.UTF_8)))
.consumeNextWith(buf -> assertThat(dumpString(buf, StandardCharsets.UTF_8)).isEqualTo(responseBody))
.expectComplete()
.verify();
}

View File

@@ -43,11 +43,7 @@ import org.springframework.web.method.ResolvableMethod;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link ModelAttributeMethodArgumentResolver}.
@@ -78,16 +74,16 @@ public class ModelAttributeMethodArgumentResolverTests {
new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), false);
MethodParameter param = this.testMethod.annotPresent(ModelAttribute.class).arg(Foo.class);
assertTrue(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isTrue();
param = this.testMethod.annotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertTrue(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isTrue();
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
assertFalse(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isFalse();
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertFalse(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isFalse();
}
@Test
@@ -96,22 +92,22 @@ public class ModelAttributeMethodArgumentResolverTests {
new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), true);
MethodParameter param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
assertTrue(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isTrue();
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertTrue(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isTrue();
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(String.class);
assertFalse(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isFalse();
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, String.class);
assertFalse(resolver.supportsParameter(param));
assertThat(resolver.supportsParameter(param)).isFalse();
}
@Test
public void createAndBind() throws Exception {
testBindFoo("foo", this.testMethod.annotPresent(ModelAttribute.class).arg(Foo.class), value -> {
assertEquals(Foo.class, value.getClass());
assertThat(value.getClass()).isEqualTo(Foo.class);
return (Foo) value;
});
}
@@ -122,9 +118,10 @@ public class ModelAttributeMethodArgumentResolverTests {
.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
testBindFoo("fooMono", parameter, mono -> {
assertTrue(mono.getClass().getName(), mono instanceof Mono);
boolean condition = mono instanceof Mono;
assertThat(condition).as(mono.getClass().getName()).isTrue();
Object value = ((Mono<?>) mono).block(Duration.ofSeconds(5));
assertEquals(Foo.class, value.getClass());
assertThat(value.getClass()).isEqualTo(Foo.class);
return (Foo) value;
});
}
@@ -135,9 +132,10 @@ public class ModelAttributeMethodArgumentResolverTests {
.annotPresent(ModelAttribute.class).arg(Single.class, Foo.class);
testBindFoo("fooSingle", parameter, single -> {
assertTrue(single.getClass().getName(), single instanceof Single);
boolean condition = single instanceof Single;
assertThat(condition).as(single.getClass().getName()).isTrue();
Object value = ((Single<?>) single).toBlocking().value();
assertEquals(Foo.class, value.getClass());
assertThat(value.getClass()).isEqualTo(Foo.class);
return (Foo) value;
});
}
@@ -150,11 +148,11 @@ public class ModelAttributeMethodArgumentResolverTests {
MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
testBindFoo("foo", parameter, value -> {
assertEquals(Foo.class, value.getClass());
assertThat(value.getClass()).isEqualTo(Foo.class);
return (Foo) value;
});
assertSame(foo, this.bindContext.getModel().asMap().get("foo"));
assertThat(this.bindContext.getModel().asMap().get("foo")).isSameAs(foo);
}
@Test
@@ -165,11 +163,11 @@ public class ModelAttributeMethodArgumentResolverTests {
MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
testBindFoo("foo", parameter, value -> {
assertEquals(Foo.class, value.getClass());
assertThat(value.getClass()).isEqualTo(Foo.class);
return (Foo) value;
});
assertSame(foo, this.bindContext.getModel().asMap().get("foo"));
assertThat(this.bindContext.getModel().asMap().get("foo")).isSameAs(foo);
}
@Test
@@ -180,11 +178,11 @@ public class ModelAttributeMethodArgumentResolverTests {
MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
testBindFoo("foo", parameter, value -> {
assertEquals(Foo.class, value.getClass());
assertThat(value.getClass()).isEqualTo(Foo.class);
return (Foo) value;
});
assertSame(foo, this.bindContext.getModel().asMap().get("foo"));
assertThat(this.bindContext.getModel().asMap().get("foo")).isSameAs(foo);
}
@Test
@@ -198,9 +196,10 @@ public class ModelAttributeMethodArgumentResolverTests {
.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
testBindFoo(modelKey, parameter, mono -> {
assertTrue(mono.getClass().getName(), mono instanceof Mono);
boolean condition = mono instanceof Mono;
assertThat(condition).as(mono.getClass().getName()).isTrue();
Object value = ((Mono<?>) mono).block(Duration.ofSeconds(5));
assertEquals(Foo.class, value.getClass());
assertThat(value.getClass()).isEqualTo(Foo.class);
return (Foo) value;
});
}
@@ -213,16 +212,17 @@ public class ModelAttributeMethodArgumentResolverTests {
.block(Duration.ZERO);
Foo foo = valueExtractor.apply(value);
assertEquals("Robert", foo.getName());
assertEquals(25, foo.getAge());
assertThat(foo.getName()).isEqualTo("Robert");
assertThat(foo.getAge()).isEqualTo(25);
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + modelKey;
Map<String, Object> map = bindContext.getModel().asMap();
assertEquals(map.toString(), 2, map.size());
assertSame(foo, map.get(modelKey));
assertNotNull(map.get(bindingResultKey));
assertTrue(map.get(bindingResultKey) instanceof BindingResult);
assertThat(map.size()).as(map.toString()).isEqualTo(2);
assertThat(map.get(modelKey)).isSameAs(foo);
assertThat(map.get(bindingResultKey)).isNotNull();
boolean condition = map.get(bindingResultKey) instanceof BindingResult;
assertThat(condition).isTrue();
}
@Test
@@ -232,7 +232,6 @@ public class ModelAttributeMethodArgumentResolverTests {
}
@Test
@SuppressWarnings("unchecked")
public void validationErrorToMono() throws Exception {
MethodParameter parameter = this.testMethod
.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
@@ -240,8 +239,9 @@ public class ModelAttributeMethodArgumentResolverTests {
testValidationError(parameter,
resolvedArgumentMono -> {
Object value = resolvedArgumentMono.block(Duration.ofSeconds(5));
assertNotNull(value);
assertTrue(value instanceof Mono);
assertThat(value).isNotNull();
boolean condition = value instanceof Mono;
assertThat(condition).isTrue();
return (Mono<?>) value;
});
}
@@ -254,8 +254,9 @@ public class ModelAttributeMethodArgumentResolverTests {
testValidationError(parameter,
resolvedArgumentMono -> {
Object value = resolvedArgumentMono.block(Duration.ofSeconds(5));
assertNotNull(value);
assertTrue(value instanceof Single);
assertThat(value).isNotNull();
boolean condition = value instanceof Single;
assertThat(condition).isTrue();
return Mono.from(RxReactiveStreams.toPublisher((Single<?>) value));
});
}
@@ -269,10 +270,11 @@ public class ModelAttributeMethodArgumentResolverTests {
StepVerifier.create(mono)
.consumeErrorWith(ex -> {
assertTrue(ex instanceof WebExchangeBindException);
boolean condition = ex instanceof WebExchangeBindException;
assertThat(condition).isTrue();
WebExchangeBindException bindException = (WebExchangeBindException) ex;
assertEquals(1, bindException.getErrorCount());
assertTrue(bindException.hasFieldErrors("age"));
assertThat(bindException.getErrorCount()).isEqualTo(1);
assertThat(bindException.hasFieldErrors("age")).isTrue();
})
.verify();
}
@@ -288,18 +290,19 @@ public class ModelAttributeMethodArgumentResolverTests {
.block(Duration.ZERO);
Bar bar = (Bar) value;
assertEquals("Robert", bar.getName());
assertEquals(25, bar.getAge());
assertEquals(1, bar.getCount());
assertThat(bar.getName()).isEqualTo("Robert");
assertThat(bar.getAge()).isEqualTo(25);
assertThat(bar.getCount()).isEqualTo(1);
String key = "bar";
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + key;
Map<String, Object> map = bindContext.getModel().asMap();
assertEquals(map.toString(), 2, map.size());
assertSame(bar, map.get(key));
assertNotNull(map.get(bindingResultKey));
assertTrue(map.get(bindingResultKey) instanceof BindingResult);
assertThat(map.size()).as(map.toString()).isEqualTo(2);
assertThat(map.get(key)).isSameAs(bar);
assertThat(map.get(bindingResultKey)).isNotNull();
boolean condition = map.get(bindingResultKey) instanceof BindingResult;
assertThat(condition).isTrue();
}
// TODO: SPR-15871, SPR-15542

View File

@@ -53,9 +53,8 @@ import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
/**
@@ -97,7 +96,7 @@ public class ModelInitializerTests {
this.modelInitializer.initModel(handlerMethod, context, this.exchange).block(Duration.ofMillis(5000));
WebExchangeDataBinder binder = context.createDataBinder(this.exchange, "name");
assertEquals(Collections.singletonList(validator), binder.getValidators());
assertThat(binder.getValidators()).isEqualTo(Collections.singletonList(validator));
}
@SuppressWarnings("unchecked")
@@ -111,22 +110,22 @@ public class ModelInitializerTests {
this.modelInitializer.initModel(handlerMethod, context, this.exchange).block(Duration.ofMillis(5000));
Map<String, Object> model = context.getModel().asMap();
assertEquals(5, model.size());
assertThat(model.size()).isEqualTo(5);
Object value = model.get("bean");
assertEquals("Bean", ((TestBean) value).getName());
assertThat(((TestBean) value).getName()).isEqualTo("Bean");
value = model.get("monoBean");
assertEquals("Mono Bean", ((Mono<TestBean>) value).block(Duration.ofMillis(5000)).getName());
assertThat(((Mono<TestBean>) value).block(Duration.ofMillis(5000)).getName()).isEqualTo("Mono Bean");
value = model.get("singleBean");
assertEquals("Single Bean", ((Single<TestBean>) value).toBlocking().value().getName());
assertThat(((Single<TestBean>) value).toBlocking().value().getName()).isEqualTo("Single Bean");
value = model.get("voidMethodBean");
assertEquals("Void Method Bean", ((TestBean) value).getName());
assertThat(((TestBean) value).getName()).isEqualTo("Void Method Bean");
value = model.get("voidMonoMethodBean");
assertEquals("Void Mono Method Bean", ((TestBean) value).getName());
assertThat(((TestBean) value).getName()).isEqualTo("Void Mono Method Bean");
}
@Test
@@ -139,18 +138,18 @@ public class ModelInitializerTests {
this.modelInitializer.initModel(handlerMethod, context, this.exchange).block(Duration.ofMillis(5000));
WebSession session = this.exchange.getSession().block(Duration.ZERO);
assertNotNull(session);
assertEquals(0, session.getAttributes().size());
assertThat(session).isNotNull();
assertThat(session.getAttributes().size()).isEqualTo(0);
context.saveModel();
assertEquals(1, session.getAttributes().size());
assertEquals("Bean", ((TestBean) session.getRequiredAttribute("bean")).getName());
assertThat(session.getAttributes().size()).isEqualTo(1);
assertThat(((TestBean) session.getRequiredAttribute("bean")).getName()).isEqualTo("Bean");
}
@Test
public void retrieveModelAttributeFromSession() {
WebSession session = this.exchange.getSession().block(Duration.ZERO);
assertNotNull(session);
assertThat(session).isNotNull();
TestBean testBean = new TestBean("Session Bean");
session.getAttributes().put("bean", testBean);
@@ -163,8 +162,8 @@ public class ModelInitializerTests {
this.modelInitializer.initModel(handlerMethod, context, this.exchange).block(Duration.ofMillis(5000));
context.saveModel();
assertEquals(1, session.getAttributes().size());
assertEquals("Session Bean", ((TestBean) session.getRequiredAttribute("bean")).getName());
assertThat(session.getAttributes().size()).isEqualTo(1);
assertThat(((TestBean) session.getRequiredAttribute("bean")).getName()).isEqualTo("Session Bean");
}
@Test
@@ -182,7 +181,7 @@ public class ModelInitializerTests {
@Test
public void clearModelAttributeFromSession() {
WebSession session = this.exchange.getSession().block(Duration.ZERO);
assertNotNull(session);
assertThat(session).isNotNull();
TestBean testBean = new TestBean("Session Bean");
session.getAttributes().put("bean", testBean);
@@ -197,7 +196,7 @@ public class ModelInitializerTests {
context.getSessionStatus().setComplete();
context.saveModel();
assertEquals(0, session.getAttributes().size());
assertThat(session.getAttributes().size()).isEqualTo(0);
}

View File

@@ -31,9 +31,7 @@ import org.springframework.web.method.ResolvableMethod;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
/**
@@ -53,14 +51,14 @@ public class ModelMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertTrue(this.resolver.supportsParameter(this.resolvable.arg(Model.class)));
assertTrue(this.resolver.supportsParameter(this.resolvable.arg(ModelMap.class)));
assertTrue(this.resolver.supportsParameter(
this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class)));
assertThat(this.resolver.supportsParameter(this.resolvable.arg(Model.class))).isTrue();
assertThat(this.resolver.supportsParameter(this.resolvable.arg(ModelMap.class))).isTrue();
assertThat(this.resolver.supportsParameter(
this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class))).isTrue();
assertFalse(this.resolver.supportsParameter(this.resolvable.arg(Object.class)));
assertFalse(this.resolver.supportsParameter(
this.resolvable.annotPresent(RequestBody.class).arg(Map.class, String.class, Object.class)));
assertThat(this.resolver.supportsParameter(this.resolvable.arg(Object.class))).isFalse();
assertThat(this.resolver.supportsParameter(
this.resolvable.annotPresent(RequestBody.class).arg(Map.class, String.class, Object.class))).isFalse();
}
@Test
@@ -73,7 +71,7 @@ public class ModelMethodArgumentResolverTests {
private void testResolveArgument(MethodParameter parameter) {
BindingContext context = new BindingContext();
Object result = this.resolver.resolveArgument(parameter, context, this.exchange).block(Duration.ZERO);
assertSame(context.getModel(), result);
assertThat(result).isSameAs(context.getModel());
}

View File

@@ -52,7 +52,7 @@ import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
@@ -85,7 +85,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
StepVerifier
.create(result)
.consumeNextWith(response -> assertEquals(HttpStatus.OK, response.statusCode()))
.consumeNextWith(response -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK))
.verifyComplete();
}
@@ -99,8 +99,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.bodyToMono(String.class);
StepVerifier.create(result)
.consumeNextWith(body -> assertEquals(
"Map[[fieldPart],[fileParts:foo.txt,fileParts:logo.png],[jsonPart]]", body))
.consumeNextWith(body -> assertThat(body).isEqualTo("Map[[fieldPart],[fileParts:foo.txt,fileParts:logo.png],[jsonPart]]"))
.verifyComplete();
}
@@ -114,8 +113,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.bodyToMono(String.class);
StepVerifier.create(result)
.consumeNextWith(body -> assertEquals(
"[fieldPart,fileParts:foo.txt,fileParts:logo.png,jsonPart]", body))
.consumeNextWith(body -> assertThat(body).isEqualTo("[fieldPart,fileParts:foo.txt,fileParts:logo.png,jsonPart]"))
.verifyComplete();
}
@@ -129,8 +127,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.bodyToMono(String.class);
StepVerifier.create(result)
.consumeNextWith(body -> assertEquals(
"[fileParts:foo.txt,fileParts:logo.png]", body))
.consumeNextWith(body -> assertThat(body).isEqualTo("[fileParts:foo.txt,fileParts:logo.png]"))
.verifyComplete();
}
@@ -144,8 +141,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.bodyToMono(String.class);
StepVerifier.create(result)
.consumeNextWith(body -> assertEquals(
"[fileParts:foo.txt]", body))
.consumeNextWith(body -> assertThat(body).isEqualTo("[fileParts:foo.txt]"))
.verifyComplete();
}
@@ -159,8 +155,7 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.bodyToMono(String.class);
StepVerifier.create(result)
.consumeNextWith(body -> assertEquals(
"FormBean[fieldValue,[fileParts:foo.txt,fileParts:logo.png]]", body))
.consumeNextWith(body -> assertThat(body).isEqualTo("FormBean[fieldValue,[fileParts:foo.txt,fileParts:logo.png]]"))
.verifyComplete();
}
@@ -194,11 +189,11 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
@RequestPart("fileParts") FilePart fileParts,
@RequestPart("jsonPart") Mono<Person> personMono) {
assertEquals("fieldValue", fieldPart.value());
assertEquals("fileParts:foo.txt", partDescription(fileParts));
assertThat(fieldPart.value()).isEqualTo("fieldValue");
assertThat(partDescription(fileParts)).isEqualTo("fileParts:foo.txt");
StepVerifier.create(personMono)
.consumeNextWith(p -> assertEquals("Jason", p.getName()))
.consumeNextWith(p -> assertThat(p.getName()).isEqualTo("Jason"))
.verifyComplete();
}

View File

@@ -34,10 +34,8 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.HandlerMapping;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link PathVariableMapMethodArgumentResolver}.
@@ -70,9 +68,9 @@ public class PathVariableMapMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertTrue(resolver.supportsParameter(paramMap));
assertFalse(resolver.supportsParameter(paramNamedMap));
assertFalse(resolver.supportsParameter(paramMapNoAnnot));
assertThat(resolver.supportsParameter(paramMap)).isTrue();
assertThat(resolver.supportsParameter(paramNamedMap)).isFalse();
assertThat(resolver.supportsParameter(paramMapNoAnnot)).isFalse();
assertThatIllegalStateException().isThrownBy(() ->
this.resolver.supportsParameter(this.paramMonoMap))
.withMessageStartingWith("PathVariableMapMethodArgumentResolver does not support reactive type wrapper");
@@ -88,7 +86,7 @@ public class PathVariableMapMethodArgumentResolverTests {
Mono<Object> mono = this.resolver.resolveArgument(this.paramMap, new BindingContext(), this.exchange);
Object result = mono.block();
assertEquals(uriTemplateVars, result);
assertThat(result).isEqualTo(uriTemplateVars);
}
@Test
@@ -96,7 +94,7 @@ public class PathVariableMapMethodArgumentResolverTests {
Mono<Object> mono = this.resolver.resolveArgument(this.paramMap, new BindingContext(), this.exchange);
Object result = mono.block();
assertEquals(Collections.emptyMap(), result);
assertThat(result).isEqualTo(Collections.emptyMap());
}

View File

@@ -39,10 +39,8 @@ import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.ServerErrorException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link PathVariableMethodArgumentResolver}.
@@ -78,8 +76,8 @@ public class PathVariableMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertTrue(this.resolver.supportsParameter(this.paramNamedString));
assertFalse(this.resolver.supportsParameter(this.paramString));
assertThat(this.resolver.supportsParameter(this.paramNamedString)).isTrue();
assertThat(this.resolver.supportsParameter(this.paramString)).isFalse();
assertThatIllegalStateException().isThrownBy(() ->
this.resolver.supportsParameter(this.paramMono))
.withMessageStartingWith("PathVariableMethodArgumentResolver does not support reactive type wrapper");
@@ -94,7 +92,7 @@ public class PathVariableMethodArgumentResolverTests {
BindingContext bindingContext = new BindingContext();
Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange);
Object result = mono.block();
assertEquals("value", result);
assertThat(result).isEqualTo("value");
}
@Test
@@ -106,7 +104,7 @@ public class PathVariableMethodArgumentResolverTests {
BindingContext bindingContext = new BindingContext();
Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange);
Object result = mono.block();
assertEquals("value", result);
assertThat(result).isEqualTo("value");
}
@Test
@@ -121,7 +119,7 @@ public class PathVariableMethodArgumentResolverTests {
Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
Object result = mono.block();
assertEquals(Optional.of("value"), result);
assertThat(result).isEqualTo(Optional.of("value"));
}
@Test
@@ -151,8 +149,9 @@ public class PathVariableMethodArgumentResolverTests {
StepVerifier.create(mono)
.consumeNextWith(value -> {
assertTrue(value instanceof Optional);
assertFalse(((Optional<?>) value).isPresent());
boolean condition = value instanceof Optional;
assertThat(condition).isTrue();
assertThat(((Optional<?>) value).isPresent()).isFalse();
})
.expectComplete()
.verify();

View File

@@ -30,8 +30,7 @@ import org.springframework.web.method.ResolvableMethod;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link PrincipalMethodArgumentResolver}.
@@ -48,9 +47,9 @@ public class PrincipalMethodArgumentResolverTests {
@Test
public void supportsParameter() {
assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Principal.class)));
assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, Principal.class)));
assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Single.class, Principal.class)));
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Principal.class))).isTrue();
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Mono.class, Principal.class))).isTrue();
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Single.class, Principal.class))).isTrue();
}
@@ -63,17 +62,17 @@ public class PrincipalMethodArgumentResolverTests {
MethodParameter param = this.testMethod.arg(Principal.class);
Object actual = this.resolver.resolveArgument(param, context, exchange).block();
assertSame(user, actual);
assertThat(actual).isSameAs(user);
param = this.testMethod.arg(Mono.class, Principal.class);
actual = this.resolver.resolveArgument(param, context, exchange).block();
assertTrue(Mono.class.isAssignableFrom(actual.getClass()));
assertSame(user, ((Mono<?>) actual).block());
assertThat(Mono.class.isAssignableFrom(actual.getClass())).isTrue();
assertThat(((Mono<?>) actual).block()).isSameAs(user);
param = this.testMethod.arg(Single.class, Principal.class);
actual = this.resolver.resolveArgument(param, context, exchange).block();
assertTrue(Single.class.isAssignableFrom(actual.getClass()));
assertSame(user, ((Single<?>) actual).blockingGet());
assertThat(Single.class.isAssignableFrom(actual.getClass())).isTrue();
assertThat(((Single<?>) actual).blockingGet()).isSameAs(user);
}

View File

@@ -35,8 +35,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.protobuf.Msg;
import org.springframework.web.reactive.protobuf.SecondMsg;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for Protobuf support.
@@ -73,9 +72,9 @@ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationT
.uri("/message")
.exchange()
.doOnNext(response -> {
assertFalse(response.headers().contentType().get().getParameters().containsKey("delimited"));
assertEquals("sample.proto", response.headers().header("X-Protobuf-Schema").get(0));
assertEquals("Msg", response.headers().header("X-Protobuf-Message").get(0));
assertThat(response.headers().contentType().get().getParameters().containsKey("delimited")).isFalse();
assertThat(response.headers().header("X-Protobuf-Schema").get(0)).isEqualTo("sample.proto");
assertThat(response.headers().header("X-Protobuf-Message").get(0)).isEqualTo("Msg");
})
.flatMap(response -> response.bodyToMono(Msg.class));
@@ -90,9 +89,9 @@ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationT
.uri("/messages")
.exchange()
.doOnNext(response -> {
assertEquals("true", response.headers().contentType().get().getParameters().get("delimited"));
assertEquals("sample.proto", response.headers().header("X-Protobuf-Schema").get(0));
assertEquals("Msg", response.headers().header("X-Protobuf-Message").get(0));
assertThat(response.headers().contentType().get().getParameters().get("delimited")).isEqualTo("true");
assertThat(response.headers().header("X-Protobuf-Schema").get(0)).isEqualTo("sample.proto");
assertThat(response.headers().header("X-Protobuf-Message").get(0)).isEqualTo("Msg");
})
.flatMapMany(response -> response.bodyToFlux(Msg.class));
@@ -109,9 +108,9 @@ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationT
.uri("/message-stream")
.exchange()
.doOnNext(response -> {
assertEquals("true", response.headers().contentType().get().getParameters().get("delimited"));
assertEquals("sample.proto", response.headers().header("X-Protobuf-Schema").get(0));
assertEquals("Msg", response.headers().header("X-Protobuf-Message").get(0));
assertThat(response.headers().contentType().get().getParameters().get("delimited")).isEqualTo("true");
assertThat(response.headers().header("X-Protobuf-Schema").get(0)).isEqualTo("sample.proto");
assertThat(response.headers().header("X-Protobuf-Message").get(0)).isEqualTo("Msg");
})
.flatMapMany(response -> response.bodyToFlux(Msg.class));

Some files were not shown because too many files have changed in this diff Show More