ArtifactHandler { public DbArtifact getArtifact(final String gavc) { final DbArtifact artifact = repositoryHandler.getArtifact(gavc); if(artifact == null){ throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) .entity("Artifact " + gavc + " does not exist.").build()); } return artifact; } ArtifactHandler(final RepositoryHandler repositoryHandler,
                           final LicenseMatcher matcher); void store(final DbArtifact dbArtifact); void storeIfNew(final DbArtifact fromClient); void addLicense(final String gavc, final String licenseId); List<String> getArtifactGavcs(final FiltersHolder filters); List<String> getArtifactGroupIds(final FiltersHolder filters); List<String> getArtifactVersions(final String gavc); String getArtifactLastVersion(final String gavc); DbArtifact getArtifact(final String gavc); DbArtifact getArtifactUsingSHA256(final String sha256); DbModule getModule(final DbArtifact dbArtifact); DbOrganization getOrganization(final DbArtifact dbArtifact); void updateDownLoadUrl(final String gavc, final String downLoadUrl); void updateProvider(final String gavc, final String provider); void deleteArtifact(final String gavc); void updateDoNotUse(final String gavc, final Boolean doNotUse); List<DbModule> getAncestors(final String gavc, final FiltersHolder filters); List<DbLicense> getArtifactLicenses(final String gavc, final FiltersHolder filters); void addLicenseToArtifact(final String gavc, final String licenseId); void removeLicenseFromArtifact(final String gavc, final String licenseId); List<DbArtifact> getArtifacts(final FiltersHolder filters); String getModuleJenkinsJobInfo(final DbArtifact dbArtifact);  }
@Test public void getAnExistingArtifact(){ final DbArtifact artifact = new DbArtifact(); artifact.setArtifactId("test"); artifact.setVersion("1.0.0-SNAPSHOT"); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getArtifact(artifact.getGavc())).thenReturn(artifact); final ArtifactHandler handler = new ArtifactHandler(repositoryHandler, mock(LicenseMatcher.class)); final DbArtifact gotArtifact = handler.getArtifact(artifact.getGavc()); assertNotNull(gotArtifact); assertEquals(artifact, gotArtifact); verify(repositoryHandler, times(1)).getArtifact(artifact.getGavc()); }
@Test public void getAnArtifactThatDoesNotExist(){ final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final ArtifactHandler handler = new ArtifactHandler(repositoryHandler, mock(LicenseMatcher.class)); WebApplicationException exception = null; try { handler.getArtifact("doesNotExist"); }catch (WebApplicationException e){ exception = e; } assertNotNull(exception); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), exception.getResponse().getStatus()); }