### Question:
PortHandler { public String findSchemaTypeForPort(String userId, String portGUID) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { final String methodName = "findSchemaTypeForPort"; invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateGUID(portGUID, ProcessPropertiesMapper.GUID_PROPERTY_NAME, methodName); TypeDef relationshipTypeDef = repositoryHelper.getTypeDefByName(userId, PortPropertiesMapper.PORT_SCHEMA_TYPE_NAME); EntityDetail entity = repositoryHandler.getEntityForRelationshipType(userId, portGUID, PortPropertiesMapper.PORT_TYPE_NAME, relationshipTypeDef.getGUID(), relationshipTypeDef.getName(), methodName); if (entity == null) { return null; } return entity.getGUID(); } PortHandler(String serviceName, String serverName, InvalidParameterHandler invalidParameterHandler, RepositoryHandler repositoryHandler,
                       OMRSRepositoryHelper repositoryHelper, DataEngineCommonHandler dataEngineCommonHandler); String createPortImplementation(String userId, PortImplementation portImplementation, String externalSourceName); String createPortAlias(String userId, PortAlias portAlias, String externalSourceName); void updatePortImplementation(String userId, EntityDetail originalPortEntity, PortImplementation portImplementation); void updatePortAlias(String userId, EntityDetail originalPortEntity, PortAlias portAlias); void addPortSchemaRelationship(String userId, String portGUID, String schemaTypeGUID, String externalSourceName); String findSchemaTypeForPort(String userId, String portGUID); void addPortDelegationRelationship(String userId, String portGUID, PortType portType, String delegatesToQualifiedName,
                                              String externalSourceName); void removePort(String userId, String portGUID, String entityTypeName); Optional<EntityDetail> findPortImplementationEntity(String userId, String qualifiedName); Optional<EntityDetail> findPortAliasEntity(String userId, String qualifiedName); Optional<EntityDetail> findPortEntity(String userId, String qualifiedName);  }### Answer:
@Test void getSchemaTypeForPort() throws InvalidParameterException, PropertyServerException, UserNotAuthorizedException { String methodName = "findSchemaTypeForPort"; mockTypeDef(PortPropertiesMapper.PORT_SCHEMA_TYPE_NAME, PortPropertiesMapper.PORT_SCHEMA_TYPE_GUID); EntityDetail entityDetail = mock(EntityDetail.class); when(entityDetail.getGUID()).thenReturn(GUID); when(repositoryHandler.getEntityForRelationshipType(USER, PORT_GUID, PortPropertiesMapper.PORT_TYPE_NAME, PortPropertiesMapper.PORT_SCHEMA_TYPE_GUID, PortPropertiesMapper.PORT_SCHEMA_TYPE_NAME, methodName)).thenReturn(entityDetail); String resultGUID = portHandler.findSchemaTypeForPort(USER, PORT_GUID); verify(invalidParameterHandler, times(1)).validateUserId(USER, methodName); verify(invalidParameterHandler, times(1)).validateGUID(PORT_GUID, PortPropertiesMapper.GUID_PROPERTY_NAME, methodName); assertEquals(GUID, resultGUID); }
@Test void getSchemaTypeForPort_throwsUserNotAuthorizedException() throws PropertyServerException, UserNotAuthorizedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { String methodName = "findSchemaTypeForPort"; mockTypeDef(PortPropertiesMapper.PORT_SCHEMA_TYPE_NAME, PortPropertiesMapper.PORT_SCHEMA_TYPE_GUID); UserNotAuthorizedException mockedException = mockException(UserNotAuthorizedException.class, methodName); when(repositoryHandler.getEntityForRelationshipType(USER, PORT_GUID, PortPropertiesMapper.PORT_TYPE_NAME, PortPropertiesMapper.PORT_SCHEMA_TYPE_GUID, PortPropertiesMapper.PORT_SCHEMA_TYPE_NAME, methodName)).thenThrow(mockedException); UserNotAuthorizedException thrown = assertThrows(UserNotAuthorizedException.class, () -> portHandler.findSchemaTypeForPort(USER, PORT_GUID)); assertTrue(thrown.getMessage().contains("OMAS-DATA-ENGINE-404-001 ")); }