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);
}
}