Fix StringDecoder#decodeToMono issue with empty input
Before this change decodeToMono always created a StringBuilder to aggregate resulting in an "" (empty string) rather than an empty Mono for an empty input stream. Now we aggregate in the DataBuffer instead and then decode to String.
This commit is contained in:
@@ -73,7 +73,18 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeEmpty() throws InterruptedException {
|
||||
public void decodeEmptyFlux() throws InterruptedException {
|
||||
Flux<DataBuffer> source = Flux.empty();
|
||||
Flux<String> output = this.decoder.decode(source, ResolvableType.forClass(String.class), null);
|
||||
|
||||
TestSubscriber.subscribe(output)
|
||||
.assertNoError()
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeEmptyString() throws InterruptedException {
|
||||
Flux<DataBuffer> source = Flux.just(stringBuffer(""));
|
||||
Flux<String> output = this.decoder.decode(source, ResolvableType.forClass(String.class), null);
|
||||
|
||||
@@ -92,4 +103,15 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
|
||||
.assertValues("foobarbaz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeToMonoWithEmptyFlux() throws InterruptedException {
|
||||
Flux<DataBuffer> source = Flux.empty();
|
||||
Mono<String> output = this.decoder.decodeToMono(source, ResolvableType.forClass(String.class), null);
|
||||
|
||||
TestSubscriber.subscribe(output)
|
||||
.assertNoError()
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user