LocalTimeConverter implements PropertyConverter<LocalTime> { @Override public LocalTime convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), LocalTime.now().toString()); if(value==null){ return null; } try{ return LocalTime.parse(value); }catch(Exception e){ LOG.log(Level.FINEST, e, () -> "Cannot parse LocalTime: " + value); return null; } }  @Override LocalTime convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void convert() throws Exception { LocalTimeConverter conv = new LocalTimeConverter(); LocalTime value = conv.convert("10:15:30", context); assertThat(LocalTime.parse("10:15:30")).isEqualTo(value); value = conv.convert("foo", context); assertThat(value).isNull(); }
@Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(LocalTime.class)).build(); LocalTimeConverter converter = new LocalTimeConverter(); converter.convert("", context); assertThat(context.getSupportedFormats().toString()).contains(" (LocalTimeConverter)"); }