ConfigPropertyConverter implements Converter<JndiBindingsType.JndiBinding.ConfigProperty> { @Override public JndiBindingsType.JndiBinding.ConfigProperty convertFromText(String value, Class<?> targetType, String optionContext) { try { return mapper.readValue(value, JndiBindingsType.JndiBinding.ConfigProperty.class); } catch (IOException e) { throw new IllegalArgumentException("invalid json: " + value); } }  @Override boolean supports(Class<?> type, String optionContext); @Override JndiBindingsType.JndiBinding.ConfigProperty convertFromText(String value,
      Class<?> targetType, String optionContext); @Override boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType,
      String existingData, String optionContext, MethodTarget target);  }
@Test public void validJson() { JndiBindingsType.JndiBinding.ConfigProperty configProperty = converter.convertFromText("{'name':'name','type':'type','value':'value'}", null, null); assertThat(configProperty.getName()).isEqualTo("name"); assertThat(configProperty.getType()).isEqualTo("type"); assertThat(configProperty.getValue()).isEqualTo("value"); }
@Test public void invalidJson() { assertThatThrownBy(() -> converter.convertFromText( "{'name':'name','type':'type','value':'value','another':'another'}", null, null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void invalidWhenEmptyString() { assertThatThrownBy(() -> converter.convertFromText("", null, null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void validWhenTypeMissing() { JndiBindingsType.JndiBinding.ConfigProperty configProperty = converter.convertFromText("{'name':'name','value':'value'}", null, null); assertThat(configProperty.getName()).isEqualTo("name"); assertThat(configProperty.getType()).isNull(); assertThat(configProperty.getValue()).isEqualTo("value"); }
@Test public void inValidWhenTypo() { assertThatThrownBy(() -> converter .convertFromText("{'name':'name','typo':'type','value':'value'}", null, null)) .isInstanceOf(IllegalArgumentException.class);; }