LicenseHandler implements LicenseMatcher { @Override public Set<DbLicense> getMatchingLicenses(String licenseString) { final List<DbLicense> allLicenses = repoHandler.getAllLicenses(); return allLicenses .stream() .filter(license -> licenseString.equalsIgnoreCase(license.getName()) || ( !license.getRegexp().isEmpty() && licenseString.matches(String.format("(?i:%s)", license.getRegexp())) ) ) .collect(Collectors.toSet()); } LicenseHandler(final RepositoryHandler repoHandler); void store(final DbLicense dbLicense); List<String> getLicensesNames(final FiltersHolder filters); DbLicense getLicense(final String name); void deleteLicense(final String licName); void approveLicense(final String name, final Boolean approved); DbLicense resolve(final String licenseId); List<License> getLicenses(); Set<DbLicense> resolveLicenses(List<String> licStrings); @Override Set<DbLicense> getMatchingLicenses(String licenseString);  }
@Test public void findMatchingLicenses(){ final DbLicense license = new DbLicense(); license.setName("LGPL-3.0"); license.setRegexp("((.*)(GNU)(.*)(lesser)(.*)|(LGPL)*)(?!.*(GPL|gpl|BSD|SQL|COMM|W|CC|GNU)).*(3)+(.*)"); final RepositoryHandler repoHandler = mock(RepositoryHandler.class); when(repoHandler.getAllLicenses()).thenReturn(Collections.singletonList(license)); final LicenseHandler licenseHandler = new LicenseHandler(repoHandler); assertEquals(1, licenseHandler.getMatchingLicenses("LGPL-3.0").size()); }