**Test Class**
@RunWith(SpringRunner.class)
//@WebMvcTest
@AutoConfigureMockMvc
@TestPropertySource(locations = "classpath:application-test.properties")
@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
public class UnitTestingMockitoApplicationTe
{
private static @Autowired
Product PRODUCT = new privateProduct(110, static"WXYZ", MockMvc150d, mockMvc;"V20");
@MockBean
public static final String privateURL ProductRepository= productRepository;"http://localhost:%s/product/";
// @Autowired
public static final Integer privatePRODUCT_ID IProductService= productService;101;
@Test@Autowired
public voidprivate contextLoads()TestRestTemplate {restTemplate;
}
@LocalServerPort
@Test
private int port;
public void testProductDelete_02() {
// 1. POST Method doThrow(newCase PersistenceException("ExceptionFrom Occured..!!")).when(productRepository).deleteById(productIdDB);
verify(productRepository).deleteById(any());@Test
}
**Service Class**
@Service
public classvoid IProductServiceImpltestProductSave_01() implementsthrows IProductServiceException {
@Autowired
private ProductRepository repo;
ProductDto productDTO = @OverridegivenProductDto();
publicString voidformat deleteProduct= String.format(IntegerURL+"register", prodIdport) {;
HttpHeaders httpHeaders = new repo.deleteByIdHttpHeaders(prodId);
}
}
**Controller Class**
@RestController
@RequestMappinghttpHeaders.set(""Content-Type", "application/product"json;charset=UTF-8")
public class EmployeeRestController {
@Autowired;
private IProductService service;
@DeleteMapping("/delete/{id}")
HttpEntity<ProductDto> httpEntity public= ResponseEntity<?>new deleteProductHttpEntity<ProductDto>(@PathVariable IntegerproductDTO, idhttpHeaders) {;
ResponseEntity<?>ResponseEntity<ProductDto> response = null;
boolean exist = servicerestTemplate.isProductExistexchange(id);
format, HttpMethod.POST, httpEntity,
if (exist) {
serviceProductDto.deleteProduct(idclass);
assertEquals(response = new ResponseEntity<String>.getStatusCode(id + "-Removed"), HttpStatus.OK);
} else {
response = new ResponseEntity<String>assertNotNull("Product NOT FOUND", HttpStatusresponse.BAD_REQUESTgetBody());
}
return response;
}
Exception org.springframework.web.client.RestClientException: mockito wanted but not invoked, Actually there were zero interactions with this mock OccuringError while extracting response for type [class com.junittesting.dto.ProductDto] While calling this method from JPA Repository. I am getting mockito wantedm trying to write unit test cases but not invoked. Actually there were zero interactions with this mock at verify call.giving error