MiddlewareService { @Transactional public void deleteAll(Long apiId) { List<Middleware> middlewares = middlewareRepository.findByApiId(apiId); middlewares.forEach(middleware -> this.delete(apiId, middleware.getId())); }  @Transactional(readOnly = true) Middleware find(Long apiId, Long middlewareId); @Transactional(readOnly = true) MiddlewarePage list(Long apiId, MiddlewareDTO middlewareDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<Middleware> list(Long apiId, MiddlewareDTO middlewareDTO); @Transactional Middleware save(Long apiId, MiddlewareDTO middlewareDTO, MultipartFile file); @Transactional Middleware update(Long apiId, Long middlewareId, MiddlewareDTO middlewareDTO); @Transactional void delete(Long apiId, Long middlewareId); @Transactional void deleteAll(Long apiId);  }
@Test public void deleteAllTest() { Mockito.when(middlewareRepository.findByApiIdAndId(Mockito.anyLong(), Mockito.anyLong())).thenReturn(middleware); Mockito.when(middlewareRepository.findByApiId(Mockito.anyLong())).thenReturn(middlewareList); service.deleteAll(1L); Mockito.verify(middlewareRepository, Mockito.times(1)).findByApiId(Mockito.anyLong()); }