18
18
19
19
import java .net .InetSocketAddress ;
20
20
import java .nio .charset .StandardCharsets ;
21
- import java .util .Collections ;
22
21
import java .util .List ;
23
22
import java .util .Map ;
24
23
import java .util .OptionalLong ;
@@ -94,8 +93,7 @@ void header() {
94
93
httpHeaders .setContentType (contentType );
95
94
InetSocketAddress host = InetSocketAddress .createUnresolved ("localhost" , 80 );
96
95
httpHeaders .setHost (host );
97
- List <HttpRange > range = Collections .singletonList (HttpRange .createByteRange (0 , 42 ));
98
- httpHeaders .setRange (range );
96
+ httpHeaders .setRange (List .of (HttpRange .createByteRange (0 , 42 )));
99
97
100
98
given (mockResponse .getHeaders ()).willReturn (httpHeaders );
101
99
@@ -124,7 +122,7 @@ void body() {
124
122
mockTextPlainResponse (Flux .just (dataBuffer ));
125
123
126
124
given (mockExchangeStrategies .messageReaders ()).willReturn (
127
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
125
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
128
126
129
127
Mono <String > resultMono = defaultClientResponse .body (toMono (String .class ));
130
128
assertThat (resultMono .block ()).isEqualTo ("foo" );
@@ -137,7 +135,7 @@ void bodyToMono() {
137
135
mockTextPlainResponse (Flux .just (dataBuffer ));
138
136
139
137
given (mockExchangeStrategies .messageReaders ()).willReturn (
140
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
138
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
141
139
142
140
Mono <String > resultMono = defaultClientResponse .bodyToMono (String .class );
143
141
assertThat (resultMono .block ()).isEqualTo ("foo" );
@@ -150,7 +148,7 @@ void bodyToMonoTypeReference() {
150
148
mockTextPlainResponse (Flux .just (dataBuffer ));
151
149
152
150
given (mockExchangeStrategies .messageReaders ()).willReturn (
153
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
151
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
154
152
155
153
Mono <String > resultMono = defaultClientResponse .bodyToMono (STRING_TYPE );
156
154
assertThat (resultMono .block ()).isEqualTo ("foo" );
@@ -163,11 +161,11 @@ void bodyToFlux() {
163
161
mockTextPlainResponse (Flux .just (dataBuffer ));
164
162
165
163
given (mockExchangeStrategies .messageReaders ()).willReturn (
166
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
164
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
167
165
168
166
Flux <String > resultFlux = defaultClientResponse .bodyToFlux (String .class );
169
167
Mono <List <String >> result = resultFlux .collectList ();
170
- assertThat (result .block ()).isEqualTo ( Collections . singletonList ( "foo" ) );
168
+ assertThat (result .block ()).containsExactly ( "foo" );
171
169
}
172
170
173
171
@ Test
@@ -177,11 +175,11 @@ void bodyToFluxTypeReference() {
177
175
mockTextPlainResponse (Flux .just (dataBuffer ));
178
176
179
177
given (mockExchangeStrategies .messageReaders ()).willReturn (
180
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
178
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
181
179
182
180
Flux <String > resultFlux = defaultClientResponse .bodyToFlux (STRING_TYPE );
183
181
Mono <List <String >> result = resultFlux .collectList ();
184
- assertThat (result .block ()).isEqualTo ( Collections . singletonList ( "foo" ) );
182
+ assertThat (result .block ()).containsExactly ( "foo" );
185
183
}
186
184
187
185
@ Test
@@ -192,7 +190,7 @@ void toEntity() {
192
190
mockTextPlainResponse (Flux .just (dataBuffer ));
193
191
194
192
given (mockExchangeStrategies .messageReaders ()).willReturn (
195
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
193
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
196
194
197
195
ResponseEntity <String > result = defaultClientResponse .toEntity (String .class ).block ();
198
196
assertThat (result .getBody ()).isEqualTo ("foo" );
@@ -213,7 +211,7 @@ void toEntityWithUnknownStatusCode() {
213
211
given (mockResponse .getBody ()).willReturn (Flux .just (dataBuffer ));
214
212
215
213
given (mockExchangeStrategies .messageReaders ()).willReturn (
216
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
214
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
217
215
218
216
ResponseEntity <String > result = defaultClientResponse .toEntity (String .class ).block ();
219
217
assertThat (result .getBody ()).isEqualTo ("foo" );
@@ -230,7 +228,7 @@ void toEntityTypeReference() {
230
228
mockTextPlainResponse (Flux .just (dataBuffer ));
231
229
232
230
given (mockExchangeStrategies .messageReaders ()).willReturn (
233
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
231
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
234
232
235
233
ResponseEntity <String > result = defaultClientResponse .toEntity (STRING_TYPE ).block ();
236
234
assertThat (result .getBody ()).isEqualTo ("foo" );
@@ -247,10 +245,10 @@ void toEntityList() {
247
245
mockTextPlainResponse (Flux .just (dataBuffer ));
248
246
249
247
given (mockExchangeStrategies .messageReaders ()).willReturn (
250
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
248
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
251
249
252
250
ResponseEntity <List <String >> result = defaultClientResponse .toEntityList (String .class ).block ();
253
- assertThat (result .getBody ()).isEqualTo ( Collections . singletonList ( "foo" ) );
251
+ assertThat (result .getBody ()).containsExactly ( "foo" );
254
252
assertThat (result .getStatusCode ()).isEqualTo (HttpStatus .OK );
255
253
assertThat (result .getStatusCodeValue ()).isEqualTo (HttpStatus .OK .value ());
256
254
assertThat (result .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
@@ -268,10 +266,10 @@ void toEntityListWithUnknownStatusCode() {
268
266
given (mockResponse .getBody ()).willReturn (Flux .just (dataBuffer ));
269
267
270
268
given (mockExchangeStrategies .messageReaders ()).willReturn (
271
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
269
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
272
270
273
271
ResponseEntity <List <String >> result = defaultClientResponse .toEntityList (String .class ).block ();
274
- assertThat (result .getBody ()).isEqualTo ( Collections . singletonList ( "foo" ) );
272
+ assertThat (result .getBody ()).containsExactly ( "foo" );
275
273
assertThat (result .getStatusCode ()).isEqualTo (HttpStatusCode .valueOf (999 ));
276
274
assertThat (result .getStatusCodeValue ()).isEqualTo (999 );
277
275
assertThat (result .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
@@ -286,10 +284,10 @@ void toEntityListTypeReference() {
286
284
mockTextPlainResponse (Flux .just (dataBuffer ));
287
285
288
286
given (mockExchangeStrategies .messageReaders ()).willReturn (
289
- Collections . singletonList (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
287
+ List . of (new DecoderHttpMessageReader <>(StringDecoder .allMimeTypes ())));
290
288
291
289
ResponseEntity <List <String >> result = defaultClientResponse .toEntityList (STRING_TYPE ).block ();
292
- assertThat (result .getBody ()).isEqualTo ( Collections . singletonList ( "foo" ) );
290
+ assertThat (result .getBody ()).containsExactly ( "foo" );
293
291
assertThat (result .getStatusCode ()).isEqualTo (HttpStatus .OK );
294
292
assertThat (result .getStatusCodeValue ()).isEqualTo (HttpStatus .OK .value ());
295
293
assertThat (result .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
@@ -305,18 +303,18 @@ void createException() {
305
303
given (mockResponse .getBody ()).willReturn (Flux .just (dataBuffer ));
306
304
307
305
given (mockExchangeStrategies .messageReaders ()).willReturn (
308
- Collections . singletonList (new DecoderHttpMessageReader <>(new ByteArrayDecoder ())));
306
+ List . of (new DecoderHttpMessageReader <>(new ByteArrayDecoder ())));
309
307
310
308
Mono <WebClientResponseException > resultMono = defaultClientResponse .createException ();
311
309
WebClientResponseException exception = resultMono .block ();
312
310
assertThat (exception .getStatusCode ()).isEqualTo (HttpStatus .NOT_FOUND );
313
311
assertThat (exception .getMessage ()).isEqualTo ("404 Not Found" );
314
- assertThat (exception .getHeaders ()).containsExactly (entry ("Content-Type" ,
315
- Collections .singletonList ("text/plain" )));
312
+ assertThat (exception .getHeaders ()).containsExactly (entry ("Content-Type" , List .of ("text/plain" )));
316
313
assertThat (exception .getResponseBodyAsByteArray ()).isEqualTo (bytes );
317
314
}
318
315
319
316
@ Test
317
+ @ SuppressWarnings ("unchecked" )
320
318
void createExceptionAndDecodeContent () {
321
319
byte [] bytes = "{\" name\" :\" Jason\" }" .getBytes (StandardCharsets .UTF_8 );
322
320
DataBuffer buffer = DefaultDataBufferFactory .sharedInstance .wrap (bytes );
@@ -330,10 +328,11 @@ void createExceptionAndDecodeContent() {
330
328
new DecoderHttpMessageReader <>(new Jackson2JsonDecoder ())));
331
329
332
330
WebClientResponseException ex = defaultClientResponse .createException ().block ();
333
- assertThat (ex .getResponseBodyAs (Map .class )).hasSize ( 1 ). containsEntry ("name" , "Jason" );
331
+ assertThat (ex .getResponseBodyAs (Map .class )).containsExactly ( entry ("name" , "Jason" ) );
334
332
}
335
333
336
334
@ Test
335
+ @ SuppressWarnings ("unchecked" )
337
336
void createExceptionAndDecodeWithoutContent () {
338
337
byte [] bytes = new byte [0 ];
339
338
DataBuffer buffer = DefaultDataBufferFactory .sharedInstance .wrap (bytes );
@@ -360,7 +359,7 @@ void createError() {
360
359
given (mockResponse .getBody ()).willReturn (Flux .just (dataBuffer ));
361
360
362
361
given (mockExchangeStrategies .messageReaders ()).willReturn (
363
- Collections . singletonList (new DecoderHttpMessageReader <>(new ByteArrayDecoder ())));
362
+ List . of (new DecoderHttpMessageReader <>(new ByteArrayDecoder ())));
364
363
365
364
Mono <String > resultMono = defaultClientResponse .createError ();
366
365
StepVerifier .create (resultMono )
@@ -369,10 +368,8 @@ void createError() {
369
368
WebClientResponseException exception = (WebClientResponseException ) t ;
370
369
assertThat (exception .getStatusCode ()).isEqualTo (HttpStatus .NOT_FOUND );
371
370
assertThat (exception .getMessage ()).isEqualTo ("404 Not Found" );
372
- assertThat (exception .getHeaders ()).containsExactly (entry ("Content-Type" ,
373
- Collections .singletonList ("text/plain" )));
371
+ assertThat (exception .getHeaders ()).containsExactly (entry ("Content-Type" ,List .of ("text/plain" )));
374
372
assertThat (exception .getResponseBodyAsByteArray ()).isEqualTo (bytes );
375
-
376
373
})
377
374
.verify ();
378
375
}
0 commit comments