### Question:
TargetTypesServiceImpl implements TargetTypesService { @Override public String updateTargetTypeDetails(CreateUpdateTargetTypeDetailsRequest targetTypesDetails, final String userId) throws PacManException { targetTypesDetails.setName(targetTypesDetails.getName().toLowerCase().trim().replaceAll(" ", "-")); boolean isTargetTypeExits = targetTypesRepository.existsById(targetTypesDetails.getName()); if (isTargetTypeExits) { Date currentDate = new Date(); TargetTypes existingTargetType = targetTypesRepository.findById(targetTypesDetails.getName().trim()).get(); existingTargetType.setTargetDesc(targetTypesDetails.getDesc()); existingTargetType.setCategory(targetTypesDetails.getCategory()); existingTargetType.setDataSourceName(targetTypesDetails.getDataSource()); existingTargetType.setTargetConfig(targetTypesDetails.getConfig()); existingTargetType.setUserId(userId); String endpoint = config.getElasticSearch().getDevIngestHost() + ":" + config.getElasticSearch().getDevIngestPort() + "/" + targetTypesDetails.getDataSource() + "_"+ targetTypesDetails.getName() + "/" + targetTypesDetails.getName(); existingTargetType.setEndpoint(endpoint); existingTargetType.setModifiedDate(currentDate); existingTargetType.setDomain(targetTypesDetails.getDomain()); targetTypesRepository.save(existingTargetType); return AdminConstants.TARGET_TYPE_UPDATION_SUCCESS; } else { throw new PacManException(AdminConstants.TARGET_TYPE_NAME_NOT_EXITS); } }  @Override Collection<String> getTargetTypesNamesByDataSourceName(final String dataSourceName); @Override List<TargetTypes> getAllTargetTypesByDomainList(final List<String> domains); @Override Page<TargetTypesProjections> getAllTargetTypeDetails(String searchTerm, int page, int size); @Override List<String> getAllTargetTypesCategories(); @Override List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes); @Override List<TargetTypeAttribute> getTargetTypeAttributes(final List<TargetTypes> targetTypes); @Override Map<String, Object> getAttributeValues(AttributeValuesRequest attributeValuesRequest); @Override TargetTypes getTargetTypesByName(String targetTypeName); @Override String updateTargetTypeDetails(CreateUpdateTargetTypeDetailsRequest targetTypesDetails, final String userId); @Override String addTargetTypeDetails(final CreateUpdateTargetTypeDetailsRequest targetTypeDetailsRequest, final String userId); @Override void deleteIndex(String targetTypeIndex);  }### Answer:
@Test public void updateTargetTypeDetailsTest() throws PacManException { when(targetTypesRepository.existsById("targettypename123")).thenReturn(true); when(targetTypesRepository.findById("targettypename123")).thenReturn(getTargetTypesValues()); when(config.getElasticSearch()).thenReturn(getElasticSearchProperty()); assertThat(targetTypesService.updateTargetTypeDetails(getTargetTypeDetailsRequest(), "userId"), is(AdminConstants.TARGET_TYPE_UPDATION_SUCCESS)); }
@Test public void updateTargetTypeDetailsExceptionTest() throws PacManException { when(targetTypesRepository.existsById("targetTypeName123")).thenReturn(false); assertThatThrownBy(() -> targetTypesService.updateTargetTypeDetails(getTargetTypeDetailsRequest(), "userId")).isInstanceOf(PacManException.class); }