### Question:
PortHandler { public void updatePortAlias(String userId, EntityDetail originalPortEntity, PortAlias portAlias) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { updatePort(userId, originalPortEntity, portAlias, PortPropertiesMapper.PORT_ALIAS_TYPE_NAME); } 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 updatePortAlias() throws InvalidParameterException, PropertyServerException, UserNotAuthorizedException { String methodName = "updatePort"; EntityDetail mockedOriginalPortEntity = Mockito.mock(EntityDetail.class); when(mockedOriginalPortEntity.getGUID()).thenReturn(PORT_GUID); EntityDetail mockedUpdatedPortEntity = Mockito.mock(EntityDetail.class); when(dataEngineCommonHandler.buildEntityDetail(PORT_GUID, null)).thenReturn(mockedUpdatedPortEntity); EntityDetailDifferences mockedDifferences = mock(EntityDetailDifferences.class); when(mockedDifferences.hasInstancePropertiesDifferences()).thenReturn(Boolean.TRUE); when(repositoryHelper.getEntityDetailDifferences(mockedOriginalPortEntity, mockedUpdatedPortEntity, true)).thenReturn(mockedDifferences); portHandler.updatePortAlias(USER, mockedOriginalPortEntity, getPortAlias()); verify(invalidParameterHandler, times(1)).validateUserId(USER, methodName); verify(invalidParameterHandler, times(1)).validateName(NAME, PortPropertiesMapper.DISPLAY_NAME_PROPERTY_NAME, methodName); verify(invalidParameterHandler, times(1)).validateName(QUALIFIED_NAME, PortPropertiesMapper.QUALIFIED_NAME_PROPERTY_NAME, methodName); verify(dataEngineCommonHandler, times(1)).updateEntity(USER, PORT_GUID, null, PortPropertiesMapper.PORT_ALIAS_TYPE_NAME); }
@Test void updatePortAlias_throwsUserNotAuthorizedException() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, UserNotAuthorizedException, PropertyServerException { String methodName = "updatePort"; EntityDetail mockedOriginalPortEntity = Mockito.mock(EntityDetail.class); when(mockedOriginalPortEntity.getGUID()).thenReturn(PORT_GUID); EntityDetail mockedUpdatedPortEntity = Mockito.mock(EntityDetail.class); when(dataEngineCommonHandler.buildEntityDetail(PORT_GUID, null)).thenReturn(mockedUpdatedPortEntity); EntityDetailDifferences mockedDifferences = mock(EntityDetailDifferences.class); when(mockedDifferences.hasInstancePropertiesDifferences()).thenReturn(Boolean.TRUE); when(repositoryHelper.getEntityDetailDifferences(mockedOriginalPortEntity, mockedUpdatedPortEntity, true)).thenReturn(mockedDifferences); UserNotAuthorizedException mockedException = mockException(UserNotAuthorizedException.class, methodName); doThrow(mockedException).when(dataEngineCommonHandler).updateEntity(USER, PORT_GUID, null, PortPropertiesMapper.PORT_ALIAS_TYPE_NAME); UserNotAuthorizedException thrown = assertThrows(UserNotAuthorizedException.class, () -> portHandler.updatePortAlias(USER, mockedOriginalPortEntity, getPortAlias())); assertTrue(thrown.getMessage().contains("OMAS-DATA-ENGINE-404-001 ")); }