ModuleHandler { public DbModule getModule(final String moduleId) { final DbModule dbModule = repositoryHandler.getModule(moduleId); if (dbModule == null) { throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) .entity("Module " + moduleId + " does not exist.").build()); } return dbModule; } 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 getAModule(){ final DbModule module = new DbModule(); module.setName("module"); module.setVersion("1.0.0-SNAPSHOT"); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getModule(module.getId())).thenReturn(module); final ModuleHandler handler = new ModuleHandler(repositoryHandler); final DbModule gotModule = handler.getModule(module.getId()); assertNotNull(gotModule); assertEquals(module, gotModule); verify(repositoryHandler, times(1)).getModule(module.getId()); }
@Test public void getAModuleThatDoesNotExist(){ final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final ModuleHandler handler = new ModuleHandler(repositoryHandler); WebApplicationException exception = null; try{ handler.getModule("doesNotExist"); } catch (WebApplicationException e){ exception = e; } assertNotNull(exception); assertEquals(javax.ws.rs.core.Response.Status.NOT_FOUND.getStatusCode(), exception.getResponse().getStatus()); }
@Test public void getModule(){ final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final ModuleHandler handler = new ModuleHandler(repositoryHandler); final FiltersHolder filters = mock(FiltersHolder.class); handler.getModules(filters); verify(repositoryHandler, times(1)).getModules(filters); }