@Test
public void testGetSubjectMatterExpertByKeyCredStashGetCredentialFailedException() 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))
        .thenThrow(new CredStashGetCredentialFailedException(ERROR_MESSAGE));
    // Specify the expected exception.
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(ERROR_MESSAGE);
    // Try to call the method under test.
    subjectMatterExpertDaoImpl.getSubjectMatterExpertByKey(subjectMatterExpertKey);
    // 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);
    verifyNoMoreInteractionsHelper();
}