ConvertUtilsConverter implements Converter, Initializable { private <T> T convert(Class<T> targetType, Object sourceValue) { T result; try { result = (T) ConvertUtils.convert(sourceValue, targetType); } catch (ConversionException ex) { throw new org.xwiki.properties.converter.ConversionException("Error while performing type conversion", ex); } if (result == null) { return null; } if (!TypeUtils.isAssignable(targetType, result.getClass())) { throw new org.xwiki.properties.converter.ConversionException( String.format("Failed to find a Converter to convert from [%s] to [%s]", sourceValue.getClass().getName(), targetType.getName())); } return result; }  @Override void initialize(); @Override Object convert(Type targetType, Object sourceValue);  }
@Test void convert() throws SecurityException { assertEquals(Integer.valueOf(42), this.converter.convert(Integer.class, "42")); }
@Test void convertArrays() throws SecurityException, NoSuchFieldException { assertArrayEquals(new int[] {1, 2, 3}, this.converter.<int[]>convert(int[].class, "1, 2, 3")); assertArrayEquals(new Integer[] {1, 2, 3}, this.converter.<Integer[]>convert(Integer[].class, "1, 2, 3")); assertArrayEquals(new Integer[] {1, 2, 3}, this.converter .<Integer[]>convert(ConvertUtilsConverterTest.class.getField("field").getGenericType(), "1, 2, 3")); }
@Test void convertWhenNoConverterAvailable() { assertThrows(ConversionException.class, () -> this.converter.convert(ConvertUtilsConverter.class, ""), "Failed to find a Converter to convert from [java.lang.String] to " + "[" + ConvertUtilsConverter.class.getName() + "]"); }
@Test void convertNull() { assertNull(this.converter.convert(String.class, null)); }