4141
4242/**
4343 * @author Arjen Poutsma
44+ * @author Rossen Stoyanchev
4445 */
4546public class Jackson2TokenizerTests extends AbstractDataBufferAllocatingTestCase {
4647
4748 private ObjectMapper objectMapper ;
4849
4950 private JsonFactory jsonFactory ;
5051
52+
5153 @ Before
52- public void createParser () throws IOException {
53- jsonFactory = new JsonFactory ();
54- this .objectMapper = new ObjectMapper (jsonFactory );
54+ public void createParser () {
55+ this . jsonFactory = new JsonFactory ();
56+ this .objectMapper = new ObjectMapper (this . jsonFactory );
5557 }
5658
5759 @ Test
@@ -66,41 +68,44 @@ public void doNotTokenizeArrayElements() {
6668 singletonList ("{\" foo\" :\" foofoo\" ,\" bar\" :\" barbar\" }" ), false );
6769
6870 testTokenize (
69- singletonList ("[{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" },{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
70- singletonList ("[{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" },{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ), false );
71+ singletonList ("[" +
72+ "{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }," +
73+ "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
74+ singletonList ("[" +
75+ "{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }," +
76+ "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ), false );
7177
7278 testTokenize (
7379 singletonList ("[{\" foo\" : \" bar\" },{\" foo\" : \" baz\" }]" ),
7480 singletonList ("[{\" foo\" : \" bar\" },{\" foo\" : \" baz\" }]" ), false );
7581
7682 testTokenize (
77- asList ("[{\" foo\" : \" foofoo\" , \" bar\" " ,
78- ": \" barbar\" },{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
79- singletonList ("[{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" },{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ), false );
83+ asList ("[" +
84+ "{\" foo\" : \" foofoo\" , \" bar\" " , ": \" barbar\" }," +
85+ "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
86+ singletonList ("[" +
87+ "{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }," +
88+ "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ), false );
8089
8190 testTokenize (
8291 asList ("[" ,
83- "{\" id\" :1,\" name\" :\" Robert\" }" ,
84- "," ,
85- "{\" id\" :2 ,\" name\" :\" Raide \" }" ,
86- "," ,
87- "{\" id\" :3 ,\" name\" :\" Ford \" }" ,
88- "]" ),
89- singletonList ( "[{ \" id \" :1, \" name \" : \" Robert \" },{ \" id \" :2, \" name \" : \" Raide \" }, {\" id\" :3,\" name\" :\" Ford\" }]" ), false );
92+ "{\" id\" :1,\" name\" :\" Robert\" }" , "," ,
93+ "{ \" id \" :2, \" name \" : \" Raide \" }" , " ," ,
94+ "{\" id\" :3 ,\" name\" :\" Ford \" }" , "]" ) ,
95+ singletonList ( "[" +
96+ "{\" id\" :1 ,\" name\" :\" Robert \" }," +
97+ "{ \" id \" :2, \" name \" : \" Raide \" }," +
98+ " {\" id\" :3,\" name\" :\" Ford\" }]" ), false );
9099
91100 // SPR-16166: top-level JSON values
92- testTokenize (asList ("\" foo" , "bar\" " )
93- ,singletonList ("\" foobar\" " ), false );
101+ testTokenize (asList ("\" foo" , "bar\" " ),singletonList ("\" foobar\" " ), false );
94102
95- testTokenize (asList ("12" , "34" )
96- ,singletonList ("1234" ), false );
103+ testTokenize (asList ("12" , "34" ),singletonList ("1234" ), false );
97104
98- testTokenize (asList ("12." , "34" )
99- ,singletonList ("12.34" ), false );
105+ testTokenize (asList ("12." , "34" ),singletonList ("12.34" ), false );
100106
101107 // note that we do not test for null, true, or false, which are also valid top-level values,
102108 // but are unsupported by JSONassert
103-
104109 }
105110
106111 @ Test
@@ -110,19 +115,20 @@ public void tokenizeArrayElements() {
110115 singletonList ("{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }" ), true );
111116
112117 testTokenize (
113- asList ("{\" foo\" : \" foofoo\" " ,
114- ", \" bar\" : \" barbar\" }" ),
118+ asList ("{\" foo\" : \" foofoo\" " , ", \" bar\" : \" barbar\" }" ),
115119 singletonList ("{\" foo\" :\" foofoo\" ,\" bar\" :\" barbar\" }" ), true );
116120
117121 testTokenize (
118- singletonList ("[{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" },{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
119- asList ("{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }" ,
122+ singletonList ("[" +
123+ "{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }," +
124+ "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
125+ asList (
126+ "{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }" ,
120127 "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }" ), true );
121128
122129 testTokenize (
123130 singletonList ("[{\" foo\" : \" bar\" },{\" foo\" : \" baz\" }]" ),
124- asList ("{\" foo\" : \" bar\" }" ,
125- "{\" foo\" : \" baz\" }" ), true );
131+ asList ("{\" foo\" : \" bar\" }" , "{\" foo\" : \" baz\" }" ), true );
126132
127133 // SPR-15803: nested array
128134 testTokenize (
@@ -134,18 +140,19 @@ public void tokenizeArrayElements() {
134140 asList (
135141 "{\" id\" :\" 0\" ,\" start\" :[-999999999,1,1],\" end\" :[999999999,12,31]}" ,
136142 "{\" id\" :\" 1\" ,\" start\" :[-999999999,1,1],\" end\" :[999999999,12,31]}" ,
137- "{\" id\" :\" 2\" ,\" start\" :[-999999999,1,1],\" end\" :[999999999,12,31]}" ),
138- true );
143+ "{\" id\" :\" 2\" ,\" start\" :[-999999999,1,1],\" end\" :[999999999,12,31]}" ), true );
139144
140145 // SPR-15803: nested array, no top-level array
141146 testTokenize (
142147 singletonList ("{\" speakerIds\" :[\" tastapod\" ],\" language\" :\" ENGLISH\" }" ),
143148 singletonList ("{\" speakerIds\" :[\" tastapod\" ],\" language\" :\" ENGLISH\" }" ), true );
144149
145150 testTokenize (
146- asList ("[{\" foo\" : \" foofoo\" , \" bar\" " ,
147- ": \" barbar\" },{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
148- asList ("{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }" ,
151+ asList ("[" +
152+ "{\" foo\" : \" foofoo\" , \" bar\" " , ": \" barbar\" }," +
153+ "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }]" ),
154+ asList (
155+ "{\" foo\" : \" foofoo\" , \" bar\" : \" barbar\" }" ,
149156 "{\" foo\" : \" foofoofoo\" , \" bar\" : \" barbarbar\" }" ), true );
150157
151158 testTokenize (
@@ -161,18 +168,14 @@ public void tokenizeArrayElements() {
161168 "{\" id\" :3,\" name\" :\" Ford\" }" ), true );
162169
163170 // SPR-16166: top-level JSON values
164- testTokenize (asList ("\" foo" , "bar\" " )
165- ,singletonList ("\" foobar\" " ), true );
171+ testTokenize (asList ("\" foo" , "bar\" " ),singletonList ("\" foobar\" " ), true );
166172
167- testTokenize (asList ("12" , "34" )
168- ,singletonList ("1234" ), true );
173+ testTokenize (asList ("12" , "34" ),singletonList ("1234" ), true );
169174
170- testTokenize (asList ("12." , "34" )
171- ,singletonList ("12.34" ), true );
175+ testTokenize (asList ("12." , "34" ),singletonList ("12.34" ), true );
172176
173177 // SPR-16407
174- testTokenize (asList ("[1" , ",2," , "3]" ),
175- asList ("1" , "2" , "3" ), true );
178+ testTokenize (asList ("[1" , ",2," , "3]" ), asList ("1" , "2" , "3" ), true );
176179 }
177180
178181 @ Test (expected = DecodingException .class ) // SPR-16521
@@ -184,11 +187,11 @@ public void jsonEOFExceptionIsWrappedAsDecodingError() {
184187
185188
186189 private void testTokenize (List <String > source , List <String > expected , boolean tokenizeArrayElements ) {
187- Flux <DataBuffer > sourceFlux = Flux .fromIterable (source )
188- .map (this ::stringBuffer );
189190
190- Flux <TokenBuffer > tokenBufferFlux =
191- Jackson2Tokenizer .tokenize (sourceFlux , this .jsonFactory , tokenizeArrayElements );
191+ Flux <TokenBuffer > tokenBufferFlux = Jackson2Tokenizer .tokenize (
192+ Flux .fromIterable (source ).map (this ::stringBuffer ),
193+ this .jsonFactory ,
194+ tokenizeArrayElements );
192195
193196 Flux <String > result = tokenBufferFlux
194197 .map (tokenBuffer -> {
@@ -202,17 +205,16 @@ private void testTokenize(List<String> source, List<String> expected, boolean to
202205 });
203206
204207 StepVerifier .FirstStep <String > builder = StepVerifier .create (result );
205- for (String s : expected ) {
206- builder .assertNext (new JSONAssertConsumer (s ));
207- }
208+ expected .forEach (s -> builder .assertNext (new JSONAssertConsumer (s )));
208209 builder .verifyComplete ();
209210 }
210211
212+
211213 private static class JSONAssertConsumer implements Consumer <String > {
212214
213215 private final String expected ;
214216
215- public JSONAssertConsumer (String expected ) {
217+ JSONAssertConsumer (String expected ) {
216218 this .expected = expected ;
217219 }
218220
@@ -226,6 +228,4 @@ public void accept(String s) {
226228 }
227229 }
228230 }
229-
230-
231231}
0 commit comments