コード例 #1
0
 @Test
 public void shouldReturnExpectedProduct() throws Exception {
   final Long id = 1L;
   final Product expectedProduct = Product.build(id, "IOL123", "Optimus Prime");
   when(repository.findOne(eq(id))).thenReturn(expectedProduct);
   final Product actual = productService.getProduct(id);
   verify(repository).findOne(eq(id));
   assertEquals(expectedProduct, actual);
 }
コード例 #2
0
 @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));
 }
コード例 #3
0
 @Test
 public void shouldRetrieveProductsByCategory() {
   Pageable pageable = new PageRequest(1, 10);
   Long categoryId = 1L;
   Page<Product> page =
       new PageImpl(
           Collections.singletonList(Product.build(1L, "IOL123", "Optimus Prime")), pageable, 1);
   when(repository.findByCategoryId(eq(categoryId), Matchers.any(PageRequest.class)))
       .thenReturn(page);
   final Page<Product> results = productService.getProductsByCategory(categoryId, pageable);
   assertFalse(results.getContent().isEmpty());
 }