@Test
 public void collectionToObjectInteraction() throws Exception {
   List<List<String>> list = new ArrayList<List<String>>();
   list.add(Arrays.asList("9", "12"));
   list.add(Arrays.asList("37", "23"));
   conversionService.addConverter(new CollectionToObjectConverter(conversionService));
   assertTrue(conversionService.canConvert(List.class, List.class));
   assertSame(list, conversionService.convert(list, List.class));
 }
 @Test
 public void emptyListToList() throws Exception {
   conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
   conversionService.addConverterFactory(new StringToNumberConverterFactory());
   List<String> list = new ArrayList<String>();
   TypeDescriptor sourceType = TypeDescriptor.forObject(list);
   TypeDescriptor targetType = new TypeDescriptor(getClass().getField("emptyListTarget"));
   assertTrue(conversionService.canConvert(sourceType, targetType));
   assertEquals(list, conversionService.convert(list, sourceType, targetType));
 }
 @Test
 @SuppressWarnings("unchecked")
 public void arrayCollectionToObjectInteraction() throws Exception {
   List<String>[] array = new List[2];
   array[0] = Arrays.asList("9", "12");
   array[1] = Arrays.asList("37", "23");
   conversionService.addConverter(new ArrayToCollectionConverter(conversionService));
   conversionService.addConverter(new CollectionToObjectConverter(conversionService));
   assertTrue(conversionService.canConvert(String[].class, List.class));
   assertEquals(Arrays.asList(array), conversionService.convert(array, List.class));
 }
 @Test
 public void emptyListToListDifferentTargetType() throws Exception {
   conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
   conversionService.addConverterFactory(new StringToNumberConverterFactory());
   List<String> list = new ArrayList<String>();
   TypeDescriptor sourceType = TypeDescriptor.forObject(list);
   TypeDescriptor targetType = new TypeDescriptor(getClass().getField("emptyListDifferentTarget"));
   assertTrue(conversionService.canConvert(sourceType, targetType));
   @SuppressWarnings("unchecked")
   LinkedList<Integer> result =
       (LinkedList<Integer>) conversionService.convert(list, sourceType, targetType);
   assertEquals(LinkedList.class, result.getClass());
   assertTrue(result.isEmpty());
 }
 @Test
 public void listToCollectionNoCopyRequired() throws NoSuchFieldException {
   List<?> input = new ArrayList<String>(Arrays.asList("foo", "bar"));
   assertSame(
       input,
       conversionService.convert(
           input,
           TypeDescriptor.forObject(input),
           new TypeDescriptor(getClass().getField("wildCardCollection"))));
 }
 @Test
 @SuppressWarnings("unchecked")
 public void objectToCollection() throws Exception {
   List<List<String>> list = new ArrayList<List<String>>();
   list.add(Arrays.asList("9", "12"));
   list.add(Arrays.asList("37", "23"));
   conversionService.addConverterFactory(new StringToNumberConverterFactory());
   conversionService.addConverter(new ObjectToCollectionConverter(conversionService));
   conversionService.addConverter(new CollectionToObjectConverter(conversionService));
   TypeDescriptor sourceType = TypeDescriptor.forObject(list);
   TypeDescriptor targetType = new TypeDescriptor(getClass().getField("objectToCollection"));
   assertTrue(conversionService.canConvert(sourceType, targetType));
   List<List<List<Integer>>> result =
       (List<List<List<Integer>>>) conversionService.convert(list, sourceType, targetType);
   assertEquals((Integer) 9, result.get(0).get(0).get(0));
   assertEquals((Integer) 12, result.get(0).get(1).get(0));
   assertEquals((Integer) 37, result.get(1).get(0).get(0));
   assertEquals((Integer) 23, result.get(1).get(1).get(0));
 }
 @Test(expected = ConversionFailedException.class)
 public void nothingInCommon() throws Exception {
   List<Object> resources = new ArrayList<Object>();
   resources.add(new ClassPathResource("test"));
   resources.add(3);
   TypeDescriptor sourceType = TypeDescriptor.forObject(resources);
   assertEquals(
       resources,
       conversionService.convert(
           resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
 }
 @Test(expected = ConverterNotFoundException.class)
 public void elementTypesNotConvertible() throws Exception {
   List<String> resources = new ArrayList<String>();
   resources.add(null);
   resources.add(null);
   TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings"));
   assertEquals(
       resources,
       conversionService.convert(
           resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
 }
 @Test
 public void allNulls() throws Exception {
   List<Resource> resources = new ArrayList<Resource>();
   resources.add(null);
   resources.add(null);
   TypeDescriptor sourceType = TypeDescriptor.forObject(resources);
   assertSame(
       resources,
       conversionService.convert(
           resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
 }
 @Test
 public void scalarList() throws Exception {
   List<String> list = new ArrayList<String>();
   list.add("9");
   list.add("37");
   TypeDescriptor sourceType = TypeDescriptor.forObject(list);
   TypeDescriptor targetType = new TypeDescriptor(getClass().getField("scalarListTarget"));
   assertTrue(conversionService.canConvert(sourceType, targetType));
   try {
     conversionService.convert(list, sourceType, targetType);
   } catch (ConversionFailedException ex) {
     assertTrue(ex.getCause() instanceof ConverterNotFoundException);
   }
   conversionService.addConverterFactory(new StringToNumberConverterFactory());
   assertTrue(conversionService.canConvert(sourceType, targetType));
   @SuppressWarnings("unchecked")
   List<String> result = (List<String>) conversionService.convert(list, sourceType, targetType);
   assertFalse(list.equals(result));
   assertEquals(9, result.get(0));
   assertEquals(37, result.get(1));
 }
 @Test
 public void differentImpls() throws Exception {
   List<Resource> resources = new ArrayList<Resource>();
   resources.add(new ClassPathResource("test"));
   resources.add(new FileSystemResource("test"));
   resources.add(new TestResource());
   TypeDescriptor sourceType = TypeDescriptor.forObject(resources);
   assertSame(
       resources,
       conversionService.convert(
           resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
 }
 @Before
 public void setUp() {
   conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
 }