|
1 | 1 | /* |
2 | | - * Copyright 2002-2011 the original author or authors. |
| 2 | + * Copyright 2002-2012 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.core.convert.support; |
18 | 18 |
|
19 | | -import static org.junit.Assert.assertTrue; |
20 | 19 | import static org.junit.Assert.assertEquals; |
21 | 20 | import static org.junit.Assert.assertFalse; |
22 | 21 | import static org.junit.Assert.assertNotNull; |
23 | 22 | import static org.junit.Assert.assertNull; |
24 | 23 | import static org.junit.Assert.assertSame; |
| 24 | +import static org.junit.Assert.assertTrue; |
25 | 25 | import static org.junit.Assert.fail; |
26 | 26 |
|
27 | 27 | import java.awt.Color; |
|
52 | 52 | /** |
53 | 53 | * @author Keith Donald |
54 | 54 | * @author Juergen Hoeller |
| 55 | + * @author Phillip Webb |
55 | 56 | */ |
56 | 57 | public class GenericConversionServiceTests { |
57 | 58 |
|
@@ -599,4 +600,48 @@ public void testConvertiblePairDifferentEqualsAndHash() throws Exception { |
599 | 600 | assertFalse(pair.hashCode() == pairOpposite.hashCode()); |
600 | 601 | } |
601 | 602 |
|
| 603 | + @Test |
| 604 | + public void convertPrimitiveArray() throws Exception { |
| 605 | + GenericConversionService conversionService = new DefaultConversionService(); |
| 606 | + byte[] byteArray = new byte[] { 1, 2, 3 }; |
| 607 | + Byte[] converted = conversionService.convert(byteArray, Byte[].class); |
| 608 | + assertTrue(Arrays.equals(converted, new Byte[] { 1, 2, 3 })); |
| 609 | + } |
| 610 | + |
| 611 | + @Test |
| 612 | + public void canConvertIllegalArgumentNullTargetTypeFromClass() { |
| 613 | + try { |
| 614 | + conversionService.canConvert(String.class, null); |
| 615 | + fail("Did not thow IllegalArgumentException"); |
| 616 | + } catch(IllegalArgumentException e) { |
| 617 | + } |
| 618 | + } |
| 619 | + |
| 620 | + @Test |
| 621 | + public void canConvertIllegalArgumentNullTargetTypeFromTypeDescriptor() { |
| 622 | + try { |
| 623 | + conversionService.canConvert(TypeDescriptor.valueOf(String.class), null); |
| 624 | + fail("Did not thow IllegalArgumentException"); |
| 625 | + } catch(IllegalArgumentException e) { |
| 626 | + } |
| 627 | + } |
| 628 | + |
| 629 | + @Test |
| 630 | + @SuppressWarnings({ "rawtypes" }) |
| 631 | + public void convertHashMapValuesToList() throws Exception { |
| 632 | + GenericConversionService conversionService = new DefaultConversionService(); |
| 633 | + Map<String, Integer> hashMap = new LinkedHashMap<String, Integer>(); |
| 634 | + hashMap.put("1", 1); |
| 635 | + hashMap.put("2", 2); |
| 636 | + List converted = conversionService.convert(hashMap.values(), List.class); |
| 637 | + assertEquals(Arrays.asList(1, 2), converted); |
| 638 | + } |
| 639 | + |
| 640 | + @Test |
| 641 | + public void removeConvertible() throws Exception { |
| 642 | + conversionService.addConverter(new ColorConverter()); |
| 643 | + assertTrue(conversionService.canConvert(String.class, Color.class)); |
| 644 | + conversionService.removeConvertible(String.class, Color.class); |
| 645 | + assertFalse(conversionService.canConvert(String.class, Color.class)); |
| 646 | + } |
602 | 647 | } |
0 commit comments