ApiService { public Swagger findSwaggerByApi(Long id) { Api api = apiRepository.findOne(id); List<Resource> resources = resourceService.list(api.getId(), new ResourceDTO()); api.setResources(new HashSet<>(resources)); return swaggerService.exportApiToSwaggerJSON(api); }  Api find(Long id); Swagger findSwaggerByApi(Long id); ApiPage list(ApiDTO apiDTO, PageableDTO pageableDTO); List<Api> list(ApiDTO apiDTO); Api save(ApiDTO apiDTO); Api update(Long id, ApiDTO apiDTO); Api updateBySwagger(Long id, String swagger, boolean override); void delete(Long id); @Transactional(readOnly = true) List<Plan> plansByApi(Long id);  }
@Test public void findSwaggerByApiTest() { Mockito.when(apiRepository.findOne(Mockito.anyLong())).thenReturn(api); Mockito.when(resourceRepository.findAll(Mockito.any(Example.class))).thenReturn(Mockito.anyList()); Mockito.when(swaggerService.exportApiToSwaggerJSON(api)).thenReturn(new Swagger()); Swagger result = this.apiService.findSwaggerByApi(1L); Mockito.verify(swaggerService, Mockito.times(1)).exportApiToSwaggerJSON(api); assertNotNull(result); }