0

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

Milan Panic
  • 473
  • 1
  • 9
  • 30
  • Is it just me sensing a contradiction here? First you say that `card.getForecastedEndDates().get(95L)` throws a `NullPointerException`, next you say it yields `Tue Oct 16 03:16:34 EEST 2018`. It can’t do both, at least not on the same call. – Ole V.V. Oct 02 '18 at 10:28
  • Strange: In the test, you use the key 95L, in your code snippet to set the values you use 50L. – jokster Oct 02 '18 at 10:29

0 Answers0