I'm unit testing a method that uses a Date and everyway I initialize it seems to cause a NPE when I pass it. The HashMap is initialized and I can see the value when I debug to know there is a date but at my put statement the Date just seems to through the exception.
EDIT
Map<Double, Date> actualTimes = new HashMap<>();
Date date = new Date();
testMethod() {
clearProductMaps();
calendar.set(Calendar.MONTH, Calendar.JULY);
calendar.set(Calendar.DAY_OF_MONTH, 21);
calendar.set(Calendar.YEAR, 2016);
date = calendar.getTime();
try {
date = sdf.parse("2016-10-15");
} catch(ParseException ex) {
System.out.println("ParseException " + ex);
}
System.out.println("Debug:" + " " + sdf.format(date).toString());
if(date != null) {
actualTimes.put(1.50, date);
}
//assertTest call
}
I don't need the date formatted to be apart of the map and I have gotten strange responses with my null conditional check so I'm not what I'm doing wrong.