ValueSetServiceImpl implements ValueSetService { @Override public Map<String, Object> findAllByCode(String searchTerm, String valueSetCategory, int pageNumber) { Sort sort = new Sort(new Order(Direction.ASC, "code")); PageRequest pageRequest = new PageRequest(pageNumber, VALUE_SET_PAGE_SIZE, sort); Page<ValueSet> pagedValueSets = valueSetRepository.findAllByCodeLike( "%" + searchTerm + "%", "%" + valueSetCategory + "%", pageRequest); Map<String, Object> pageResultsMap = new HashMap<String, Object>(); pageResultsMap.put("valueSets", setDeletableToValueSetDto(pagedValueSets.getContent())); pageResultsMap.put("totalNumberOfValueSets", pagedValueSets.getTotalElements()); pageResultsMap.put("totalPages", pagedValueSets.getTotalPages()); pageResultsMap.put("itemsPerPage", pagedValueSets.getSize()); pageResultsMap.put("currentPage", pagedValueSets.getNumber()); pageResultsMap.put("numberOfElements", pagedValueSets.getNumberOfElements()); return pageResultsMap; } ValueSetServiceImpl(int valueSetPageSize,
			ValueSetRepository valueSetRepository,
			ValueSetCategoryRepository valueSetCategoryRepository,
			ConceptCodeValueSetRepository conceptCodeValueSetRepository,
			ValueSetMgmtHelper valueSetMgmtHelper); @Override @Transactional ValueSetDto create(ValueSetDto created); @Override @Transactional(rollbackFor = ValueSetNotFoundException.class) ValueSetDto delete(Long valueSetId); @Override ValueSetDto findById(Long id); @Override @Transactional(rollbackFor = ValueSetNotFoundException.class) ValueSetDto update(ValueSetDto updated); @Override ValueSetVSCDto create(); @Override List<ValueSetDto> findAll(); @Override List<ValueSetDto> findAllWithoutDeletable(); @Override Map<String, Object> findAll(int pageNumber); @Override Map<String, Object> findAllByName(String searchTerm,
			String valueSetCategory, int pageNumber); @Override Map<String, Object> findAllByCode(String searchTerm,
			String valueSetCategory, int pageNumber); @Override @Transactional(rollbackFor = DataIntegrityViolationException.class) ValueSetDto valueSetBatchUpload(ValueSetDto valueSetDto,
			MultipartFile file);  }
@Test public void testFindAllByCode() { Page<ValueSet> valueSetsMock = mock(Page.class); when( valueSetRepository.findAllByCodeLike(anyString(), anyString(), any(Pageable.class))).thenReturn(valueSetsMock); List<ValueSetDto> valueSetDtosMock = new ArrayList<ValueSetDto>(); ValueSetDto valueSetDtoMock = mock(ValueSetDto.class); valueSetDtosMock.add(valueSetDtoMock); when( valueSetMgmtHelper.convertValueSetEntitiesToDtos(valueSetsMock .getContent())).thenReturn(valueSetDtosMock); when(valueSetDtoMock.getId()).thenReturn((long) 1); when(conceptCodeValueSetRepository.findAllByPkValueSetId(anyLong())) .thenReturn(null); assertEquals(vst.findAllByCode("a", "ETH", 0).get("valueSets"), valueSetDtosMock); }