@Test(expected = NoProductsFoundException.class) public void shouldThrowExceptionWhenNoProductsExists() { final PageRequest pageRequest = new PageRequest(1, 10); final Page<Product> page = new PageImpl<>(Collections.<Product>emptyList(), pageRequest, 0); when(repository.findAll(Matchers.any(PageRequest.class))).thenReturn(page); productService.getProducts(pageRequest); }
@Test public void shouldRetrieveAllProducts() throws Exception { Pageable pageable = new PageRequest(1, 10); Page<Product> expected = new PageImpl( Collections.singletonList(Product.build(1L, "IOL123", "Optimus Prime")), pageable, 1); when(repository.findAll(Matchers.any(PageRequest.class))).thenReturn(expected); final Page<Product> actual = productService.getProducts(pageable); assertEquals(expected, actual); verify(repository).findAll(Matchers.any(PageRequest.class)); }