Skip to content

Commit 0176d36

Browse files
committed
Add error stream tests for Jackson2JsonDecoder
Issue: SPR-17418
1 parent 946ec7e commit 0176d36

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@
4646
import static java.util.Arrays.asList;
4747
import static java.util.Collections.emptyMap;
4848
import static java.util.Collections.singletonMap;
49-
import static org.junit.Assert.assertEquals;
50-
import static org.junit.Assert.assertFalse;
51-
import static org.junit.Assert.assertNull;
52-
import static org.junit.Assert.assertTrue;
49+
import static org.junit.Assert.*;
5350
import static org.springframework.core.ResolvableType.forClass;
5451
import static org.springframework.http.MediaType.APPLICATION_JSON;
5552
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;
@@ -229,6 +226,18 @@ public void invalidData() throws Exception {
229226
StepVerifier.create(flux).verifyErrorMatches(ex -> ex instanceof DecodingException);
230227
}
231228

229+
@Test
230+
public void error() throws Exception {
231+
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"foofoo\": \"foofoo\", \"barbar\":"))
232+
.concatWith(Flux.error(new RuntimeException()));
233+
ResolvableType elementType = forClass(Pojo.class);
234+
Flux<Object> flux = new Jackson2JsonDecoder(new ObjectMapper()).decode(source, elementType, null, emptyMap());
235+
236+
StepVerifier.create(flux)
237+
.expectError(RuntimeException.class)
238+
.verify();
239+
}
240+
232241
@Test
233242
public void noDefaultConstructor() throws Exception {
234243
Flux<DataBuffer> source = Flux.just(stringBuffer( "{\"property1\":\"foo\",\"property2\":\"bar\"}"));

spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
3737
import org.springframework.core.io.buffer.DataBuffer;
3838

39-
import static java.util.Arrays.*;
40-
import static java.util.Collections.*;
39+
import static java.util.Arrays.asList;
40+
import static java.util.Collections.singletonList;
4141

4242
/**
4343
* @author Arjen Poutsma
@@ -178,6 +178,19 @@ public void tokenizeArrayElements() {
178178
testTokenize(asList("[1", ",2,", "3]"), asList("1", "2", "3"), true);
179179
}
180180

181+
@Test
182+
public void errorInStream() {
183+
DataBuffer buffer = stringBuffer("{\"id\":1,\"name\":");
184+
Flux<DataBuffer> source = Flux.just(buffer)
185+
.concatWith(Flux.error(new RuntimeException()));
186+
187+
Flux<TokenBuffer> result = Jackson2Tokenizer.tokenize(source, this.jsonFactory, true);
188+
189+
StepVerifier.create(result)
190+
.expectError(RuntimeException.class)
191+
.verify();
192+
}
193+
181194
@Test(expected = DecodingException.class) // SPR-16521
182195
public void jsonEOFExceptionIsWrappedAsDecodingError() {
183196
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"status\": \"noClosingQuote}"));

0 commit comments

Comments
 (0)