Refactor AssertJ assertions into more idiomatic ones

This commit refactors some AssertJ assertions into more idiomatic and
readable ones. Using the dedicated assertion instead of a generic one
will produce more meaningful error messages. 

For instance, consider collection size:
```
// expected: 5 but was: 2
assertThat(collection.size()).equals(5);
// Expected size: 5 but was: 2 in: [1, 2]
assertThat(collection).hasSize(5);
```

Closes gh-30104
This commit is contained in:
Krzysztof Krasoń
2023-04-04 17:34:07 +02:00
committed by GitHub
parent dd97ee4e99
commit 1734deca1e
371 changed files with 3177 additions and 3076 deletions

View File

@@ -21,7 +21,6 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import org.junit.jupiter.api.BeforeEach;
@@ -101,7 +100,7 @@ class DefaultClientResponseTests {
ClientResponse.Headers headers = defaultClientResponse.headers();
assertThat(headers.contentLength()).isEqualTo(OptionalLong.of(contentLength));
assertThat(headers.contentType()).isEqualTo(Optional.of(contentType));
assertThat(headers.contentType()).contains(contentType);
assertThat(headers.asHttpHeaders()).isEqualTo(httpHeaders);
}

View File

@@ -110,7 +110,7 @@ public class DefaultWebClientTests {
ClientRequest request = verifyAndGetRequest();
assertThat(request.url().toString()).isEqualTo("/base/path/identifier?q=12");
assertThat(request.attribute(WebClient.class.getName() + ".uriTemplate").get()).isEqualTo("/path/{id}");
assertThat(request.attribute(WebClient.class.getName() + ".uriTemplate")).contains("/path/{id}");
}
@Test
@@ -341,7 +341,7 @@ public class DefaultWebClientTests {
assertThat(actual.get("foo")).isEqualTo("bar");
ClientRequest request = verifyAndGetRequest();
assertThat(request.attribute("foo").get()).isEqualTo("bar");
assertThat(request.attribute("foo")).contains("bar");
}
@Test
@@ -360,7 +360,7 @@ public class DefaultWebClientTests {
assertThat(actual.get("foo")).isNull();
ClientRequest request = verifyAndGetRequest();
assertThat(request.attribute("foo").isPresent()).isFalse();
assertThat(request.attribute("foo")).isNotPresent();
}
@Test

View File

@@ -105,7 +105,7 @@ public class ExchangeFilterFunctionsTests {
ExchangeFunction exchange = r -> {
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isTrue();
assertThat(r.headers().getFirst(HttpHeaders.AUTHORIZATION).startsWith("Basic ")).isTrue();
assertThat(r.headers().getFirst(HttpHeaders.AUTHORIZATION)).startsWith("Basic ");
return Mono.just(response);
};
@@ -135,7 +135,7 @@ public class ExchangeFilterFunctionsTests {
ExchangeFunction exchange = r -> {
assertThat(r.headers().containsKey(HttpHeaders.AUTHORIZATION)).isTrue();
assertThat(r.headers().getFirst(HttpHeaders.AUTHORIZATION).startsWith("Basic ")).isTrue();
assertThat(r.headers().getFirst(HttpHeaders.AUTHORIZATION)).startsWith("Basic ");
return Mono.just(response);
};

View File

@@ -660,7 +660,7 @@ class WebClientIntegrationTests {
UnknownHttpStatusCodeException ex = (UnknownHttpStatusCodeException) throwable;
assertThat(ex.getMessage()).isEqualTo(("Unknown status code ["+errorStatus+"]"));
assertThat(ex.getRawStatusCode()).isEqualTo(errorStatus);
assertThat(ex.getStatusText()).isEqualTo("");
assertThat(ex.getStatusText()).isEmpty();
assertThat(ex.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage);
})

View File

@@ -32,7 +32,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.function.Consumer;
@@ -131,7 +130,7 @@ public class DefaultServerRequestTests {
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
assertThat(request.attribute("foo")).isEqualTo(Optional.of("bar"));
assertThat(request.attribute("foo")).contains("bar");
}
@Test
@@ -140,7 +139,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo=bar")),
this.messageReaders);
assertThat(request.queryParam("foo")).isEqualTo(Optional.of("bar"));
assertThat(request.queryParam("foo")).contains("bar");
}
@Test
@@ -149,7 +148,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
this.messageReaders);
assertThat(request.queryParam("foo")).isEqualTo(Optional.of(""));
assertThat(request.queryParam("foo")).contains("");
}
@Test
@@ -158,7 +157,7 @@ public class DefaultServerRequestTests {
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo")),
this.messageReaders);
assertThat(request.queryParam("bar")).isEqualTo(Optional.empty());
assertThat(request.queryParam("bar")).isNotPresent();
}
@Test
@@ -223,7 +222,7 @@ public class DefaultServerRequestTests {
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.contentType()).contains(contentType);
assertThat(headers.header(HttpHeaders.CONTENT_TYPE)).containsExactly(MediaType.TEXT_PLAIN_VALUE);
assertThat(headers.firstHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.TEXT_PLAIN_VALUE);
assertThat(headers.asHttpHeaders()).isEqualTo(httpHeaders);

