Polishing and completing contribution

See gh-24866
This commit is contained in:
Rossen Stoyanchev
2020-05-05 18:15:21 +01:00
parent 3543e47841
commit a7c736915a
10 changed files with 110 additions and 83 deletions

View File

@@ -16,32 +16,33 @@
package org.springframework.core.codec;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.testfixture.codec.AbstractDecoderTests;
import org.springframework.util.MimeTypeUtils;
import reactor.core.publisher.Flux;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Vladislav Kisel
*/
class ByteBufDecoderTests extends AbstractDecoderTests<ByteBufDecoder> {
class NettyByteBufDecoderTests extends AbstractDecoderTests<NettyByteBufDecoder> {
private final byte[] fooBytes = "foo".getBytes(StandardCharsets.UTF_8);
private final byte[] barBytes = "bar".getBytes(StandardCharsets.UTF_8);
ByteBufDecoderTests() {
super(new ByteBufDecoder());
NettyByteBufDecoderTests() {
super(new NettyByteBufDecoder());
}
@Override

View File

@@ -16,29 +16,30 @@
package org.springframework.core.codec;
import java.nio.charset.StandardCharsets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.testfixture.codec.AbstractEncoderTests;
import org.springframework.util.MimeTypeUtils;
import reactor.core.publisher.Flux;
import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Vladislav Kisel
*/
class ByteBufEncoderTests extends AbstractEncoderTests<ByteBufEncoder> {
class NettyByteBufEncoderTests extends AbstractEncoderTests<NettyByteBufEncoder> {
private final byte[] fooBytes = "foo".getBytes(StandardCharsets.UTF_8);
private final byte[] barBytes = "bar".getBytes(StandardCharsets.UTF_8);
ByteBufEncoderTests() {
super(new ByteBufEncoder());
NettyByteBufEncoderTests() {
super(new NettyByteBufEncoder());
}
@Override
@@ -51,7 +52,7 @@ class ByteBufEncoderTests extends AbstractEncoderTests<ByteBufEncoder> {
assertThat(this.encoder.canEncode(ResolvableType.forClass(ByteBuf.class),
MimeTypeUtils.APPLICATION_JSON)).isTrue();
// SPR-15464
// gh-20024
assertThat(this.encoder.canEncode(ResolvableType.NONE, null)).isFalse();
}
@@ -60,12 +61,9 @@ class ByteBufEncoderTests extends AbstractEncoderTests<ByteBufEncoder> {
public void encode() {
Flux<ByteBuf> input = Flux.just(this.fooBytes, this.barBytes).map(Unpooled::copiedBuffer);
Unpooled.copiedBuffer(this.fooBytes, this.barBytes);
testEncodeAll(input, ByteBuf.class, step -> step
.consumeNextWith(expectBytes(this.fooBytes))
.consumeNextWith(expectBytes(this.barBytes))
.verifyComplete());
}
}