VulnerabilityUtils { public static VulnerabilityUpdateStatus reduceVulnerabilityUpdateStatus(VulnerabilityUpdateStatus ... statuses){ VulnerabilityUpdateStatus resultStatus = getEmptyVulnerabilityUpdateStatus(); RequestStatus requestStatus = Arrays.stream(statuses) .map(VulnerabilityUpdateStatus::getRequestStatus) .reduce(RequestStatus.SUCCESS, CommonUtils::reduceRequestStatus); resultStatus.setRequestStatus(requestStatus); for(UpdateType updateType : UpdateType.values()) { for (VulnerabilityUpdateStatus status : statuses) { if(status.isSetStatusToVulnerabilityIds()) { resultStatus.statusToVulnerabilityIds.get(updateType) .addAll(nullToEmptyList(status.statusToVulnerabilityIds.get(updateType))); } } } return resultStatus; }  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 testReduceVulnerabilityUpdateStatusEmptySingle() throws Exception { assertThat(reduceVulnerabilityUpdateStatus(emptyVus).requestStatus, is(RequestStatus.SUCCESS)); assertThat(reduceVulnerabilityUpdateStatus(emptyVus).statusToVulnerabilityIds.get(UpdateType.NEW), is(Collections.EMPTY_LIST)); }
@Test public void testReduceVulnerabilityUpdateStatusSingle() throws Exception { assertThat(reduceVulnerabilityUpdateStatus(vus1).getRequestStatus(), is(RequestStatus.SUCCESS)); assertThat(reduceVulnerabilityUpdateStatus(vus1).statusToVulnerabilityIds.get(UpdateType.UPDATED), is(vus1.statusToVulnerabilityIds.get(UpdateType.UPDATED))); assertThat(reduceVulnerabilityUpdateStatus(vus1).statusToVulnerabilityIds.get(UpdateType.FAILED), is(vus1.statusToVulnerabilityIds.get(UpdateType.FAILED))); }
@Test public void testReduceVulnerabilityUpdateStatusTwoWithFirstEmpty() throws Exception { assertThat(reduceVulnerabilityUpdateStatus(emptyVus, vus1).getRequestStatus(), is(RequestStatus.SUCCESS)); assertThat(reduceVulnerabilityUpdateStatus(emptyVus, vus1).statusToVulnerabilityIds.get(UpdateType.UPDATED), is(vus1.statusToVulnerabilityIds.get(UpdateType.UPDATED))); assertThat(reduceVulnerabilityUpdateStatus(emptyVus, vus1).statusToVulnerabilityIds.get(UpdateType.FAILED), is(vus1.statusToVulnerabilityIds.get(UpdateType.FAILED))); }
@Test public void testReduceVulnerabilityUpdateStatusTwoWithSecondEmpty() throws Exception { assertThat(reduceVulnerabilityUpdateStatus(vus1, emptyVus).getRequestStatus(), is(RequestStatus.SUCCESS)); assertThat(reduceVulnerabilityUpdateStatus(vus1, emptyVus).statusToVulnerabilityIds.get(UpdateType.UPDATED), is(vus1.statusToVulnerabilityIds.get(UpdateType.UPDATED))); assertThat(reduceVulnerabilityUpdateStatus(vus1, emptyVus).statusToVulnerabilityIds.get(UpdateType.FAILED), is(vus1.statusToVulnerabilityIds.get(UpdateType.FAILED))); }
@Test public void testReduceVulnerabilityUpdateStatusFull() throws Exception { assertThat(reduceVulnerabilityUpdateStatus(vus1, vus2, vus3).requestStatus, is(RequestStatus.FAILURE)); assertThat(reduceVulnerabilityUpdateStatus(vus1, vus2, vus3).statusToVulnerabilityIds.get(UpdateType.FAILED), containsInAnyOrder("id0", "id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8")); assertThat(reduceVulnerabilityUpdateStatus(vus1, vus2, vus3).statusToVulnerabilityIds.get(UpdateType.UPDATED), containsInAnyOrder("id0", "id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8")); assertThat(reduceVulnerabilityUpdateStatus(vus1, vus2, vus3).statusToVulnerabilityIds.get(UpdateType.NEW), containsInAnyOrder("id0", "id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8")); assertThat(reduceVulnerabilityUpdateStatus(vus1, vus2, vus3).statusToVulnerabilityIds.get(UpdateType.OLD), containsInAnyOrder("id0", "id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8")); }