|
29 | 29 | import java.time.LocalDateTime; |
30 | 30 | import java.time.LocalTime; |
31 | 31 | import java.time.Period; |
32 | | -import java.util.ArrayList; |
33 | 32 | import java.util.Date; |
34 | 33 | import java.util.HashMap; |
35 | | -import java.util.HashSet; |
36 | 34 | import java.util.List; |
37 | 35 | import java.util.Map; |
38 | 36 | import java.util.Set; |
@@ -279,151 +277,23 @@ public void testPathCoercion() { |
279 | 277 | } |
280 | 278 |
|
281 | 279 | @Test |
282 | | - @SuppressWarnings("deprecation") |
283 | 280 | public void testListCoercion() { |
284 | | - assertEquals(listOf( |
285 | | - 1, |
286 | | - 2, |
287 | | - 3 |
288 | | - ), BeanAdapter.coerceList(listOf( |
289 | | - "1", |
290 | | - "2", |
291 | | - "3" |
292 | | - ), Integer.class)); |
293 | | - |
294 | | - assertNull(BeanAdapter.coerceList(null, Object.class)); |
295 | | - |
296 | 281 | assertInstanceOf(List.class, BeanAdapter.coerce(listOf(), List.class)); |
297 | 282 | assertThrows(IllegalArgumentException.class, () -> BeanAdapter.coerce(123, List.class)); |
298 | 283 | } |
299 | 284 |
|
300 | 285 | @Test |
301 | | - @SuppressWarnings("deprecation") |
302 | 286 | public void testMapCoercion() { |
303 | | - assertEquals(mapOf( |
304 | | - entry("a", 1.0), |
305 | | - entry("b", 2.0), |
306 | | - entry("c", 3.0) |
307 | | - ), BeanAdapter.coerceMap(mapOf( |
308 | | - entry("a", "1.0"), |
309 | | - entry("b", "2.0"), |
310 | | - entry("c", "3.0") |
311 | | - ), String.class, Double.class)); |
312 | | - |
313 | | - assertEquals(mapOf( |
314 | | - entry(1, 1.0), |
315 | | - entry(2, 2.0), |
316 | | - entry(3, 3.0) |
317 | | - ), BeanAdapter.coerceMap(mapOf( |
318 | | - entry("1", "1.0"), |
319 | | - entry("2", "2.0"), |
320 | | - entry("3", "3.0") |
321 | | - ), Integer.class, Double.class)); |
322 | | - |
323 | | - assertNull(BeanAdapter.coerceMap(null, Object.class, Object.class)); |
324 | | - |
325 | 287 | assertInstanceOf(Map.class, BeanAdapter.coerce(mapOf(), Map.class)); |
326 | 288 | assertThrows(IllegalArgumentException.class, () -> BeanAdapter.coerce(123, Map.class)); |
327 | 289 | } |
328 | 290 |
|
329 | 291 | @Test |
330 | | - @SuppressWarnings("deprecation") |
331 | 292 | public void testSetCoercion() { |
332 | | - assertEquals(setOf( |
333 | | - 1, |
334 | | - 2, |
335 | | - 3 |
336 | | - ), BeanAdapter.coerceSet(setOf( |
337 | | - "1", |
338 | | - "2", |
339 | | - "3" |
340 | | - ), Integer.class)); |
341 | | - |
342 | | - assertNull(BeanAdapter.coerceSet(null, Object.class)); |
343 | | - |
344 | 293 | assertInstanceOf(Set.class, BeanAdapter.coerce(setOf(), Set.class)); |
345 | 294 | assertThrows(IllegalArgumentException.class, () -> BeanAdapter.coerce(123, Set.class)); |
346 | 295 | } |
347 | 296 |
|
348 | | - @Test |
349 | | - @SuppressWarnings("deprecation") |
350 | | - public void testMutableListCoercion() { |
351 | | - var strings = new ArrayList<String>(); |
352 | | - |
353 | | - strings.add("1"); |
354 | | - strings.add("2"); |
355 | | - strings.add("3"); |
356 | | - strings.add(null); |
357 | | - |
358 | | - var integers = BeanAdapter.coerceList(strings, Integer.class); |
359 | | - |
360 | | - assertEquals(listOf(1, 2, 3, null), integers); |
361 | | - |
362 | | - integers.set(1, 4); |
363 | | - |
364 | | - assertEquals(listOf(1, 4, 3, null), integers); |
365 | | - |
366 | | - integers.remove(1); |
367 | | - |
368 | | - assertEquals(listOf(1, 3, null), integers); |
369 | | - } |
370 | | - |
371 | | - @Test |
372 | | - @SuppressWarnings("deprecation") |
373 | | - public void testMutableMapCoercion() { |
374 | | - var strings = new HashMap<Integer, String>(); |
375 | | - |
376 | | - strings.put(1, "1.0"); |
377 | | - strings.put(2, "2.0"); |
378 | | - strings.put(3, "3.0"); |
379 | | - strings.put(4, null); |
380 | | - |
381 | | - var doubles = BeanAdapter.coerceMap(strings, Integer.class, Double.class); |
382 | | - |
383 | | - assertEquals(mapOf( |
384 | | - entry(1, 1.0), |
385 | | - entry(2, 2.0), |
386 | | - entry(3, 3.0), |
387 | | - entry(4, null) |
388 | | - ), doubles); |
389 | | - |
390 | | - doubles.put(2, 4.0); |
391 | | - |
392 | | - assertEquals(mapOf( |
393 | | - entry(1, 1.0), |
394 | | - entry(2, 4.0), |
395 | | - entry(3, 3.0), |
396 | | - entry(4, null) |
397 | | - ), doubles); |
398 | | - |
399 | | - doubles.remove(2); |
400 | | - |
401 | | - assertEquals(mapOf( |
402 | | - entry(1, 1.0), |
403 | | - entry(3, 3.0), |
404 | | - entry(4, null) |
405 | | - ), doubles); |
406 | | - } |
407 | | - |
408 | | - @Test |
409 | | - @SuppressWarnings("deprecation") |
410 | | - public void testMutableSetCoercion() { |
411 | | - var strings = new HashSet<>(); |
412 | | - |
413 | | - strings.add("1"); |
414 | | - strings.add("2"); |
415 | | - strings.add("3"); |
416 | | - strings.add(null); |
417 | | - |
418 | | - var integers = BeanAdapter.coerceSet(strings, Integer.class); |
419 | | - |
420 | | - assertEquals(setOf(1, 2, 3, null), integers); |
421 | | - |
422 | | - integers.remove(2); |
423 | | - |
424 | | - assertEquals(setOf(1, 3, null), integers); |
425 | | - } |
426 | | - |
427 | 297 | @Test |
428 | 298 | public void testInterfaceCoercion() { |
429 | 299 | var map = new HashMap<String, Object>(); |
|
0 commit comments