ConverterHelper { TypeConverter getDefaultTypeConverter(Type toField, Type domainField) { for (TypeConverter typeConverter : typeConvertersInOrder) { if (typeConverter.canConvert(toField, domainField)) { return typeConverter; } } return new NoConversionTypeConverter(); }  ToConverter getToConverter(Class toClass, Class domainClass);  }
@Test public void testGetDefaultTypeConverterEmptyList() throws Exception { TypeConverter typeConverter = converterHelper.getDefaultTypeConverter(Object.class, Date.class); assertThat(typeConverter).isInstanceOf(NoConversionTypeConverter.class); }
@Test public void testGetDefaultTypeConverterMatchingConverter() throws Exception { TypeConverter typeConverter = mock(TypeConverter.class); when(typeConverter.canConvert(any(Class.class), any(Class.class))).thenReturn(true); ReflectionTestUtils.setField(converterHelper, "typeConvertersInOrder", Collections.singletonList(typeConverter)); TypeConverter result = converterHelper.getDefaultTypeConverter(Object.class, Date.class); assertThat(result).isEqualTo(typeConverter); }
@Test public void testGetDefaultTypeConverterNoMatchingConverter() throws Exception { List<TypeConverter> tcs = new ArrayList<>(); tcs.add(new DefaultTypeConverter()); tcs.add(new DefaultTypeConverter()); ReflectionTestUtils.setField(converterHelper, "typeConvertersInOrder", tcs); TypeConverter typeConverter = converterHelper.getDefaultTypeConverter(Object.class, Date.class); assertThat(typeConverter).isInstanceOf(NoConversionTypeConverter.class); }