LicenseHandler implements LicenseMatcher { public DbLicense getLicense(final String name) { final DbLicense license = repoHandler.getLicense(name); if (license == null) { throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) .entity("License " + name + " does not exist.").build()); } return license; } 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 getAnExistingLicense(){ final DbLicense license = new DbLicense(); license.setName("test"); license.setLongName("Grapes Test License"); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getLicense(license.getName())).thenReturn(license); final LicenseHandler handler = new LicenseHandler(repositoryHandler); final DbLicense gotLicense = handler.getLicense(license.getName()); assertNotNull(gotLicense); assertEquals(license, gotLicense); verify(repositoryHandler, times(1)).getLicense(license.getName()); }
@Test public void getALicenseThatDoesNotExist(){ final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final LicenseHandler handler = new LicenseHandler(repositoryHandler); WebApplicationException exception = null; try { handler.getLicense("doesNotExist"); }catch (WebApplicationException e){ exception = e; } assertNotNull(exception); Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), exception.getResponse().getStatus()); }