### Question:
DataEngineCommonHandler { protected Optional<EntityDetail> findEntity(String userId, String qualifiedName, String entityTypeName) throws UserNotAuthorizedException, PropertyServerException, InvalidParameterException { final String methodName = "findEntity"; invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateName(qualifiedName, CommonMapper.QUALIFIED_NAME_PROPERTY_NAME, methodName); qualifiedName = repositoryHelper.getExactMatchRegex(qualifiedName); InstanceProperties properties = repositoryHelper.addStringPropertyToInstance(serviceName, null, CommonMapper.QUALIFIED_NAME_PROPERTY_NAME, qualifiedName, methodName); TypeDef entityTypeDef = repositoryHelper.getTypeDefByName(userId, entityTypeName); Optional<EntityDetail> retrievedEntity = Optional.ofNullable(repositoryHandler.getUniqueEntityByName(userId, qualifiedName, CommonMapper.QUALIFIED_NAME_PROPERTY_NAME, properties, entityTypeDef.getGUID(), entityTypeDef.getName(), methodName)); log.debug("Searching for entity with qualifiedName: {}. Result is {}", qualifiedName, retrievedEntity.map(InstanceHeader::getGUID).orElse(null)); return retrievedEntity; } DataEngineCommonHandler(String serviceName, String serverName, InvalidParameterHandler invalidParameterHandler,
                                   RepositoryHandler repositoryHandler, OMRSRepositoryHelper repositoryHelper,
                                   DataEngineRegistrationHandler dataEngineRegistrationHandler);   }### Answer:
@Test void findEntity() throws InvalidParameterException, PropertyServerException, UserNotAuthorizedException { String methodName = "findEntity"; when(repositoryHelper.getExactMatchRegex(QUALIFIED_NAME)).thenReturn(QUALIFIED_NAME); EntityDetail mockedEntity = mock(EntityDetail.class); when(mockedEntity.getGUID()).thenReturn(GUID); when(repositoryHandler.getUniqueEntityByName(USER, QUALIFIED_NAME, CommonMapper.QUALIFIED_NAME_PROPERTY_NAME, null, ENTITY_TYPE_GUID, ENTITY_TYPE_NAME, methodName)).thenReturn(mockedEntity); Optional<EntityDetail> result = dataEngineCommonHandler.findEntity(USER, QUALIFIED_NAME, ENTITY_TYPE_NAME); assertTrue(result.isPresent()); assertEquals(GUID, result.get().getGUID()); verify(invalidParameterHandler, times(1)).validateUserId(USER, methodName); verify(invalidParameterHandler, times(1)).validateName(QUALIFIED_NAME, CommonMapper.QUALIFIED_NAME_PROPERTY_NAME, methodName); }
@Test void findEntity_throwsUserNotAuthorizedException() throws PropertyServerException, UserNotAuthorizedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { String methodName = "findEntity"; when(repositoryHelper.getExactMatchRegex(QUALIFIED_NAME)).thenReturn(QUALIFIED_NAME); UserNotAuthorizedException mockedException = mockException(UserNotAuthorizedException.class, methodName); when(repositoryHandler.getUniqueEntityByName(USER, QUALIFIED_NAME, CommonMapper.QUALIFIED_NAME_PROPERTY_NAME, null, ENTITY_TYPE_GUID, ENTITY_TYPE_NAME, methodName)).thenThrow(mockedException); UserNotAuthorizedException thrown = assertThrows(UserNotAuthorizedException.class, () -> dataEngineCommonHandler.findEntity(USER, QUALIFIED_NAME, ENTITY_TYPE_NAME)); assertTrue(thrown.getMessage().contains("OMAS-DATA-ENGINE-404-001 ")); }