ModuleHandler { public List<DbLicense> getModuleLicenses(final String moduleId, final LicenseMatcher licenseMatcher) { final DbModule module = getModule(moduleId); final List<DbLicense> licenses = new ArrayList<>(); final FiltersHolder filters = new FiltersHolder(); final ArtifactHandler artifactHandler = new ArtifactHandler(repositoryHandler, licenseMatcher); for (final String gavc : DataUtils.getAllArtifacts(module)) { licenses.addAll(artifactHandler.getArtifactLicenses(gavc, filters)); } return licenses; } ModuleHandler(final RepositoryHandler repositoryHandler); void store(final DbModule dbModule); List<String> getModuleNames(final FiltersHolder filters); List<String> getModuleVersions(final String name, final FiltersHolder filters); DbModule getModule(final String moduleId); void deleteModule(final String moduleId); List<DbLicense> getModuleLicenses(final String moduleId,
                                             final LicenseMatcher licenseMatcher); void promoteModule(final String moduleId); PromotionReportView getPromotionReport(final String moduleId); DbOrganization getOrganization(final DbModule module); List<DbModule> getModules(final FiltersHolder filters);  }
@Test public void getModuleLicenses(){ final DbModule module = new DbModule(); module.setName("module"); module.setVersion("1.0.0-SNAPSHOT"); final DbArtifact artifact1 = new DbArtifact(); artifact1.setArtifactId("artifact1"); artifact1.setVersion("1.0.0-SNAPSHOT"); module.addArtifact(artifact1); final DbLicense license = new DbLicense(); license.setName("test"); license.setLongName("License for Grapes tests"); artifact1.addLicense(license); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getModule(module.getId())).thenReturn(module); when(repositoryHandler.getArtifact(artifact1.getGavc())).thenReturn(artifact1); final ModuleHandler sut = new ModuleHandler(repositoryHandler); LicenseMatcher licenseMatcherMock = mock(LicenseMatcher.class); when(licenseMatcherMock.getMatchingLicenses(license.getName())).thenReturn(asSet(license)); final List<DbLicense> licenses = sut.getModuleLicenses(module.getId(), licenseMatcherMock); assertNotNull(licenses); assertEquals(1, licenses.size()); assertEquals(license, licenses.get(0)); }