ValueSetServiceImpl implements ValueSetService { @Override @Transactional(rollbackFor = ValueSetNotFoundException.class) public ValueSetDto delete(Long valueSetId) throws ValueSetNotFoundException { logger.debug("Deleting ValueSet with id: " + valueSetId); ValueSet deleted = valueSetRepository.findOne(valueSetId); if (deleted == null) { logger.debug("No ValueSet found with an id: " + valueSetId); throw new ValueSetNotFoundException( "No ValueSet found with an id: " + valueSetId); } List<ConceptCodeValueSet> conceptCodeValueSets = deleted .getConceptCodes(); if (null != conceptCodeValueSets && conceptCodeValueSets.size() > 0) { logger.debug("You can not delete a Value Set attached to an active Concept Code. " + valueSetId); throw new ValueSetNotFoundException( "You can not delete a Value Set attached to an active Concept Code. " + valueSetId); } valueSetRepository.delete(deleted); return valueSetMgmtHelper.createValuesetDtoFromEntity(deleted); } 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 testDeleteVelueSet() throws ValueSetNotFoundException { ValueSet deleted = mock(ValueSet.class); when(valueSetRepository.findOne(anyLong())).thenReturn(deleted); ValueSetDto valueSetDto = mock(ValueSetDto.class); when(valueSetMgmtHelper.createValuesetDtoFromEntity(deleted)) .thenReturn(valueSetDto); Assert.assertEquals(vst.delete((long) 1), valueSetDto); }
@Test(expected = ValueSetNotFoundException.class) public void testDeleteVelueSet_throw_ValueSetNotFoundException() throws ValueSetNotFoundException { when(valueSetRepository.findOne(anyLong())).thenReturn(null); vst.delete((long) 1); }