VulnerabilityUtils { public static VulnerabilityUpdateStatus getUpdateStatusFromUpdateMap(Map<UpdateType, List<Vulnerability>> statusToVulnerabilities){ VulnerabilityUpdateStatus status = getEmptyVulnerabilityUpdateStatus(); status.requestStatus = nullToEmptyList(statusToVulnerabilities.get(UpdateType.FAILED)).size() > 0 ? RequestStatus.FAILURE : RequestStatus.SUCCESS; for(UpdateType updateType: UpdateType.values()){ List<String> idList = nullToEmptyList(statusToVulnerabilities.get(updateType)) .stream() .map(Vulnerability::getExternalId) .collect(Collectors.toList()); status.statusToVulnerabilityIds.get(updateType).addAll(idList); } return status; }  static VulnerabilityUpdateStatus getEmptyVulnerabilityUpdateStatus(RequestStatus requestStatus); static VulnerabilityUpdateStatus getEmptyVulnerabilityUpdateStatus(); static VulnerabilityUpdateStatus reduceVulnerabilityUpdateStatus(VulnerabilityUpdateStatus ... statuses); static VulnerabilityUpdateStatus getUpdateStatusFromUpdateMap(Map<UpdateType, List<Vulnerability>> statusToVulnerabilities); static List<String> successIdsFromUpdateMap(Map<UpdateType, List<Vulnerability>> updateMap);  }
@Test public void getUpdateStatusFromUpdateMapEmpty() throws Exception { VulnerabilityUpdateStatus result = getUpdateStatusFromUpdateMap(new HashMap<>()); assertThat(result.getRequestStatus(), is(RequestStatus.SUCCESS)); assertThat(result.statusToVulnerabilityIds.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST)); assertThat(result.statusToVulnerabilityIds.get(UpdateType.NEW), is(Collections.EMPTY_LIST)); }
@Test public void getUpdateStatusFromUpdateMapSuccess() throws Exception { VulnerabilityUpdateStatus result = getUpdateStatusFromUpdateMap(updateMap); assertThat(result.getRequestStatus(), is(RequestStatus.SUCCESS)); assertThat(result.statusToVulnerabilityIds.get(UpdateType.UPDATED), containsInAnyOrder("ue1", "ue2", "ue3")); assertThat(result.statusToVulnerabilityIds.get(UpdateType.NEW), containsInAnyOrder("ne1", "ne2")); }
@Test public void getUpdateStatusFromUpdateMapFailure() throws Exception { VulnerabilityUpdateStatus result = getUpdateStatusFromUpdateMap(failedUpdateMap); assertThat(result.getRequestStatus(), is(RequestStatus.FAILURE)); assertThat(result.statusToVulnerabilityIds.get(UpdateType.UPDATED), containsInAnyOrder("ue1", "ue2", "ue3")); assertThat(result.statusToVulnerabilityIds.get(UpdateType.NEW), containsInAnyOrder("ne1", "ne2")); assertThat(result.statusToVulnerabilityIds.get(UpdateType.OLD), containsInAnyOrder("oe1", "oe2", "oe3")); assertThat(result.statusToVulnerabilityIds.get(UpdateType.FAILED), containsInAnyOrder("fe1", "fe2", "fe3")); }