View File

@@ -92,7 +92,7 @@ class ServerRequestWrapperTests {
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).isEqualTo(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
@@ -101,7 +101,7 @@ class ServerRequestWrapperTests {
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).isEqualTo(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ public class PathResourceResolverTests {
Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT);
assertThat(actual).isNotNull();
assertThat(actual.getFile().getName()).isEqualTo("foo foo.txt");
assertThat(actual.getFile()).hasName("foo foo.txt");
}
@Test

View File

@@ -440,7 +440,7 @@ class ResourceWebHandlerTests {
assertThat(this.handler.processPath((char) 1 + " / " + (char) 127 + " // foo/bar")).isEqualTo("/foo/bar");
// root or empty path
assertThat(this.handler.processPath(" ")).isEqualTo("");
assertThat(this.handler.processPath(" ")).isEmpty();
assertThat(this.handler.processPath("/")).isEqualTo("/");
assertThat(this.handler.processPath("///")).isEqualTo("/");
assertThat(this.handler.processPath("/ / / ")).isEqualTo("/");
@@ -677,8 +677,8 @@ class ResourceWebHandlerTests {
this.handler.handle(exchange).block(TIMEOUT);
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType().toString()
.startsWith("multipart/byteranges;boundary=")).isTrue();
assertThat(exchange.getResponse().getHeaders().getContentType().toString()).startsWith(
"multipart/byteranges;boundary=");
String boundary = "--" + exchange.getResponse().getHeaders().getContentType().toString().substring(30);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -146,10 +146,10 @@ public class ConsumesRequestConditionTests {
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
}
@Test
@@ -160,10 +160,10 @@ public class ConsumesRequestConditionTests {
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*", "text/plain;q=0.7");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
}
@@ -209,7 +209,7 @@ public class ConsumesRequestConditionTests {
private void assertConditions(ConsumesRequestCondition condition, String... expected) {
Collection<ConsumeMediaTypeExpression> expressions = condition.getContent();
assertThat(expected.length).as("Invalid amount of conditions").isEqualTo(expressions.size());
assertThat(expected).as("Invalid amount of conditions").hasSameSizeAs(expressions);
for (String s : expected) {
boolean found = false;
for (ConsumeMediaTypeExpression expr : expressions) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -114,10 +114,10 @@ public class HeadersRequestConditionTests {
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo=a", "bar");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
}
@Test // SPR-16674
@@ -128,7 +128,7 @@ public class HeadersRequestConditionTests {
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,10 +85,10 @@ public class ParamsRequestConditionTests {
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo", "bar");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
}
@Test // SPR-16674
@@ -99,7 +99,7 @@ public class ParamsRequestConditionTests {
ParamsRequestCondition condition2 = new ParamsRequestCondition("response_type");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
}
@Test

View File

@@ -42,8 +42,7 @@ public class PatternsRequestConditionTests {
public void prependNonEmptyPatternsOnly() {
PatternsRequestCondition c = createPatternsCondition("");
assertThat(c.getPatterns().iterator().next().getPatternString())
.as("Do not prepend empty patterns (SPR-8255)")
.isEqualTo("");
.as("Do not prepend empty patterns (SPR-8255)").isEmpty();
}
@Test

View File

@@ -157,18 +157,18 @@ public class ProducesRequestConditionTests {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/")
.header("Accept", "application/xml, text/html"));
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();
assertThat(html.compareTo(xml, exchange)).isGreaterThan(0);
assertThat(xml.compareTo(html, exchange)).isLessThan(0);
assertThat(xml.compareTo(none, exchange)).isLessThan(0);
assertThat(none.compareTo(xml, exchange)).isGreaterThan(0);
assertThat(html.compareTo(none, exchange)).isLessThan(0);
assertThat(none.compareTo(html, exchange)).isGreaterThan(0);
exchange = MockServerWebExchange.from(
get("/").header("Accept", "application/xml, text/*"));
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
assertThat(html.compareTo(xml, exchange)).isGreaterThan(0);
assertThat(xml.compareTo(html, exchange)).isLessThan(0);
exchange = MockServerWebExchange.from(
get("/").header("Accept", "application/pdf"));
@@ -180,8 +180,8 @@ public class ProducesRequestConditionTests {
exchange = MockServerWebExchange.from(
get("/").header("Accept", "text/html;q=0.9,application/xml"));
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
assertThat(html.compareTo(xml, exchange)).isGreaterThan(0);
assertThat(xml.compareTo(html, exchange)).isLessThan(0);
}
@Test
@@ -192,10 +192,10 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
}
@Test
@@ -221,19 +221,19 @@ public class ProducesRequestConditionTests {
get("/").header("Accept", "text/plain", "application/xml"));
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
exchange = MockServerWebExchange.from(
get("/").header("Accept", "application/xml", "text/plain"));
result = condition1.compareTo(condition2, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
}
// SPR-8536
@@ -245,14 +245,16 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition1 = new ProducesRequestCondition();
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
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();
assertThat(condition1.compareTo(condition2, exchange)).as("Should have picked '*/*' condition as an exact match")
.isLessThan(0);
assertThat(condition2.compareTo(condition1, exchange)).as("Should have picked '*/*' condition as an exact match")
.isGreaterThan(0);
condition1 = new ProducesRequestCondition("*/*");
condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
assertThat(condition1.compareTo(condition2, exchange)).isLessThan(0);
assertThat(condition2.compareTo(condition1, exchange)).isGreaterThan(0);
exchange = MockServerWebExchange.from(
get("/").header("Accept", "*/*"));
@@ -260,14 +262,14 @@ public class ProducesRequestConditionTests {
condition1 = new ProducesRequestCondition();
condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
assertThat(condition1.compareTo(condition2, exchange)).isLessThan(0);
assertThat(condition2.compareTo(condition1, exchange)).isGreaterThan(0);
condition1 = new ProducesRequestCondition("*/*");
condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
assertThat(condition1.compareTo(condition2, exchange)).isLessThan(0);
assertThat(condition2.compareTo(condition1, exchange)).isGreaterThan(0);
}
// SPR-9021
@@ -279,8 +281,8 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition1 = new ProducesRequestCondition();
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
assertThat(condition1.compareTo(condition2, exchange)).isLessThan(0);
assertThat(condition2.compareTo(condition1, exchange)).isGreaterThan(0);
}
@Test
@@ -291,10 +293,10 @@ public class ProducesRequestConditionTests {
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/xhtml");
int result = condition1.compareTo(condition2, exchange);
assertThat(result < 0).as("Should have used MediaType.equals(Object) to break the match").isTrue();
assertThat(result).as("Should have used MediaType.equals(Object) to break the match").isLessThan(0);
result = condition2.compareTo(condition1, exchange);
assertThat(result > 0).as("Should have used MediaType.equals(Object) to break the match").isTrue();
assertThat(result).as("Should have used MediaType.equals(Object) to break the match").isGreaterThan(0);
}
@Test

View File

@@ -98,13 +98,13 @@ public class RequestMethodsRequestConditionTests {
ServerWebExchange exchange = getExchange("GET");
int result = c1.compareTo(c2, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = c2.compareTo(c1, exchange);
assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isGreaterThan(0);
result = c2.compareTo(c3, exchange);
assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
assertThat(result).as("Invalid comparison result: " + result).isLessThan(0);
result = c1.compareTo(c1, exchange);
assertThat(result).as("Invalid comparison result ").isEqualTo(0);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -276,7 +276,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);
assertThat(pattern.getPatternString()).isEqualTo("");
assertThat(pattern.getPatternString()).isEmpty();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,7 +125,7 @@ public class ControllerMethodResolverTests {
public void modelAttributeArgumentResolvers() {
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod);
assertThat(methods.size()).as("Expected one each from Controller + ControllerAdvice").isEqualTo(2);
assertThat(methods).as("Expected one each from Controller + ControllerAdvice").hasSize(2);
InvocableHandlerMethod invocable = methods.get(0);
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
@@ -163,7 +163,7 @@ public class ControllerMethodResolverTests {
List<SyncInvocableHandlerMethod> methods =
this.methodResolver.getInitBinderMethods(this.handlerMethod);
assertThat(methods.size()).as("Expected one each from Controller + ControllerAdvice").isEqualTo(2);
assertThat(methods).as("Expected one each from Controller + ControllerAdvice").hasSize(2);
SyncInvocableHandlerMethod invocable = methods.get(0);
List<SyncHandlerMethodArgumentResolver> resolvers = invocable.getResolvers();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -151,7 +151,7 @@ public class PathVariableMethodArgumentResolverTests {
.consumeNextWith(value -> {
boolean condition = value instanceof Optional;
assertThat(condition).isTrue();
assertThat(((Optional<?>) value).isPresent()).isFalse();
assertThat(((Optional<?>) value)).isNotPresent();
})
.expectComplete()
.verify();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -121,7 +121,7 @@ public class RequestAttributeMethodArgumentResolverTests {
assertThat(mono.block()).isNotNull();
assertThat(mono.block().getClass()).isEqualTo(Optional.class);
assertThat(((Optional<?>) mono.block()).isPresent()).isFalse();
assertThat(((Optional<?>) mono.block())).isNotPresent();
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultFormattingConversionService());
@@ -134,7 +134,7 @@ public class RequestAttributeMethodArgumentResolverTests {
assertThat(mono.block()).isNotNull();
assertThat(mono.block().getClass()).isEqualTo(Optional.class);
Optional<?> optional = (Optional<?>) mono.block();
assertThat(optional.isPresent()).isTrue();
assertThat(optional).isPresent();
assertThat(optional.get()).isSameAs(foo);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -206,7 +206,7 @@ public class RequestParamMethodArgumentResolverTests {
assertThat(result.getClass()).isEqualTo(Optional.class);
Optional<?> value = (Optional<?>) result;
assertThat(value.isPresent()).isTrue();
assertThat(value).isPresent();
assertThat(value.get()).isEqualTo(123);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -184,7 +184,7 @@ public class ResponseEntityExceptionHandlerTests {
ResponseEntity<?> entity = this.exceptionHandler.handleException(exception, this.exchange).block();
assertThat(entity).isNotNull();
assertThat(entity.getStatusCode()).isEqualTo(exception.getStatusCode());
assertThat(entity.getBody()).isNotNull().isInstanceOf(ProblemDetail.class);
assertThat(entity.getBody()).isInstanceOf(ProblemDetail.class);
return (ResponseEntity<ProblemDetail>) entity;
}

View File

@@ -116,7 +116,7 @@ class SessionAttributeMethodArgumentResolverTests {
.resolveArgument(param, new BindingContext(), this.exchange).block();
assertThat(actual).isNotNull();
assertThat(actual.isPresent()).isFalse();
assertThat(actual).isNotPresent();
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultFormattingConversionService());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ public class HttpMessageWriterViewTests {
this.view.setModelKeys(Collections.singleton("foo2"));
this.model.addAttribute("foo1", "bar1");
assertThat(doRender()).isEqualTo("");
assertThat(doRender()).isEmpty();
}
@Test
@@ -84,7 +84,7 @@ public class HttpMessageWriterViewTests {
this.view.setModelKeys(new HashSet<>(Collections.singletonList("foo1")));
this.model.addAttribute("foo1", "bar1");
assertThat(doRender()).isEqualTo("");
assertThat(doRender()).isEmpty();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -219,7 +219,7 @@ class WebSocketIntegrationTests extends AbstractReactiveWebSocketIntegrationTest
public Mono<Void> handle(WebSocketSession session) {
return Mono.deferContextual(contextView -> {
String key = ServerWebExchangeContextFilter.EXCHANGE_CONTEXT_ATTRIBUTE;
assertThat(contextView.getOrEmpty(key).orElse(null)).isNotNull();
assertThat(contextView.getOrEmpty(key)).isPresent();
return session.send(session.receive().map(WebSocketMessage::retain));
});
}