ProductHandler { public void create(final DbProduct dbProduct) { if(repositoryHandler.getProduct(dbProduct.getName()) != null){ throw new WebApplicationException(Response.status(Response.Status.CONFLICT).entity("Product already exist!").build()); } repositoryHandler.store(dbProduct); } ProductHandler(final RepositoryHandler repositoryHandler); void create(final DbProduct dbProduct); void update(final DbProduct dbProduct); List<String> getProductNames(); DbProduct getProduct(final String name); void deleteProduct(final String name); void setProductModules(final String name, final List<String> moduleNames);  }
@Test public void storeANewProduct(){ final DbProduct product = new DbProduct(); product.setName("product1"); final RepositoryHandler repositoryHandler = GrapesTestUtils.getRepoHandlerMock(); final ProductHandler productHandler = new ProductHandler(repositoryHandler); Exception exception = null; try { productHandler.create(product); } catch(Exception e){ exception = e; } assertNull(exception); verify(repositoryHandler,times(1)).store(product); }