@Test
public void testCreateBusinessObjectFormatExternalInterfaceAlreadyExists()
{

    // Create a business object format to external interface mapping key.
    BusinessObjectFormatExternalInterfaceKey businessObjectFormatExternalInterfaceKey =
        new BusinessObjectFormatExternalInterfaceKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, EXTERNAL_INTERFACE);
    // Create a business object format to external interface mapping create request.
    BusinessObjectFormatExternalInterfaceCreateRequest businessObjectFormatExternalInterfaceCreateRequest =
        new BusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceKey);
    // Create a business object format entity.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    // Create a external interface entity.
    ExternalInterfaceEntity externalInterfaceEntity = new ExternalInterfaceEntity();
    // Mock the external calls.
    when(businessObjectFormatDaoHelper
        .getBusinessObjectFormatEntity(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null)))
        .thenReturn(businessObjectFormatEntity);
    when(externalInterfaceDaoHelper.getExternalInterfaceEntity(EXTERNAL_INTERFACE)).thenReturn(externalInterfaceEntity);
    when(businessObjectFormatExternalInterfaceDao
        .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity))
        .thenReturn(new BusinessObjectFormatExternalInterfaceEntity());
    // Specify the expected exception.
    expectedException.expect(AlreadyExistsException.class);
    expectedException.expectMessage(String.format("Unable to create business object format to external interface mapping for \"%s\" namespace, " +
        "\"%s\" business object definition name, \"%s\" business object format usage, \"%s\" business object format file type, and " +
        "\"%s\" external interface name because it already exists.", NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, EXTERNAL_INTERFACE));
    // Call the method under test.
    businessObjectFormatExternalInterfaceService.createBusinessObjectFormatExternalInterface(businessObjectFormatExternalInterfaceCreateRequest);
    // Verify the external calls.
    verify(businessObjectFormatExternalInterfaceHelper)
        .validateAndTrimBusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceCreateRequest);
    verify(businessObjectFormatDaoHelper)
        .getBusinessObjectFormatEntity(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null));
    verify(externalInterfaceDaoHelper).getExternalInterfaceEntity(EXTERNAL_INTERFACE);
    verify(businessObjectFormatExternalInterfaceDao)
        .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity);
    verifyNoMoreInteractionsHelper();
}