@Test(expected = ConfigException.class) public void emulateExceptionWhenGivenContextIsNull() { ConversionContext context = Mockito.mock(ConversionContext.class); new OptionalConverter().convert("JustATestValueThatIsIgnored", context); }
@Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } } }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }  }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }  @Override Optional convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode(); }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }  @Override Optional convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }