11/*
2- * Copyright 2002-2020 the original author or authors.
2+ * Copyright 2002-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
4040 * Unit tests for {@link ServerSentEventHttpMessageReader}.
4141 *
4242 * @author Sebastien Deleuze
43+ * @author Juergen Hoeller
4344 */
4445public class ServerSentEventHttpMessageReaderTests extends AbstractLeakCheckingTests {
4546
@@ -66,7 +67,7 @@ public void readServerSentEvents() {
6667 MockServerHttpRequest request = MockServerHttpRequest .post ("/" )
6768 .body (Mono .just (stringBuffer (
6869 "id:c42\n event:foo\n retry:123\n :bla\n :bla bla\n :bla bla bla\n data:bar\n \n " +
69- "id:c43\n event:bar\n retry:456\n data:baz\n \n " )));
70+ "id:c43\n event:bar\n retry:456\n data:baz\n \n data: \n \n data: \n \ n " )));
7071
7172 Flux <ServerSentEvent > events = this .reader
7273 .read (ResolvableType .forClassWithGenerics (ServerSentEvent .class , String .class ),
@@ -87,6 +88,8 @@ public void readServerSentEvents() {
8788 assertThat (event .comment ()).isNull ();
8889 assertThat (event .data ()).isEqualTo ("baz" );
8990 })
91+ .consumeNextWith (event -> assertThat (event .data ()).isNull ())
92+ .consumeNextWith (event -> assertThat (event .data ()).isNull ())
9093 .expectComplete ()
9194 .verify ();
9295 }
@@ -175,7 +178,7 @@ public void readPojo() {
175178 .verify ();
176179 }
177180
178- @ Test // gh-24389
181+ @ Test // gh-24389
179182 void readPojoWithCommentOnly () {
180183 MockServerHttpRequest request = MockServerHttpRequest .post ("/" )
181184 .body (Flux .just (stringBuffer (":ping\n " ), stringBuffer ("\n " )));
@@ -221,7 +224,6 @@ public void readError() {
221224
222225 @ Test
223226 public void maxInMemoryLimit () {
224-
225227 this .reader .setMaxInMemorySize (17 );
226228
227229 MockServerHttpRequest request = MockServerHttpRequest .post ("/" )
@@ -235,9 +237,8 @@ public void maxInMemoryLimit() {
235237 .verify ();
236238 }
237239
238- @ Test // gh-24312
240+ @ Test // gh-24312
239241 public void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize () {
240-
241242 int limit = this .jsonDecoder .getMaxInMemorySize ();
242243
243244 String fooValue = getStringOfSize (limit ) + "and then some more" ;
@@ -259,13 +260,6 @@ public void maxInMemoryLimitAllowsReadingPojoLargerThanDefaultSize() {
259260 .verify ();
260261 }
261262
262- private static String getStringOfSize (long size ) {
263- StringBuilder content = new StringBuilder ("Aa" );
264- while (content .length () < size ) {
265- content .append (content );
266- }
267- return content .toString ();
268- }
269263
270264 private DataBuffer stringBuffer (String value ) {
271265 byte [] bytes = value .getBytes (StandardCharsets .UTF_8 );
@@ -274,4 +268,12 @@ private DataBuffer stringBuffer(String value) {
274268 return buffer ;
275269 }
276270
271+ private static String getStringOfSize (long size ) {
272+ StringBuilder content = new StringBuilder ("Aa" );
273+ while (content .length () < size ) {
274+ content .append (content );
275+ }
276+ return content .toString ();
277+ }
278+
277279}
0 commit comments