@Test
public void testCreateSecurityRoleFunctionSecurityRoleFunctionAlreadyExists()
{

    // Create a security role to function mapping key.
    SecurityRoleFunctionKey securityRoleFunctionKey = new SecurityRoleFunctionKey(SECURITY_ROLE, SECURITY_FUNCTION);
    // Create a security role to function mapping create request.
    SecurityRoleFunctionCreateRequest securityRoleFunctionCreateRequest = new SecurityRoleFunctionCreateRequest(securityRoleFunctionKey);
    // Create a security role to function mapping entity.
    SecurityRoleFunctionEntity securityRoleFunctionEntity = new SecurityRoleFunctionEntity();
    // Mock the external calls.
    when(securityRoleFunctionDao.getSecurityRoleFunctionByKey(securityRoleFunctionKey)).thenReturn(securityRoleFunctionEntity);
    // Specify the expected exception.
    expectedException.expect(AlreadyExistsException.class);
    expectedException.expectMessage(String.format(
        "Unable to create security role to function mapping for \"%s\" security role name and \"%s\" security function name because it already exists.",
        SECURITY_ROLE, SECURITY_FUNCTION));
    // Call the method under test.
    securityRoleFunctionService.createSecurityRoleFunction(securityRoleFunctionCreateRequest);
    // Verify the external calls.
    verify(securityRoleFunctionHelper).validateAndTrimSecurityRoleFunctionCreateRequest(securityRoleFunctionCreateRequest);
    verify(securityRoleFunctionDao).getSecurityRoleFunctionByKey(securityRoleFunctionKey);
    verifyNoMoreInteractionsHelper();
}