DateTimeConverter implements Converter<DateTime> { public DateTime convert(String value, Class<? extends DateTime> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDateTime()); if (out == null) { return null; } return out.toDateTime(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } } DateTimeConverter(Localization localization); DateTime convert(String value, Class<? extends DateTime> type, ResourceBundle bundle);  }
@Test public void shouldBeAbleToConvert() { when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")) .thenReturn("pt_br"); assertThat(converter.convert("05/06/2010 3:38", DateTime.class, bundle), is(equalTo(new DateTime(2010, 6, 5, 3, 38, 0, 0)))); }
@Test public void shouldBeAbleToConvertEmpty() { assertThat(converter.convert("", DateTime.class, bundle), is(nullValue())); }
@Test public void shouldBeAbleToConvertNull() { assertThat(converter.convert(null, DateTime.class, bundle), is(nullValue())); }
@Test public void shouldThrowExceptionWhenUnableToParse() { when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")) .thenReturn("pt_br"); try { converter.convert("a,10/06/2008/a/b/c", DateTime.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("a,10/06/2008/a/b/c is not a valid datetime."))); } }