### Question:
DateConverter implements Converter<Date> { @Override public Date convert(String toBeConverted) throws ConversionException { if (toBeConverted == null || toBeConverted.isEmpty()) { return null; } try { SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", DateFormatSymbols.getInstance(Locale.ENGLISH)); return formatter.parse(toBeConverted); } catch (ParseException e) { throw new ConversionException(toBeConverted + " cannot be converted to Date", e); } }  @Override Date convert(String toBeConverted);  }### Answer:
@Test public void nullIsConvertedToNull() throws Exception { Date converted = converter.convert(null); assertNull(converted); }
@Test public void emptyIsConvertedToNull() throws Exception { Date converted = converter.convert(""); assertNull(converted); }
@Test public void shouldConvertDateStringIntoDate() throws Exception { Calendar c = Calendar.getInstance(); int hourOfDay = 11; int minute = 43; int second = 30; int dayOfDateate = 18; int year = 2014; c.set(year, Calendar.AUGUST, dayOfDateate, hourOfDay, minute, second); String timeZone = "GMT"; c.setTimeZone(TimeZone.getTimeZone(timeZone)); c.set(Calendar.MILLISECOND, 0); Date date = c.getTime(); Date converted = converter.convert("Mon Aug " + dayOfDateate + " " + hourOfDay + ":" + minute + ":" + second + " " + timeZone + " " + year); assertEquals(date.toString() + " is not well converted", date, converted); }
@Test(expected = ConversionException.class) public void nonParsableStringThrowAConversionException() throws Exception { converter.convert("nonParsable"); }