I have a HashMap<Long, Date> forecastedEndDates
. It is in a field class named Card
.
In my JUnit test
I want to assertEquals
my Date and a Date from the map, but
on
date1 = card.getForecastedEndDates().get(95L);
line, it givens me a null pointer exception. I have declared and initialized the date as:
Date date1 = new Date()
I can't go and change Date to Calendar or Time, because it is too big of a project.
I have a suspicion that there is a format mismatch. When I println
Date.getTime()
, I get 1538473954932
and when I do:
Card card = new Card();
card.getForecastedEndDates().get(95L);
I get: Tue Oct 16 03:16:34 EEST 2018
I fill in the map with:
Map<Long, Date> forecastedEndDates = new HashMap<Long, Date>();
forecastedEndDates.put(50L,
Date.from(LocalDateTime.now(ZoneOffset.UTC)
.plus(Math.round(forecast.getSimulation().getMedian() * DAY_IN_MILISECONDS), ChronoUnit.MILLIS)
.toInstant(ZoneOffset.UTC)));
The 50L is the key and the Date is value