コード例 #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(expected = ProductNotFoundException.class)
 public void shouldThrowExceptionWhenProductNotFound() throws Exception {
   when(repository.findOne(anyLong())).thenReturn(null);
   productService.getProduct(1L);
 }