StatisticsActionUtil { public static Map<String, Long> getDefaultMap(TimeRangedStatisticsRequest request) { Validate.notNull(request); final int duration = Days.daysBetween(request.getStartDate().toInstant(), request.getEndDate().toInstant()).getDays(); final Map<String, Long> resultMap = new LinkedHashMap<>(); for (int i = 0; i < duration; i++) { resultMap.put(formatDate(request.getStartDate().plusDays(i)), 0L); } return resultMap; }  static String formatDate(DateTime dateTime); static Map<String, Long> getDefaultMap(TimeRangedStatisticsRequest request); static Map<String, Long> fillMap(Map<String, Long> defaultMap, Map<String, Long> mapToFill);  }
@Test public void getDefaultMap_should_return_one_by_same_day() { assertThat(getDefaultMap(new TimeRangedStatisticsRequest(DateTime.now(), DateTime.now())).size(), is(1)); }
@Test public void getDefaultMap_should_return_map_with_entry_for_each_day_bounds_inclusive() { DateTime startDate = DateTime.now(); DateTime endDate = startDate.plusDays(10); Map<String, Long> result = getDefaultMap(new TimeRangedStatisticsRequest(startDate, endDate)); assertThat(result.size(), is(11)); assertThat(result, hasKey(startDate.toString("yyyy-MM-dd"))); assertThat(result, hasKey(endDate.toString("yyyy-MM-dd"))); for(Map.Entry entry : result.entrySet()) { assertThat(entry.getValue(), is(0L)); } }
@Test(expected = NullPointerException.class) public void getDefaultMap_should_throw_nullpointerexception_on_null_parameter() { getDefaultMap(null); }