StatisticsActionUtil { public static Map<String, Long> fillMap(Map<String, Long> defaultMap, Map<String, Long> mapToFill) { notNull(defaultMap, "defaultMap should not be null"); notNull(mapToFill, "mapToFill should not be null"); isTrue(defaultMap.size() >= mapToFill.size(), "default map should not have less element than mapToFill, so that the result should contain all the elements of both maps"); final Map<String, Long> resultMap = new LinkedHashMap<>(); defaultMap.forEach((k, v) -> resultMap.merge(k, v, Long::max)); mapToFill.forEach((k, v) -> resultMap.merge(k, v, Long::max)); 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(expected = IllegalArgumentException.class) public void fillMap_should_throw_exception_if_defaultMap_is_smaller_than_mapToFill() { final Map<String, Long> defaultMap = new HashMap<>(); defaultMap.put("1", 0L); final Map<String, Long> mapToFill = new HashMap<>(); mapToFill.put("2", 0L); mapToFill.put("3", 0L); fillMap(defaultMap, mapToFill); }
@Test(expected = NullPointerException.class) public void fillMap_should_throw_exception_if_defaultMap_is_null() { final Map<String, Long> mapToFill = new HashMap<>(); mapToFill.put("2", 0L); mapToFill.put("3", 0L); fillMap(null, mapToFill); }
@Test(expected = NullPointerException.class) public void fillMap_should_throw_exception_if_mapToFill_is_null() { final Map<String, Long> defaultMap = new HashMap<>(); defaultMap.put("1", 0L); fillMap(defaultMap, null); }
@Test public void fillMap_should_return_default_map_if_mapToFill_is_empty() { final Map<String, Long> defaultMap = new HashMap<>(); defaultMap.put("1", 0L); final Map<String, Long> mapToFill = new HashMap<>(); Map<String, Long> result = fillMap(defaultMap, mapToFill); assertThat(result.entrySet(), hasSize(1)); }
@Test public void fillMap_should_return_merged_map_from_both_maps() { final Map<String, Long> defaultMap = new HashMap<>(); defaultMap.put("1", 0L); defaultMap.put("2", 0L); defaultMap.put("3", 0L); final Map<String, Long> mapToFill = new HashMap<>(); mapToFill.put("2", 2L); Map<String, Long> result = fillMap(defaultMap, mapToFill); assertThat(result.entrySet(), hasSize(3)); assertThat(result.get("2"), is(2L)); assertThat(result.get("1"), is(0L)); assertThat(result.get("3"), is(0L)); }