DefaultConverterManager implements ConverterManager { @Override public <T> T convert(Type targetType, Object value) { if (targetType instanceof Class && ((Class<?>) targetType).isInstance(value)) { return (T) value; } if (targetType instanceof WildcardType) { Type[] upperBounds = ((WildcardType) targetType).getUpperBounds(); if (upperBounds.length == 0) { return (T) value; } else { return convert(upperBounds[0], value); } } Type converterType = targetType; if (converterType == String.class && value != null) { converterType = value.getClass(); } Converter<T> converter = lookupConverter(converterType); if (converter != null) { return converter.convert(targetType, value); } else { throw new ConversionException( "Cannot find Converter to convert value [" + value + "] to type [" + targetType + "] "); } }  @Override T convert(Type targetType, Object value); @Override Converter<T> getConverter(Type targetType);  }
@Test void convert() { assertEquals(Integer.valueOf(42), this.converterManager.convert(Integer.class, "42")); }
@Test void convertEnum() { assertEquals(TestEnum.ENUMVALUE, this.converterManager.convert(TestEnum.class, "ENUMVALUE")); }
@Test void convertColor() { assertEquals(Color.WHITE, this.converterManager.convert(Color.class, "#ffffff")); }
@Test void convertUnsupportedType() { Throwable exception = assertThrows(ConversionException.class, () -> this.converterManager.convert(DefaultConverterManagerTest.class, "#ffffff")); assertEquals("Failed to find a Converter to convert from [java.lang.String] to " + "[org.xwiki.properties.internal.DefaultConverterManagerTest]", exception.getMessage()); }
@Test void convertSame() { assertSame(Color.WHITE, this.converterManager.convert(Color.class, Color.WHITE)); }