ScopeService { @Transactional(readOnly = true) public ScopePage list(final Long apiId, final ScopeDTO scopeDTO, final PageableDTO pageableDTO) { Api api = apiService.find(apiId); Scope scope = GenericConverter.mapper(scopeDTO, Scope.class); scope.setApi(api); Example<Scope> example = Example.of(scope, ExampleMatcher.matching().withIgnorePaths("api.creationDate").withIgnoreCase().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit(), new Sort(Sort.Direction.ASC, "id")); Page<Scope> page = scopeRepository.findAll(example, pageable); return new ScopePage(PageDTO.build(page)); }  @Transactional(readOnly = true) Scope find(final Long apiId, final Long scopeId); @Transactional(readOnly = true) ScopePage list(final Long apiId, final ScopeDTO scopeDTO, final PageableDTO pageableDTO); @Transactional(readOnly = true) List<Scope> list(final Long apiId, final ScopeDTO scopeDTO); @Transactional Scope save(final Long apiId, Scope scope); @Transactional void delete(final Long apiId, final Long scopeId); @Transactional Scope update(final Long apiId, final Long scopeId, Scope scope);  }
@Test public void listTest() { ScopeDTO scopeDTO = new ScopeDTO(); scopeDTO.setName("Scope"); scopeDTO.setDescription("Scope description"); List<Scope> scopesExpected = new ArrayList<>(); scopesExpected.add(scope); Mockito.when(apiService.find(Mockito.anyLong())).thenReturn(scope.getApi()); Mockito.when(scopeRepository.findAll(Mockito.any(Example.class))).thenReturn(scopesExpected); List<Scope> listScopes = scopeService.list(scope.getApi().getId(), scopeDTO); assertEquals(scopesExpected, listScopes); }