Backend Low Level Design 4
About Lesson

Here we are checking exception for this we we will use thenThrow method when we will call getSingleProduct method it will throw error that we will add in method signature and getSingleProduct method from controller return us the ResponseEntity<ProductResponseSelf>
<p>we wil store in actual variabl and use assert.Equals will test status code and same we will get code from ResponseEntitiy using getStatusCode method. </p>
<p>@Test <br />
public void productNotPresentTest() throws ProductNotPresentException {
Mockito.when(productService.getSingleProduct(25L)).thenThrow(ProductNotPresentException.class) ;
ResponseEntity</p>
<ProductResponseSelf>
actual = productController.getSingleProduct(25L);
Assertions.assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode());
}

© GeekySanjay