StringToJodaTimeBaseLocalConverter extends AbstractConverter { @Override public Object convert(Object source, TypeToken<?> targetTypeToken) { if (!canHandle(source, targetTypeToken)) { throw new ConverterException(source, targetTypeToken.getRawType()); } Date date = stringToDateConverter.convert(String.valueOf(source)); return dateToJodaTimeBaseLocalConverter.convert(date, targetTypeToken); }  @Override Object convert(Object source, TypeToken<?> targetTypeToken); @Override boolean canHandle(Object source, TypeToken<?> targetTypeToken);  }
@Test public void convert() throws Exception { String dateString = "1985-09-03 13:30"; LocalTime localTime = (LocalTime) converter.convert(dateString, TypeToken.of(LocalTime.class)); assertEquals(13, localTime.getHourOfDay()); assertEquals(30, localTime.getMinuteOfHour()); LocalDate localDate = (LocalDate) converter.convert(dateString, TypeToken.of(LocalDate.class)); assertEquals(1985, localDate.getYear()); assertEquals(9, localDate.getMonthOfYear()); assertEquals(3, localDate.getDayOfMonth()); LocalDateTime localDateTime = (LocalDateTime) converter.convert(dateString, TypeToken.of(LocalDateTime.class)); assertEquals(13, localDateTime.getHourOfDay()); assertEquals(30, localDateTime.getMinuteOfHour()); assertEquals(1985, localDateTime.getYear()); assertEquals(9, localDateTime.getMonthOfYear()); assertEquals(3, localDateTime.getDayOfMonth()); }
@Test(expected = ConverterException.class) public void testConvertExceptionBySource() { converter.convert(new Date(), TypeToken.of(LocalTime.class)); }
@Test(expected = ConverterException.class) public void testConvertExceptionByDest() { converter.convert("2017-09-03", TypeToken.of(Duration.class)); }