SupplierConverter implements PropertyConverter<Supplier> { @Override public Supplier convert(String value, ConversionContext context) { return () -> { try{ Type targetType = context.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return value; } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); Object o = context.getConfiguration().adapt(converter); if(o==null){ throw new ConfigException("No such createValue: " + context.getKey()); } return o; }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }; }  @Override Supplier convert(String value, ConversionContext context); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testConvert() { SupplierConverter instance = new SupplierConverter(); Supplier<String> stringResult; TypeLiteral listStringTypeLiteral = new TypeLiteral<List<String>> () {}; ConversionContext context = new ConversionContext.Builder(listStringTypeLiteral).build(); stringResult = instance.convert(null, context); assertThat(stringResult.get()).isNull(); stringResult = instance.convert("aString", context); assertThat(stringResult.get()).isEqualTo("aString"); Supplier<InetAddress> addressResult; Configuration mockConfig = Mockito.mock(Configuration.class); Mockito.when(mockConfig.adapt(any())).thenReturn(Mockito.mock(InetAddress.class)); TypeLiteral myConverterTypeLiteral = new TypeLiteral<MyConverter<InetAddress>> () {}; ConversionContext myConverterContext = new ConversionContext.Builder(myConverterTypeLiteral) .setConfiguration(mockConfig) .build(); addressResult = instance.convert("someKey", myConverterContext); assertThat(addressResult.get() instanceof InetAddress).isTrue(); }