diff --git a/spring-core/src/test/java/org/springframework/core/codec/ResourceRegionEncoderTests.java b/spring-core/src/test/java/org/springframework/core/codec/ResourceRegionEncoderTests.java index 2a25e3cc14..465780eb38 100644 --- a/spring-core/src/test/java/org/springframework/core/codec/ResourceRegionEncoderTests.java +++ b/spring-core/src/test/java/org/springframework/core/codec/ResourceRegionEncoderTests.java @@ -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 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); }; diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java index 2b785b0b71..2e34843b9c 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java @@ -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(); diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java index b369d125b3..96f720ffdf 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java @@ -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); } } diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java index 5c5ad5f44f..41e11653b0 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java @@ -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 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); }; diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java index b1e96092f0..0277163792 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java @@ -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. - *

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); - } - } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestEncoderMethodReturnValueHandler.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestEncoderMethodReturnValueHandler.java index 50bb018c1a..e16ee6ea70 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestEncoderMethodReturnValueHandler.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestEncoderMethodReturnValueHandler.java @@ -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 getContentAsStrings() { - return this.encodedContent.map(buffer -> DataBufferTestUtils.dumpString(buffer, UTF_8)); + return this.encodedContent.map(buffer -> buffer.toString(UTF_8)); } @Override diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/MetadataEncoderTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/MetadataEncoderTests.java index 3cb7928e5e..fe276b5fdb 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/MetadataEncoderTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/MetadataEncoderTests.java @@ -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); - } - } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/PayloadUtilsTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/PayloadUtilsTests.java index ddeca0ddeb..343a267770 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/PayloadUtilsTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/PayloadUtilsTests.java @@ -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); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java index 17c04a8254..18e21d5c0d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java @@ -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 diff --git a/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java index 04f4a889ec..6685493478 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/FormHttpMessageWriterTests.java @@ -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 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); }; diff --git a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java index 5411540c55..d9089b3c37 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java @@ -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"); }) diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java index 7e12e1c29a..ba025cbd6b 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java @@ -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"); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java index 4129b8b90e..ac14056642 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java @@ -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(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java index bc68dc96d9..a4ae306814 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java @@ -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() diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctionsTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctionsTests.java index a98844e486..1c8d7910bc 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctionsTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctionsTests.java @@ -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; } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java index 34c46c7e1a..7bdbeff945 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java @@ -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(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java index 6acf14437d..4940a3009e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java @@ -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(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolverTests.java index 19ebc737a9..875f355c2c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolverTests.java @@ -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); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java index f7a5f5afa7..b37e947b5a 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java @@ -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(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/HttpMessageWriterViewTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/HttpMessageWriterViewTests.java index b75a214c30..5c212b58b3 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/HttpMessageWriterViewTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/HttpMessageWriterViewTests.java @@ -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); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java index 669bf2ef59..015c6b2b66 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java @@ -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(); }