I have this code to parse a big-endian-date String to a Date :
public static final Date fromBigEndian(String dateBigEndian) {
DateFormat bigEndianFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
return bigEndianFormat.parse(dateBigEndian);
} catch (ParseException e) {
return null;
}
}
and this test case:
@Test
public void returnNullIfDoesNotMatchBigEndianFormat() {
String nonBigEndianDate = "01-06-2016";
Date parsedDate = DateUtil.fromBigEndian(nonBigEndianDate);
assertNull(parsedDate);
}
But it fails. It is returning a Date instead of null, but format of "01-06-2016"
doesn't match with the pattern "yyyy-MM-dd"
. Why doesn't the method throw ParseException
?