Use text block where feasible

See gh-31916
This commit is contained in:
Yanming Zhou 2023-12-28 15:04:50 +08:00 committed by Stéphane Nicoll
parent 9d31537ae5
commit a35384fd57
9 changed files with 93 additions and 41 deletions

View File

@ -58,9 +58,10 @@ public class PropertiesEditorTests {
@Test
public void handlesEqualsInValue() {
String s = "foo=bar\n" +
"me=mi\n" +
"x=y=z";
String s = """
foo=bar
me=mi
x=y=z""";
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
@ -98,12 +99,14 @@ public class PropertiesEditorTests {
*/
@Test
public void ignoresCommentLinesAndEmptyLines() {
String s = "#Ignore this comment\n" +
"foo=bar\n" +
"#Another=comment more junk /\n" +
"me=mi\n" +
"x=x\n" +
"\n";
String s = """
#Ignore this comment
foo=bar
#Another=comment more junk /
me=mi
x=x
""";
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();

View File

@ -28,10 +28,16 @@ public class OuterSample {
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\014sample.proto\",\n\003Msg\022\013\n\003foo\030\001 \001(\t\022\030\n\004bl" +
"ah\030\002 \001(\0132\n.SecondMsg\"\031\n\tSecondMsg\022\014\n\004bla" +
"h\030\001 \001(\005B-\n\034org.springframework.protobufB" +
"\013OuterSampleP\001"
"""
\014sample.proto",
\003Msg\022\013
\003foo\030\001 \001(\t\022\030
\004blah\030\002 \001(\0132
.SecondMsg"\031
\tSecondMsg\022\014
\004blah\030\001 \001(\005B-
\034org.springframework.protobufB\013OuterSampleP\001"""
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {

View File

@ -72,7 +72,14 @@ public class BufferingStompDecoderTests {
@Test
public void twoMessagesInOneChunk() throws InterruptedException {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = "SEND\na:alpha\n\nPayload1\0" + "SEND\na:alpha\n\nPayload2\0";
String chunk = """
SEND
a:alpha
Payload1\0SEND
a:alpha
Payload2\0""";
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk));
assertThat(messages).hasSize(2);

View File

@ -66,8 +66,25 @@ class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingTests {
void readServerSentEvents() {
MockServerHttpRequest request = MockServerHttpRequest.post("/")
.body(Mono.just(stringBuffer(
"id:c42\nevent:foo\nretry:123\n:bla\n:bla bla\n:bla bla bla\ndata:bar\n\n" +
"id:c43\nevent:bar\nretry:456\ndata:baz\n\ndata:\n\ndata: \n\n")));
"""
id:c42
event:foo
retry:123
:bla
:bla bla
:bla bla bla
data:bar
id:c43
event:bar
retry:456
data:baz
data:
data:\s
""")));
Flux<ServerSentEvent> events = this.reader
.read(ResolvableType.forClassWithGenerics(ServerSentEvent.class, String.class),

View File

@ -33,10 +33,16 @@ public final class OuterSample {
descriptor;
static {
String[] descriptorData = {
"\n\014sample.proto\",\n\003Msg\022\013\n\003foo\030\001 \001(\t\022\030\n\004bl" +
"ah\030\002 \001(\0132\n.SecondMsg\"\031\n\tSecondMsg\022\014\n\004bla" +
"h\030\001 \001(\005B-\n\034org.springframework.protobufB" +
"\013OuterSampleP\001"
"""
\014sample.proto",
\003Msg\022\013
\003foo\030\001 \001(\t\022\030
\004blah\030\002 \001(\0132
.SecondMsg"\031
\tSecondMsg\022\014
\004blah\030\001 \001(\005B-
\034org.springframework.protobufB\013OuterSampleP\001"""
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,

View File

@ -404,16 +404,18 @@ public class BodyInsertersTests {
dataBuffer.read(resultBytes);
DataBufferUtils.release(dataBuffer);
String content = new String(resultBytes, StandardCharsets.UTF_8);
assertThat(content).contains("Content-Disposition: form-data; name=\"name\"\r\n" +
"Content-Type: text/plain;charset=UTF-8\r\n" +
"Content-Length: 6\r\n" +
"\r\n" +
"value1");
assertThat(content).contains("Content-Disposition: form-data; name=\"name\"\r\n" +
"Content-Type: text/plain;charset=UTF-8\r\n" +
"Content-Length: 6\r\n" +
"\r\n" +
"value2");
assertThat(content).contains("""
Content-Disposition: form-data; name="name"\r
Content-Type: text/plain;charset=UTF-8\r
Content-Length: 6\r
\r
value1""");
assertThat(content).contains("""
Content-Disposition: form-data; name="name"\r
Content-Type: text/plain;charset=UTF-8\r
Content-Length: 6\r
\r
value2""");
})
.expectComplete()
.verify();

View File

@ -28,10 +28,16 @@ public class OuterSample {
descriptor;
static {
String[] descriptorData = {
"\n\014sample.proto\",\n\003Msg\022\013\n\003foo\030\001 \001(\t\022\030\n\004bl" +
"ah\030\002 \001(\0132\n.SecondMsg\"\031\n\tSecondMsg\022\014\n\004bla" +
"h\030\001 \001(\005B-\n\034org.springframework.protobufB" +
"\013OuterSampleP\001"
"""
\014sample.proto",
\003Msg\022\013
\003foo\030\001 \001(\t\022\030
\004blah\030\002 \001(\0132
.SecondMsg"\031
\tSecondMsg\022\014
\004blah\030\001 \001(\005B-
\034org.springframework.protobufB\013OuterSampleP\001"""
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {

View File

@ -114,8 +114,11 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
pvs = new MutablePropertyValues();
pvs.add(
"mappings", "/head.do=headController\n" +
"body.do=bodyController\n/noview*=noviewController\n/noview/simple*=noviewController");
"mappings", """
/head.do=headController
body.do=bodyController
/noview*=noviewController
/noview/simple*=noviewController""");
pvs.add("order", "1");
registerSingleton("handlerMapping", SimpleUrlHandlerMapping.class, pvs);

View File

@ -109,11 +109,13 @@ class SseServerResponseTests {
ModelAndView mav = response.writeTo(this.mockRequest, this.mockResponse, context);
assertThat(mav).isNull();
String expected = "data:{\n" +
"data: \"name\" : \"John Doe\",\n" +
"data: \"age\" : 42\n" +
"data:}\n" +
"\n";
String expected = """
data:{
data: "name" : "John Doe",
data: "age" : 42
data:}
""";
assertThat(this.mockResponse.getContentAsString()).isEqualTo(expected);
}