提交 5e1e29a2 编写于 作者: R Rossen Stoyanchev

Fix failing tests

See gh-26746
上级 7dc3a556
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
......@@ -20,6 +20,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
......@@ -89,8 +90,12 @@ public abstract class AbstractDataBufferAllocatingTests {
}
protected Consumer<DataBuffer> stringConsumer(String expected) {
return stringConsumer(expected, UTF_8);
}
protected Consumer<DataBuffer> stringConsumer(String expected, Charset charset) {
return dataBuffer -> {
String value = dataBuffer.toString(UTF_8);
String value = dataBuffer.toString(charset);
DataBufferUtils.release(dataBuffer);
assertThat(value).isEqualTo(expected);
};
......
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
......@@ -150,8 +150,12 @@ class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocating
testWrite(source, outputMessage, Pojo.class);
StepVerifier.create(outputMessage.getBody())
.consumeNextWith(stringConsumer("data:{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n\n"))
.consumeNextWith(stringConsumer("data:{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n\n"))
.consumeNextWith(stringConsumer("data:"))
.consumeNextWith(stringConsumer("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}"))
.consumeNextWith(stringConsumer("\n\n"))
.consumeNextWith(stringConsumer("data:"))
.consumeNextWith(stringConsumer("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}"))
.consumeNextWith(stringConsumer("\n\n"))
.expectComplete()
.verify();
}
......@@ -168,12 +172,16 @@ class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocating
testWrite(source, outputMessage, Pojo.class);
StepVerifier.create(outputMessage.getBody())
.consumeNextWith(stringConsumer("data:{\n" +
.consumeNextWith(stringConsumer("data:"))
.consumeNextWith(stringConsumer("{\n" +
"data: \"foo\" : \"foofoo\",\n" +
"data: \"bar\" : \"barbar\"\n" + "data:}\n\n"))
.consumeNextWith(stringConsumer("data:{\n" +
"data: \"bar\" : \"barbar\"\n" + "data:}"))
.consumeNextWith(stringConsumer("\n\n"))
.consumeNextWith(stringConsumer("data:"))
.consumeNextWith(stringConsumer("{\n" +
"data: \"foo\" : \"foofoofoo\",\n" +
"data: \"bar\" : \"barbarbar\"\n" + "data:}\n\n"))
"data: \"bar\" : \"barbarbar\"\n" + "data:}"))
.consumeNextWith(stringConsumer("\n\n"))
.expectComplete()
.verify();
}
......@@ -190,11 +198,9 @@ class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocating
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(mediaType);
StepVerifier.create(outputMessage.getBody())
.consumeNextWith(dataBuffer -> {
String value = dataBuffer.toString(charset);
DataBufferUtils.release(dataBuffer);
assertThat(value).isEqualTo("data:{\"foo\":\"foo\uD834\uDD1E\",\"bar\":\"bar\uD834\uDD1E\"}\n\n");
})
.consumeNextWith(stringConsumer("data:", charset))
.consumeNextWith(stringConsumer("{\"foo\":\"foo\uD834\uDD1E\",\"bar\":\"bar\uD834\uDD1E\"}", charset))
.consumeNextWith(stringConsumer("\n\n", charset))
.expectComplete()
.verify();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册