LocalTimeConverter implements Converter<LocalTime> { public LocalTime convert(String value, Class<? extends LocalTime> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortTime()); if (out == null) { return null; } return out.toLocalTime(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_time"), value)); } } LocalTimeConverter(Localization localization); LocalTime convert(String value, Class<? extends LocalTime> type, ResourceBundle bundle);  }
@Test public void shouldBeAbleToConvert() { when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")) .thenReturn("pt_br"); assertThat(converter.convert("15:38", LocalTime.class, bundle), is(equalTo(new LocalTime(15, 38)))); }
@Test public void shouldBeAbleToConvertEmpty() { assertThat(converter.convert("", LocalTime.class, bundle), is(nullValue())); }
@Test public void shouldBeAbleToConvertNull() { assertThat(converter.convert(null, LocalTime.class, bundle), is(nullValue())); }
@Test public void shouldThrowExceptionWhenUnableToParse() { when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")) .thenReturn("pt_br"); try { converter.convert("xx:yy:ff", LocalTime.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("xx:yy:ff is not a valid time."))); } }