ClassNameConverter implements Converter<ClassName> { @Override public ClassName convertFromText(String value, Class<?> targetType, String optionContext) { int index = value.indexOf('{'); if (index < 0) { return new ClassName(value); } else { String className = value.substring(0, index); String json = value.substring(index); return new ClassName(className, json); } }  @Override boolean supports(Class<?> type, String optionContext); @Override ClassName convertFromText(String value, Class<?> targetType, String optionContext); @Override boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType,
      String existingData, String optionContext, MethodTarget target);  }
@Test public void convertClassOnly() { ClassName declarable = converter.convertFromText("abc", ClassName.class, ""); assertThat(declarable.getClassName()).isEqualTo("abc"); assertThat(declarable.getInitProperties()).isEmpty(); }
@Test public void convertClassAndEmptyProp() { ClassName declarable = converter.convertFromText("abc{}", ClassName.class, ""); assertThat(declarable.getClassName()).isEqualTo("abc"); assertThat(declarable.getInitProperties()).isEmpty(); }
@Test public void convertWithOnlyDelimiter() { assertThat(converter.convertFromText("{}", ClassName.class, "")).isEqualTo(ClassName.EMPTY); }
@Test public void convertWithInvalidClassName() { assertThatThrownBy(() -> converter.convertFromText("abc?{}", ClassName.class, "")) .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Invalid className"); }
@Test public void convertWithEmptyString() { ClassName className = converter.convertFromText("", ClassName.class, ""); assertThat(className).isEqualTo(ClassName.EMPTY); }
@Test public void convertClassAndProperties() { String json = "{'k1':'v1','k2':'v2'}"; ClassName declarable = converter.convertFromText("abc" + json, ClassName.class, ""); assertThat(declarable.getClassName()).isEqualTo("abc"); assertThat(declarable.getInitProperties()).containsOnlyKeys("k1", "k2") .containsEntry("k1", "v1").containsEntry("k2", "v2"); }
@Test public void convertClassAndPropertiesWithDoubleQuotes() { String json = "{\"k1\":\"v1\",\"k2\":\"v2\"}"; ClassName declarable = converter.convertFromText("abc" + json, ClassName.class, ""); assertThat(declarable.getClassName()).isEqualTo("abc"); assertThat(declarable.getInitProperties()).containsOnlyKeys("k1", "k2") .containsEntry("k1", "v1").containsEntry("k2", "v2"); }