DateMidnightConverter implements Converter<DateMidnight> { public DateMidnight convert(String value, Class<? extends DateMidnight> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDate()); if (out == null) { return null; } return out.toDateMidnight(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } } DateMidnightConverter(Localization localization); DateMidnight convert(String value, Class<? extends DateMidnight> 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", DateMidnight.class, bundle), is(equalTo(new DateMidnight(2010, 6, 5)))); }
@Test public void shouldBeAbleToConvertEmpty() { assertThat(converter.convert("", DateMidnight.class, bundle), is(nullValue())); }
@Test public void shouldBeAbleToConvertNull() { assertThat(converter.convert(null, DateMidnight.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", DateMidnight.class, bundle); } catch (ConversionError e) { assertThat(e.getMessage(), is(equalTo("a,10/06/2008/a/b/c is not a valid datetime."))); } }