SW360MetaDataUpdater { public Set<SW360License> getLicenses(Collection<License> licenses) { return licenses.stream() .filter(this::isLicenseInSW360) .map(license -> licenseClientAdapter.getLicenseByName(license.getId())) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toSet()); } SW360MetaDataUpdater(SW360Connection connection); Set<SW360License> getLicenses(Collection<License> licenses); SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting); void createProject(String projectName, String projectVersion, Collection<SW360Release> releases); AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release,
                                                                  Map<Path, SW360AttachmentType> attachments,
                                                                  boolean force); SW360Release deleteSourceAttachments(SW360Release release); SW360Release deleteAttachments(SW360Release release, Predicate<SW360SparseAttachment> filter);  }
@Test public void testGetLicensesWithExistingLicense() { final String licenseName = "licenseName"; List<SW360SparseLicense> testLicenses = createTestLicenses(); testLicenses.add(createLicense(licenseName)); final SW360License license = new SW360License() .setShortName(licenseName); License licenseAntenna = new License(); licenseAntenna.setId(licenseName); when(licenseClientAdapter.getLicenses()).thenReturn(testLicenses); when(licenseClientAdapter.getLicenseByName(licenseName)) .thenReturn(Optional.of(license)); final Set<SW360License> licenses = metaDataUpdater.getLicenses(Collections.singletonList(licenseAntenna)); assertThat(licenses).hasSize(1); verify(licenseClientAdapter, times(1)).getLicenses(); verify(licenseClientAdapter, times(1)).getLicenseByName(licenseName); }
@Test public void testGetLicensesWithNonExistingLicense() { final String licenseName = "licenseName"; final SW360License license = new SW360License() .setShortName(licenseName); License licenseAntenna = new License(); licenseAntenna.setId(licenseName); when(licenseClientAdapter.getLicenses()) .thenReturn(createTestLicenses()); when(licenseClientAdapter.getLicenseByName(licenseName)) .thenReturn(Optional.of(license)); final Set<SW360License> licenses = metaDataUpdater.getLicenses(Collections.singletonList(licenseAntenna)); assertThat(licenses).hasSize(0); verify(licenseClientAdapter, times(1)).getLicenses(); }