Polishing

This commit is contained in:
Sam Brannen 2022-12-06 12:29:03 -05:00
parent f64397d822
commit 9f7a510f90
20 changed files with 60 additions and 57 deletions

View File

@ -42,6 +42,7 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.Abstra
import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer; import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
/** /**
* @author Sebastien Deleuze * @author Sebastien Deleuze
@ -95,9 +96,9 @@ class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
.getMultipartData() .getMultipartData()
.doOnNext(parts -> { .doOnNext(parts -> {
assertThat(parts).hasSize(2); assertThat(parts).hasSize(2);
assertThat(parts.containsKey("fooPart")).isTrue(); assertThat(parts).containsKey("fooPart");
assertFooPart(parts.getFirst("fooPart")); assertFooPart(parts.getFirst("fooPart"));
assertThat(parts.containsKey("barPart")).isTrue(); assertThat(parts).containsKey("barPart");
assertBarPart(parts.getFirst("barPart")); assertBarPart(parts.getFirst("barPart"));
}) })
.then(); .then();
@ -105,9 +106,9 @@ class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
private void assertFooPart(Part part) { private void assertFooPart(Part part) {
assertThat(part.name()).isEqualTo("fooPart"); assertThat(part.name()).isEqualTo("fooPart");
boolean condition = part instanceof FilePart; assertThat(part)
assertThat(condition).isTrue(); .asInstanceOf(type(FilePart.class))
assertThat(((FilePart) part).filename()).isEqualTo("foo.txt"); .extracting(FilePart::filename).isEqualTo("foo.txt");
StepVerifier.create(DataBufferUtils.join(part.content())) StepVerifier.create(DataBufferUtils.join(part.content()))
.consumeNextWith(buffer -> { .consumeNextWith(buffer -> {
@ -121,9 +122,9 @@ class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
private void assertBarPart(Part part) { private void assertBarPart(Part part) {
assertThat(part.name()).isEqualTo("barPart"); assertThat(part.name()).isEqualTo("barPart");
boolean condition = part instanceof FormFieldPart; assertThat(part)
assertThat(condition).isTrue(); .asInstanceOf(type(FormFieldPart.class))
assertThat(((FormFieldPart) part).value()).isEqualTo("bar"); .extracting(FormFieldPart::value).isEqualTo("bar");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -133,11 +133,11 @@ class DefaultClientResponse implements ClientResponse {
public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor) { public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor) {
T result = extractor.extract(this.response, this.bodyExtractorContext); T result = extractor.extract(this.response, this.bodyExtractorContext);
String description = "Body from " + this.requestDescription + " [DefaultClientResponse]"; String description = "Body from " + this.requestDescription + " [DefaultClientResponse]";
if (result instanceof Mono<?> monoResult) { if (result instanceof Mono<?> mono) {
return (T) monoResult.checkpoint(description); return (T) mono.checkpoint(description);
} }
else if (result instanceof Flux<?> fluxResult) { else if (result instanceof Flux<?> flux) {
return (T) fluxResult.checkpoint(description); return (T) flux.checkpoint(description);
} }
else { else {
return result; return result;

View File

@ -107,7 +107,7 @@ final class DefaultRenderingResponseBuilder implements RenderingResponse.Builder
@Override @Override
public RenderingResponse.Builder modelAttribute(Object attribute) { public RenderingResponse.Builder modelAttribute(Object attribute) {
Assert.notNull(attribute, "Attribute must not be null"); Assert.notNull(attribute, "Attribute must not be null");
if (attribute instanceof Collection<?> attrCollection && attrCollection.isEmpty()) { if (attribute instanceof Collection<?> collection && collection.isEmpty()) {
return this; return this;
} }
return modelAttribute(Conventions.getVariableName(attribute), attribute); return modelAttribute(Conventions.getVariableName(attribute), attribute);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -247,7 +247,7 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR
} }
} }
} }
value = (value instanceof List<?> valueList ? valueList.toArray() : value); value = (value instanceof List<?> list ? list.toArray() : value);
MethodParameter methodParam = new MethodParameter(ctor, i); MethodParameter methodParam = new MethodParameter(ctor, i);
if (value == null && methodParam.isOptional()) { if (value == null && methodParam.isOptional()) {
args[i] = (methodParam.getParameterType() == Optional.class ? Optional.empty() : null); args[i] = (methodParam.getParameterType() == Optional.class ? Optional.empty() : null);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -177,8 +177,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
@Nullable @Nullable
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class); RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class<?> typeElement ? RequestCondition<?> condition = (element instanceof Class<?> clazz ?
getCustomTypeCondition(typeElement) : getCustomMethodCondition((Method) element)); getCustomTypeCondition(clazz) : getCustomMethodCondition((Method) element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null); return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -126,8 +126,8 @@ public class BindStatus {
this.objectErrors = this.errors.getFieldErrors(this.expression); this.objectErrors = this.errors.getFieldErrors(this.expression);
this.value = this.errors.getFieldValue(this.expression); this.value = this.errors.getFieldValue(this.expression);
this.valueType = this.errors.getFieldType(this.expression); this.valueType = this.errors.getFieldType(this.expression);
if (this.errors instanceof BindingResult bindingResultError) { if (this.errors instanceof BindingResult br) {
this.bindingResult = bindingResultError; this.bindingResult = br;
this.actualValue = this.bindingResult.getRawFieldValue(this.expression); this.actualValue = this.bindingResult.getRawFieldValue(this.expression);
this.editor = this.bindingResult.findEditor(this.expression, null); this.editor = this.bindingResult.findEditor(this.expression, null);
} }
@ -162,8 +162,8 @@ public class BindStatus {
this.errorMessages = new String[0]; this.errorMessages = new String[0];
} }
if (htmlEscape && this.value instanceof String valueString) { if (htmlEscape && this.value instanceof String text) {
this.value = HtmlUtils.htmlEscape(valueString); this.value = HtmlUtils.htmlEscape(text);
} }
} }
@ -238,8 +238,8 @@ public class BindStatus {
* will get HTML-escaped. * will get HTML-escaped.
*/ */
public String getDisplayValue() { public String getDisplayValue() {
if (this.value instanceof String stringValue) { if (this.value instanceof String displayValue) {
return stringValue; return displayValue;
} }
if (this.value != null) { if (this.value != null) {
return (this.htmlEscape ? return (this.htmlEscape ?

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -223,7 +223,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport imp
if (view == null) { if (view == null) {
view = getDefaultViewName(exchange); view = getDefaultViewName(exchange);
} }
viewsMono = (view instanceof String stringView? resolveViews(stringView, locale) : viewsMono = (view instanceof String viewName ? resolveViews(viewName, locale) :
Mono.just(Collections.singletonList((View) view))); Mono.just(Collections.singletonList((View) view)));
} }
else if (Model.class.isAssignableFrom(clazz)) { else if (Model.class.isAssignableFrom(clazz)) {

View File

@ -240,7 +240,7 @@ class MultipartIntegrationTests extends AbstractRouterFunctionIntegrationTests {
public Mono<ServerResponse> transferTo(ServerRequest request) { public Mono<ServerResponse> transferTo(ServerRequest request) {
return request.body(BodyExtractors.toParts()) return request.body(BodyExtractors.toParts())
.filter(part -> part instanceof FilePart) .filter(FilePart.class::isInstance)
.next() .next()
.cast(FilePart.class) .cast(FilePart.class)
.flatMap(part -> createTempFile() .flatMap(part -> createTempFile()

View File

@ -144,8 +144,8 @@ public final class Msg extends
*/ */
public String getFoo() { public String getFoo() {
Object ref = foo_; Object ref = foo_;
if (ref instanceof String stringRef) { if (ref instanceof String) {
return stringRef; return (String) ref;
} else { } else {
com.google.protobuf.ByteString bs = com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref; (com.google.protobuf.ByteString) ref;
@ -162,9 +162,10 @@ public final class Msg extends
public com.google.protobuf.ByteString public com.google.protobuf.ByteString
getFooBytes() { getFooBytes() {
Object ref = foo_; Object ref = foo_;
if (ref instanceof String stringRef) { if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(stringRef); com.google.protobuf.ByteString.copyFromUtf8(
(String) ref);
foo_ = b; foo_ = b;
return b; return b;
} else { } else {
@ -404,8 +405,8 @@ public final class Msg extends
} }
public Builder mergeFrom(com.google.protobuf.Message other) { public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof Msg msg) { if (other instanceof Msg) {
return mergeFrom(msg); return mergeFrom((Msg)other);
} else { } else {
super.mergeFrom(other); super.mergeFrom(other);
return this; return this;
@ -462,13 +463,13 @@ public final class Msg extends
*/ */
public String getFoo() { public String getFoo() {
Object ref = foo_; Object ref = foo_;
if (!(ref instanceof String stringRef)) { if (!(ref instanceof String)) {
String s = ((com.google.protobuf.ByteString) ref) String s = ((com.google.protobuf.ByteString) ref)
.toStringUtf8(); .toStringUtf8();
foo_ = s; foo_ = s;
return s; return s;
} else { } else {
return stringRef; return (String) ref;
} }
} }
/** /**
@ -477,9 +478,10 @@ public final class Msg extends
public com.google.protobuf.ByteString public com.google.protobuf.ByteString
getFooBytes() { getFooBytes() {
Object ref = foo_; Object ref = foo_;
if (ref instanceof String stringRef) { if (ref instanceof String) {
com.google.protobuf.ByteString b = com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(stringRef); com.google.protobuf.ByteString.copyFromUtf8(
(String) ref);
foo_ = b; foo_ = b;
return b; return b;
} else { } else {

View File

@ -304,8 +304,8 @@ public final class SecondMsg extends
} }
public Builder mergeFrom(com.google.protobuf.Message other) { public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof SecondMsg secondMsg) { if (other instanceof SecondMsg) {
return mergeFrom(secondMsg); return mergeFrom((SecondMsg)other);
} else { } else {
super.mergeFrom(other); super.mergeFrom(other);
return this; return this;

View File

@ -354,7 +354,7 @@ class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
} }
private static String partDescription(Part part) { private static String partDescription(Part part) {
return part instanceof FilePart filePart? part.name() + ":" + filePart.filename() : part.name(); return part instanceof FilePart filePart ? part.name() + ":" + filePart.filename() : part.name();
} }
static class FormBean { static class FormBean {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -98,7 +98,7 @@ final class DefaultRenderingResponseBuilder implements RenderingResponse.Builder
@Override @Override
public RenderingResponse.Builder modelAttribute(Object attribute) { public RenderingResponse.Builder modelAttribute(Object attribute) {
Assert.notNull(attribute, "Attribute must not be null"); Assert.notNull(attribute, "Attribute must not be null");
if (attribute instanceof Collection && ((Collection<?>) attribute).isEmpty()) { if (attribute instanceof Collection<?> collection && collection.isEmpty()) {
return this; return this;
} }
return modelAttribute(Conventions.getVariableName(attribute), attribute); return modelAttribute(Conventions.getVariableName(attribute), attribute);

View File

@ -337,8 +337,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
@Nullable @Nullable
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class); RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class ? RequestCondition<?> condition = (element instanceof Class<?> clazz ?
getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element)); getCustomTypeCondition(clazz) : getCustomMethodCondition((Method) element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null); return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -128,8 +128,8 @@ public class BindStatus {
this.objectErrors = this.errors.getFieldErrors(this.expression); this.objectErrors = this.errors.getFieldErrors(this.expression);
this.value = this.errors.getFieldValue(this.expression); this.value = this.errors.getFieldValue(this.expression);
this.valueType = this.errors.getFieldType(this.expression); this.valueType = this.errors.getFieldType(this.expression);
if (this.errors instanceof BindingResult) { if (this.errors instanceof BindingResult br) {
this.bindingResult = (BindingResult) this.errors; this.bindingResult = br;
this.actualValue = this.bindingResult.getRawFieldValue(this.expression); this.actualValue = this.bindingResult.getRawFieldValue(this.expression);
this.editor = this.bindingResult.findEditor(this.expression, null); this.editor = this.bindingResult.findEditor(this.expression, null);
} }
@ -163,8 +163,8 @@ public class BindStatus {
this.errorMessages = new String[0]; this.errorMessages = new String[0];
} }
if (htmlEscape && this.value instanceof String) { if (htmlEscape && this.value instanceof String text) {
this.value = HtmlUtils.htmlEscape((String) this.value); this.value = HtmlUtils.htmlEscape(text);
} }
} }
@ -239,8 +239,8 @@ public class BindStatus {
* will get HTML-escaped. * will get HTML-escaped.
*/ */
public String getDisplayValue() { public String getDisplayValue() {
if (this.value instanceof String) { if (this.value instanceof String displayValue) {
return (String) this.value; return displayValue;
} }
if (this.value != null) { if (this.value != null) {
return (this.htmlEscape ? HtmlUtils.htmlEscape(this.value.toString()) : this.value.toString()); return (this.htmlEscape ? HtmlUtils.htmlEscape(this.value.toString()) : this.value.toString());