Use new Java features (switch expressions, text blocks, new JDK methods)

Closes gh-29747
This commit is contained in:
Krzysztof Krason
2022-12-28 08:59:08 +01:00
committed by Sam Brannen
parent 48abd493fe
commit afb8a0d1b1
53 changed files with 498 additions and 552 deletions

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");
* you may not use this file except in compliance with the License.
@@ -109,12 +109,15 @@ class SseServerResponseTests {
ModelAndView mav = response.writeTo(this.mockRequest, this.mockResponse, context);
assertThat(mav).isNull();
String expected = "id:id\n" +
"event:name\n" +
":comment line 1\n" +
":comment line 2\n" +
"retry:1000\n" +
"data:data\n\n";
String expected = """
id:id
event:name
:comment line 1
:comment line 2
retry:1000
data:data
""";
assertThat(this.mockResponse.getContentAsString()).isEqualTo(expected);
}

View File

@@ -52,11 +52,12 @@ public class ToStringVisitorTests {
routerFunction.accept(visitor);
String result = visitor.toString();
String expected = "/foo => {\n" +
" /bar => {\n" +
" (GET && /baz) -> \n" +
" }\n" +
"}";
String expected = """
/foo => {
/bar => {
(GET && /baz) ->\s
}
}""".replace('\t', ' ');
assertThat(result).isEqualTo(expected);
}

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");
* you may not use this file except in compliance with the License.
@@ -84,13 +84,17 @@ public class CssLinkResourceTransformerTests {
public void transform() throws Exception {
this.request = new MockHttpServletRequest("GET", "/static/main.css");
Resource css = getResource("main.css");
String expected = "\n" +
"@import url(\"/static/bar-11e16cf79faee7ac698c805cf28248d2.css?#iefix\");\n" +
"@import url('/static/bar-11e16cf79faee7ac698c805cf28248d2.css#bla-normal');\n" +
"@import url(/static/bar-11e16cf79faee7ac698c805cf28248d2.css);\n\n" +
"@import \"/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css\";\n" +
"@import '/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css';\n\n" +
"body { background: url(\"/static/images/image-f448cd1d5dba82b774f3202c878230b3.png?#iefix\") }\n";
String expected = """
@import url("/static/bar-11e16cf79faee7ac698c805cf28248d2.css?#iefix");
@import url('/static/bar-11e16cf79faee7ac698c805cf28248d2.css#bla-normal');
@import url(/static/bar-11e16cf79faee7ac698c805cf28248d2.css);
@import "/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css";
@import '/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css';
body { background: url("/static/images/image-f448cd1d5dba82b774f3202c878230b3.png?#iefix") }
""";
TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.request, css);
String result = new String(actual.getByteArray(), StandardCharsets.UTF_8);
@@ -115,9 +119,10 @@ public class CssLinkResourceTransformerTests {
ResourceTransformerChain chain = new DefaultResourceTransformerChain(mockChain, transformers);
Resource resource = getResource("external.css");
String expected = "@import url(\"https://example.org/fonts/css\");\n" +
"body { background: url(\"file:///home/spring/image.png\") }\n" +
"figure { background: url(\"//example.org/style.css\")}";
String expected = """
@import url("https://example.org/fonts/css");
body { background: url("file:///home/spring/image.png") }
figure { background: url("//example.org/style.css")}""";
TransformedResource transformedResource = (TransformedResource) chain.transform(this.request, resource);
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
@@ -155,10 +160,10 @@ public class CssLinkResourceTransformerTests {
public void transformEmptyUrlFunction() throws Exception {
this.request = new MockHttpServletRequest("GET", "/static/empty_url_function.css");
Resource css = getResource("empty_url_function.css");
String expected =
".fooStyle {\n" +
"\tbackground: transparent url() no-repeat left top;\n" +
"}";
String expected = """
.fooStyle {
\tbackground: transparent url() no-repeat left top;
}""";
TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.request, css);
String result = new String(actual.getByteArray(), StandardCharsets.UTF_8);

View File

@@ -48,7 +48,6 @@ import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
import org.springframework.web.testfixture.servlet.MockServletContext;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
/**
@@ -346,8 +345,9 @@ public class FreeMarkerMacroTests {
}
private void storeTemplateInTempDir(String macro) throws IOException {
Files.write(this.templateLoaderPath.resolve("tmp.ftl"),
("<#import \"spring.ftl\" as spring />\n" + macro).getBytes(UTF_8));
Files.writeString(this.templateLoaderPath.resolve("tmp.ftl"),
"<#import \"spring.ftl\" as spring />\n" + macro
);
}
private String getOutput() throws IOException {