VulnerabilityConnector { public Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilitiesAndSetIds(List<Vulnerability> vulnerabilities) { Map<UpdateType, List<Vulnerability>> statusToVulnerabilities = new HashMap<>(); for (UpdateType updateType: UpdateType.values()){ statusToVulnerabilities.put(updateType, new ArrayList<>()); } for (Vulnerability vulnerability : vulnerabilities) { statusToVulnerabilities = addOrUpdateVulnerabilityAndSetId(vulnerability, statusToVulnerabilities); } return statusToVulnerabilities; } VulnerabilityConnector(); Optional<Release> getRelease(String releaseId); Optional<Component> getComponent(String componentId); Optional<Project> getProject(String projectId); List<Release> getAllReleases(); boolean isMoreRecent(Vulnerability vulnerability, Vulnerability other); RequestStatus addOrUpdate(ReleaseVulnerabilityRelation partiallyFilledRelation); UpdateType addOrUpdate(Vulnerability vulnerability, ReleaseVulnerabilityRelation partiallyFilledRelation); VulnerabilityUpdateStatus addOrUpdate(Vulnerability vulnerability,
                                                 ReleaseVulnerabilityRelation partiallyFilledRelation,
                                                 VulnerabilityUpdateStatus currentVulnerabilityUpdateStatus); Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilityAndSetId(
            Vulnerability vulnerability,
            Map<UpdateType, List<Vulnerability>> statusToVulnerabilities); Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilitiesAndSetIds(List<Vulnerability> vulnerabilities); RequestStatus addReleaseVulnerabilityRelationsIfNecessary(String releaseId, List<String> vulnerabilityIds); RequestStatus addReleaseVulnerabilityRelationsIfNecessary(String releaseId, Map<String,List<String>> needleToVulnerabilityIds);  }
@Test public void testaddOrUpdateVulnerabilitiesAndSetIds(){ Vulnerability v1 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv1").setExternalId("eid1"); Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid2"); Vulnerability v3= new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv3").setExternalId("eid1"); Vulnerability v4 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv4").setExternalId("eid2"); Vulnerability v5 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv5").setExternalId("eid5"); List<Vulnerability> vulnerabilityList = Arrays.asList(v3,v4,v5); when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid1")).thenReturn(v1); when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid2")).thenReturn(v2); when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid5")).thenReturn(null); when(vulnerabilityDatabaseHandler.add(v5)).thenReturn(RequestStatus.SUCCESS); when(vulnerabilityDatabaseHandler.update(v1)).thenReturn(RequestStatus.SUCCESS); Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilitiesAndSetIds(vulnerabilityList); assertThat(resultMap.get(UpdateType.UPDATED).get(0).getId(), is("idv1")); assertThat(resultMap.get(UpdateType.NEW).get(0).getId(), is("idv5")); assertThat(resultMap.get(UpdateType.OLD).get(0).getId(), is("idv2")); assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST)); }