@Test
public void testGetSubjectMatterExpertByKeyUserNoExists() throws Exception
{

    // Create a subject matter expert key.
    SubjectMatterExpertKey subjectMatterExpertKey = new SubjectMatterExpertKey(USER_ID);
    // Create subject matter expert contact details initialised with test data.
    SubjectMatterExpertContactDetails subjectMatterExpertContactDetails =
        new SubjectMatterExpertContactDetails(USER_FULL_NAME, USER_JOB_TITLE, USER_EMAIL_ADDRESS, USER_TELEPHONE_NUMBER);
    // Mock the external calls.
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_URL)).thenReturn(LDAP_URL);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_BASE)).thenReturn(LDAP_BASE);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_USER_DN)).thenReturn(LDAP_USER_DN);
    when(configurationHelper.getProperty(ConfigurationValue.CREDSTASH_HERD_ENCRYPTION_CONTEXT)).thenReturn(CREDSTASH_ENCRYPTION_CONTEXT);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_USER_CREDENTIAL_NAME)).thenReturn(USER_CREDENTIAL_NAME);
    when(credStashHelper.getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME)).thenReturn(PASSWORD);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_ID)).thenReturn(LDAP_ATTRIBUTE_USER_ID);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_FULL_NAME)).thenReturn(LDAP_ATTRIBUTE_USER_FULL_NAME);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_JOB_TITLE)).thenReturn(LDAP_ATTRIBUTE_USER_JOB_TITLE);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_EMAIL_ADDRESS)).thenReturn(LDAP_ATTRIBUTE_USER_EMAIL_ADDRESS);
    when(configurationHelper.getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_TELEPHONE_NUMBER)).thenReturn(LDAP_ATTRIBUTE_USER_TELEPHONE_NUMBER);
    when(
        ldapOperations.search(any(LdapTemplate.class), any(LdapQuery.class), any(SubjectMatterExpertDaoImpl.SubjectMatterExpertContactDetailsMapper.class)))
        .thenReturn(Collections.emptyList());
    // Call the method under test.
    SubjectMatterExpertContactDetails result = subjectMatterExpertDaoImpl.getSubjectMatterExpertByKey(subjectMatterExpertKey);
    // Validate the results.
    assertNull(result);
    // Verify the external calls.
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_URL);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_BASE);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_USER_DN);
    verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_HERD_ENCRYPTION_CONTEXT);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_USER_CREDENTIAL_NAME);
    verify(credStashHelper).getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_ID);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_FULL_NAME);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_JOB_TITLE);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_EMAIL_ADDRESS);
    verify(configurationHelper).getProperty(ConfigurationValue.LDAP_ATTRIBUTE_USER_TELEPHONE_NUMBER);
    verify(ldapOperations)
        .search(any(LdapTemplate.class), any(LdapQuery.class), any(SubjectMatterExpertDaoImpl.SubjectMatterExpertContactDetailsMapper.class));
    verifyNoMoreInteractionsHelper();
}