PlanService { @Transactional(readOnly = true) public PlanPage list(PlanDTO planDTO, PageableDTO pageableDTO) { Plan plan = GenericConverter.mapper(planDTO, Plan.class); Example<Plan> example = Example.of(plan, ExampleMatcher.matching().withIgnorePaths("defaultPlan", "api.cors").withIgnoreCase().withStringMatcher(StringMatcher.CONTAINING)); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Plan> page = planRepository.findAll(example, pageable); PlanPage planPage = new PlanPage(PageDTO.build(page)); return planPage; }  @Transactional(readOnly = true) Plan find(Long id); @Transactional(readOnly = true) PlanPage list(PlanDTO planDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<Plan> list(PlanDTO planDTO); Plan save(PlanDTO planDTO); Plan update(Long id, PlanDTO planDTO); void delete(Long id);  }
@Test public void listPlans() { this.plan.setName("Plan Name"); List<Plan> plans = new ArrayList<>(); plans.add(plan); Mockito.when(this.planRepository.findAll(Mockito.any(Example.class))).thenReturn(plans); List<Plan> planResp = this.planService.list(this.planDTO); assertEquals(plans.size(), planResp.size()); Mockito.verify(this.planRepository, Mockito.times(1)).findAll(Mockito.any(Example.class)); }
@Test public void listPlansWithPageable() { PageableDTO pageableDTO = new PageableDTO(); pageableDTO.setLimit(10); pageableDTO.setOffset(0); ArrayList<Plan> listPlans = new ArrayList<>(); this.plan.setName("Plan Name"); listPlans.add(plan); Page<Plan> page = new PageImpl<>(listPlans); Mockito.when(this.planRepository.findAll(Mockito.any(Example.class), Mockito.any(Pageable.class))) .thenReturn(page); PlanPage planPageResp = this.planService.list(this.planDTO, pageableDTO); assertEquals(1L, planPageResp.getTotalElements()); Mockito.verify(this.planRepository, Mockito.times(1)) .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class)); }