Remove dumpString from DataBufferTestUtils

See gh-24786
This commit is contained in:
Rossen Stoyanchev 2020-03-26 21:41:45 +00:00
parent 7aa06b8610
commit 3175f0771e
21 changed files with 60 additions and 102 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -33,7 +33,6 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.support.ResourceRegion;
import org.springframework.core.testfixture.io.buffer.AbstractLeakCheckingTests;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@ -182,7 +181,7 @@ class ResourceRegionEncoderTests extends AbstractLeakCheckingTests {
protected Consumer<DataBuffer> stringConsumer(String expected) {
return dataBuffer -> {
String value = DataBufferTestUtils.dumpString(dataBuffer, UTF_8);
String value = dataBuffer.toString(UTF_8);
DataBufferUtils.release(dataBuffer);
assertThat(value).isEqualTo(expected);
};

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -46,7 +46,6 @@ import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.testfixture.io.buffer.AbstractDataBufferAllocatingTests;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
@ -815,7 +814,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
StepVerifier.create(result)
.consumeNextWith(buf -> {
assertThat(DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)).isEqualTo("foobarbaz");
assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("foobarbaz");
release(buf);
})
.verifyComplete();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -53,12 +53,10 @@ class DataBufferTestUtilsTests extends AbstractDataBufferAllocatingTests {
DataBuffer buffer = this.bufferFactory.allocateBuffer(4);
String source = "abcd";
buffer.write(source.getBytes(StandardCharsets.UTF_8));
String result = DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8);
String result = buffer.toString(StandardCharsets.UTF_8);
release(buffer);
assertThat(result).isEqualTo(source);
release(buffer);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -46,6 +46,7 @@ import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@ -89,7 +90,7 @@ public abstract class AbstractDataBufferAllocatingTests {
protected Consumer<DataBuffer> stringConsumer(String expected) {
return dataBuffer -> {
String value = DataBufferTestUtils.dumpString(dataBuffer, StandardCharsets.UTF_8);
String value = dataBuffer.toString(UTF_8);
DataBufferUtils.release(dataBuffer);
assertThat(value).isEqualTo(expected);
};

View File

@ -16,8 +16,6 @@
package org.springframework.core.testfixture.io.buffer;
import java.nio.charset.Charset;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.util.Assert;
@ -45,18 +43,4 @@ public abstract class DataBufferTestUtils {
return bytes;
}
/**
* Dump all the bytes in the given data buffer, and returns them as a string.
* <p>Note that this method reads the entire buffer into the heap, which might
* consume a lot of memory.
* @param buffer the data buffer to dump the string contents of
* @param charset the charset of the data
* @return the string representation of the given data buffer
*/
public static String dumpString(DataBuffer buffer, Charset charset) {
Assert.notNull(buffer, "'buffer' must not be null");
Assert.notNull(charset, "'charset' must not be null");
return buffer.toString(charset);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -24,7 +24,6 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.codec.Encoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.messaging.Message;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -50,7 +49,7 @@ public class TestEncoderMethodReturnValueHandler extends AbstractEncoderMethodRe
}
public Flux<String> getContentAsStrings() {
return this.encodedContent.map(buffer -> DataBufferTestUtils.dumpString(buffer, UTF_8));
return this.encodedContent.map(buffer -> buffer.toString(UTF_8));
}
@Override

View File

@ -33,7 +33,6 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBuffer;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@ -124,7 +123,7 @@ public class MetadataEncoderTests {
.encode()
.block();
assertThat(dumpString(buffer)).isEqualTo("toA");
assertThat(buffer.toString(UTF_8)).isEqualTo("toA");
}
@Test
@ -135,7 +134,7 @@ public class MetadataEncoderTests {
.encode()
.block();
assertThat(dumpString(buffer)).isEqualTo("a.BBB.C%2EC%2EC.d");
assertThat(buffer.toString(UTF_8)).isEqualTo("a.BBB.C%2EC%2EC.d");
}
@Test
@ -146,7 +145,7 @@ public class MetadataEncoderTests {
.encode()
.block();
assertThat(dumpString(buffer)).isEqualTo("Raw data");
assertThat(buffer.toString(UTF_8)).isEqualTo("Raw data");
}
@Test
@ -157,7 +156,7 @@ public class MetadataEncoderTests {
.encode()
.block();
assertThat(dumpString(buffer)).isEqualTo("toA");
assertThat(buffer.toString(UTF_8)).isEqualTo("toA");
}
@Test
@ -235,8 +234,4 @@ public class MetadataEncoderTests {
assertThat(tags.hasNext()).isFalse();
}
private String dumpString(DataBuffer buffer) {
return DataBufferTestUtils.dumpString(buffer, UTF_8);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -30,8 +30,8 @@ import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBuffer;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBuffer;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -99,8 +99,8 @@ public class PayloadUtilsTests {
Payload payload = PayloadUtils.createPayload(data, metadata);
assertThat(payload).isInstanceOf(DefaultPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(dataBufferToString(data));
assertThat(payload.getMetadataUtf8()).isEqualTo(dataBufferToString(metadata));
assertThat(payload.getDataUtf8()).isEqualTo(data.toString(UTF_8));
assertThat(payload.getMetadataUtf8()).isEqualTo(metadata.toString(UTF_8));
}
@Test
@ -111,7 +111,7 @@ public class PayloadUtilsTests {
try {
assertThat(payload).isInstanceOf(ByteBufPayload.class);
assertThat(payload.data()).isSameAs(data.getNativeBuffer());
assertThat(payload.getMetadataUtf8()).isEqualTo(dataBufferToString(metadata));
assertThat(payload.getMetadataUtf8()).isEqualTo(metadata.toString(UTF_8));
}
finally {
payload.release();
@ -125,7 +125,7 @@ public class PayloadUtilsTests {
Payload payload = PayloadUtils.createPayload(data, metadata);
try {
assertThat(payload).isInstanceOf(ByteBufPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(dataBufferToString(data));
assertThat(payload.getDataUtf8()).isEqualTo(data.toString(UTF_8));
assertThat(payload.metadata()).isSameAs(metadata.getNativeBuffer());
}
finally {
@ -152,7 +152,7 @@ public class PayloadUtilsTests {
Payload payload = PayloadUtils.createPayload(data);
assertThat(payload).isInstanceOf(DefaultPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(dataBufferToString(data));
assertThat(payload.getDataUtf8()).isEqualTo(data.toString(UTF_8));
}
@ -168,8 +168,4 @@ public class PayloadUtilsTests {
return buffer;
}
private String dataBufferToString(DataBuffer metadata) {
return DataBufferTestUtils.dumpString(metadata, StandardCharsets.UTF_8);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -76,7 +76,7 @@ public class HttpHandlerConnectorTests {
assertThat(headers.get(HttpHeaders.COOKIE)).isEqualTo(Collections.singletonList("custom-cookie=c0"));
DataBuffer buffer = request.getBody().blockFirst(Duration.ZERO);
assertThat(DataBufferTestUtils.dumpString(buffer, UTF_8)).isEqualTo("Custom body");
assertThat(buffer.toString(UTF_8)).isEqualTo("Custom body");
}
@Test
@ -102,7 +102,7 @@ public class HttpHandlerConnectorTests {
assertThat(headers.get(HttpHeaders.SET_COOKIE)).isEqualTo(Collections.singletonList("custom-cookie=c0"));
DataBuffer buffer = response.getBody().blockFirst(Duration.ZERO);
assertThat(DataBufferTestUtils.dumpString(buffer, UTF_8)).isEqualTo("Custom body");
assertThat(buffer.toString(UTF_8)).isEqualTo("Custom body");
}
@Test // gh-23936

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -16,7 +16,6 @@
package org.springframework.http.codec;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.function.Consumer;
@ -28,13 +27,13 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.testfixture.io.buffer.AbstractLeakCheckingTests;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -95,7 +94,7 @@ public class FormHttpMessageWriterTests extends AbstractLeakCheckingTests {
private Consumer<DataBuffer> stringConsumer(String expected) {
return dataBuffer -> {
String value = DataBufferTestUtils.dumpString(dataBuffer, StandardCharsets.UTF_8);
String value = dataBuffer.toString(UTF_8);
DataBufferUtils.release(dataBuffer);
assertThat(value).isEqualTo(expected);
};

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -32,7 +32,6 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.testfixture.io.buffer.AbstractDataBufferAllocatingTests;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.MediaType;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
@ -134,7 +133,7 @@ class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocating
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(mediaType);
StepVerifier.create(outputMessage.getBody())
.consumeNextWith(dataBuffer -> {
String value = DataBufferTestUtils.dumpString(dataBuffer, charset);
String value = dataBuffer.toString(charset);
DataBufferUtils.release(dataBuffer);
assertThat(value).isEqualTo("data:\u00A3\n\n");
})
@ -192,7 +191,7 @@ class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocating
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(mediaType);
StepVerifier.create(outputMessage.getBody())
.consumeNextWith(dataBuffer -> {
String value = DataBufferTestUtils.dumpString(dataBuffer, charset);
String value = dataBuffer.toString(charset);
DataBufferUtils.release(dataBuffer);
assertThat(value).isEqualTo("data:{\"foo\":\"foo\uD834\uDD1E\",\"bar\":\"bar\uD834\uDD1E\"}\n\n");
})

View File

@ -19,7 +19,6 @@ package org.springframework.http.codec.multipart;
import java.io.File;
import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Map;
import java.util.function.Consumer;
@ -37,7 +36,6 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.testfixture.io.buffer.AbstractLeakCheckingTests;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder;
@ -46,6 +44,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.testfixture.http.client.reactive.MockClientHttpRequest;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
@ -105,7 +104,7 @@ public class SynchronossPartHttpMessageReaderTests extends AbstractLeakCheckingT
assertThat(part.name()).isEqualTo("filePart");
assertThat(((FilePart) part).filename()).isEqualTo("foo.txt");
DataBuffer buffer = DataBufferUtils.join(part.content()).block();
assertThat(DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8)).isEqualTo("Lorem Ipsum.");
assertThat(buffer.toString(UTF_8)).isEqualTo("Lorem Ipsum.");
DataBufferUtils.release(buffer);
part = parts.getFirst("textPart");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -16,7 +16,6 @@
package org.springframework.web.reactive.config;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -28,7 +27,6 @@ import reactor.test.StepVerifier;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.CacheControl;
import org.springframework.http.server.PathContainer;
import org.springframework.web.reactive.HandlerMapping;
@ -48,6 +46,7 @@ import org.springframework.web.reactive.resource.WebJarsResourceResolver;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -86,7 +85,7 @@ public class ResourceHandlerRegistryTests {
handler.handle(exchange).block(Duration.ofSeconds(5));
StepVerifier.create(exchange.getResponse().getBody())
.consumeNextWith(buf -> assertThat(DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)).isEqualTo("test stylesheet content"))
.consumeNextWith(buf -> assertThat(buf.toString(UTF_8)).isEqualTo("test stylesheet content"))
.expectComplete()
.verify();
}

View File

@ -125,7 +125,7 @@ public class BodyInsertersTests {
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(response.getBody())
.consumeNextWith(buf -> {
String actual = DataBufferTestUtils.dumpString(buf, UTF_8);
String actual = buf.toString(UTF_8);
assertThat(actual).isEqualTo("foo");
})
.expectComplete()
@ -185,7 +185,7 @@ public class BodyInsertersTests {
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(response.getBody())
.consumeNextWith(buf -> {
String actual = DataBufferTestUtils.dumpString(buf, UTF_8);
String actual = buf.toString(UTF_8);
assertThat(actual).isEqualTo("foo");
})
.expectComplete()
@ -216,7 +216,7 @@ public class BodyInsertersTests {
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(response.getBody())
.consumeNextWith(buf -> {
String actual = DataBufferTestUtils.dumpString(buf, UTF_8);
String actual = buf.toString(UTF_8);
assertThat(actual).isEqualTo("foo");
})
.expectComplete()

View File

@ -27,12 +27,12 @@ import reactor.test.StepVerifier;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.BodyExtractors;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given;
@ -217,7 +217,7 @@ public class ExchangeFilterFunctionsTests {
}
private String string(DataBuffer buffer) {
String value = DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8);
String value = buffer.toString(UTF_8);
DataBufferUtils.release(buffer);
return value;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -17,7 +17,6 @@
package org.springframework.web.reactive.resource;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
@ -39,7 +38,6 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@ -55,6 +53,7 @@ import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRe
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@ -605,7 +604,7 @@ public class ResourceWebHandlerTests {
StepVerifier.create(reduced)
.consumeNextWith(buf -> {
String content = DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8);
String content = buf.toString(UTF_8);
String[] ranges = StringUtils.tokenizeToStringArray(content, "\r\n", false, true);
assertThat(ranges[0]).isEqualTo(boundary);
@ -653,7 +652,7 @@ public class ResourceWebHandlerTests {
private void assertResponseBody(MockServerWebExchange exchange, String responseBody) {
StepVerifier.create(exchange.getResponse().getBody())
.consumeNextWith(buf -> assertThat(DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)).isEqualTo(responseBody))
.consumeNextWith(buf -> assertThat(buf.toString(UTF_8)).isEqualTo(responseBody))
.expectComplete()
.verify();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -19,7 +19,6 @@ package org.springframework.web.reactive.result.method.annotation;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
@ -53,8 +52,8 @@ import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuild
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.testfixture.io.buffer.DataBufferTestUtils.dumpString;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.web.reactive.HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
import static org.springframework.web.testfixture.method.ResolvableMethod.on;
@ -184,7 +183,7 @@ public class MessageWriterResultHandlerTests {
private void assertResponseBody(String responseBody) {
StepVerifier.create(this.exchange.getResponse().getBody())
.consumeNextWith(buf -> assertThat(dumpString(buf, StandardCharsets.UTF_8)).isEqualTo(responseBody))
.consumeNextWith(buf -> assertThat(buf.toString(UTF_8)).isEqualTo(responseBody))
.expectComplete()
.verify();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -16,7 +16,6 @@
package org.springframework.web.reactive.result.method.annotation;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
@ -33,7 +32,6 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder;
@ -53,6 +51,7 @@ import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRe
import org.springframework.web.testfixture.method.ResolvableMethod;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.ResolvableType.forClass;
import static org.springframework.web.testfixture.method.MvcAnnotationPredicates.requestPart;
@ -190,7 +189,7 @@ public class RequestPartMethodArgumentResolverTests {
Part actual = resolveArgument(param, bodyBuilder);
DataBuffer buffer = DataBufferUtils.join(actual.content()).block();
assertThat(DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8)).isEqualTo("{\"name\":\"Jones\"}");
assertThat(buffer.toString(UTF_8)).isEqualTo("{\"name\":\"Jones\"}");
}
@Test
@ -318,7 +317,7 @@ public class RequestPartMethodArgumentResolverTests {
private String partToUtf8String(Part part) {
DataBuffer buffer = DataBufferUtils.join(part.content()).block();
return DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8);
return buffer.toString(UTF_8);
}

View File

@ -59,6 +59,7 @@ import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.ResolvableType.forClassWithGenerics;
import static org.springframework.http.MediaType.APPLICATION_JSON;
@ -415,7 +416,7 @@ public class ResponseEntityResultHandlerTests {
private void assertResponseBody(MockServerWebExchange exchange, String responseBody) {
StepVerifier.create(exchange.getResponse().getBody())
.consumeNextWith(buf -> assertThat(DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)).isEqualTo(responseBody))
.consumeNextWith(buf -> assertThat(buf.toString(UTF_8)).isEqualTo(responseBody))
.expectComplete()
.verify();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -16,7 +16,6 @@
package org.springframework.web.reactive.result.view;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
@ -28,8 +27,6 @@ import org.junit.jupiter.api.Test;
import reactor.test.StepVerifier;
import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.MediaType;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
@ -38,6 +35,7 @@ import org.springframework.ui.ModelMap;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@ -121,15 +119,11 @@ public class HttpMessageWriterViewTests {
this.view.render(this.model, MediaType.APPLICATION_JSON, exchange).block(Duration.ZERO);
StepVerifier.create(this.exchange.getResponse().getBody())
.consumeNextWith(buf -> assertThat(dumpString(buf)).isEqualTo("{\"foo\":\"f\",\"bar\":\"b\"}"))
.consumeNextWith(buf -> assertThat(buf.toString(UTF_8)).isEqualTo("{\"foo\":\"f\",\"bar\":\"b\"}"))
.expectComplete()
.verify();
}
private String dumpString(DataBuffer buf) {
return DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8);
}
private String doRender() {
this.view.render(this.model, MediaType.APPLICATION_JSON, this.exchange).block(Duration.ZERO);
return this.exchange.getResponse().getBodyAsString().block(Duration.ZERO);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -38,7 +38,6 @@ import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.testfixture.io.buffer.DataBufferTestUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpResponse;
@ -330,7 +329,7 @@ public class ViewResolutionResultHandlerTests {
private void assertResponseBody(MockServerWebExchange exchange, String responseBody) {
StepVerifier.create(exchange.getResponse().getBody())
.consumeNextWith(buf -> assertThat(DataBufferTestUtils.dumpString(buf, UTF_8)).isEqualTo(responseBody))
.consumeNextWith(buf -> assertThat(buf.toString(UTF_8)).isEqualTo(responseBody))
.expectComplete()
.verify();
}