SubjectMatterExpertServiceImpl implements SubjectMatterExpertService { @Override public SubjectMatterExpert getSubjectMatterExpert(SubjectMatterExpertKey subjectMatterExpertKey) { validateSubjectMatterExpertKey(subjectMatterExpertKey); SubjectMatterExpertContactDetails subjectMatterExpertContactDetails = subjectMatterExpertDao.getSubjectMatterExpertByKey(subjectMatterExpertKey); if (subjectMatterExpertContactDetails == null) { throw new ObjectNotFoundException( String.format("The subject matter expert with user id \"%s\" does not exist.", subjectMatterExpertKey.getUserId())); } return new SubjectMatterExpert(subjectMatterExpertKey, subjectMatterExpertContactDetails); }  @Override SubjectMatterExpert getSubjectMatterExpert(SubjectMatterExpertKey subjectMatterExpertKey);  }
@Test public void testGetSubjectMatterExpert() throws Exception { SubjectMatterExpertKey originalSubjectMatterExpertKey = new SubjectMatterExpertKey(USER_ID); SubjectMatterExpertKey updatedSubjectMatterExpertKey = new SubjectMatterExpertKey(USER_ID_2); SubjectMatterExpertContactDetails subjectMatterExpertContactDetails = new SubjectMatterExpertContactDetails(USER_FULL_NAME, USER_JOB_TITLE, USER_EMAIL_ADDRESS, USER_TELEPHONE_NUMBER); when(alternateKeyHelper.validateStringParameter("user id", USER_ID)).thenReturn(USER_ID_2); when(subjectMatterExpertDao.getSubjectMatterExpertByKey(updatedSubjectMatterExpertKey)).thenReturn(subjectMatterExpertContactDetails); SubjectMatterExpert result = subjectMatterExpertServiceImpl.getSubjectMatterExpert(originalSubjectMatterExpertKey); assertEquals(new SubjectMatterExpert(updatedSubjectMatterExpertKey, subjectMatterExpertContactDetails), result); verify(alternateKeyHelper).validateStringParameter("user id", USER_ID); verify(subjectMatterExpertDao).getSubjectMatterExpertByKey(updatedSubjectMatterExpertKey); verifyNoMoreInteractionsHelper(); }
@Test public void testGetSubjectMatterExpertMissingSubjectMatterExpertKey() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("A subject matter expert key must be specified."); subjectMatterExpertServiceImpl.getSubjectMatterExpert(null); verifyNoMoreInteractionsHelper(); }
@Test public void testGetSubjectMatterExpertUserNoExists() { SubjectMatterExpertKey originalSubjectMatterExpertKey = new SubjectMatterExpertKey(USER_ID); SubjectMatterExpertKey updatedSubjectMatterExpertKey = new SubjectMatterExpertKey(USER_ID_2); when(alternateKeyHelper.validateStringParameter("user id", USER_ID)).thenReturn(USER_ID_2); when(subjectMatterExpertDao.getSubjectMatterExpertByKey(updatedSubjectMatterExpertKey)).thenReturn(null); expectedException.expect(ObjectNotFoundException.class); expectedException.expectMessage(String.format("The subject matter expert with user id \"%s\" does not exist.", USER_ID_2)); subjectMatterExpertServiceImpl.getSubjectMatterExpert(originalSubjectMatterExpertKey); verify(alternateKeyHelper).validateStringParameter("user id", USER_ID); verify(subjectMatterExpertDao).getSubjectMatterExpertByKey(updatedSubjectMatterExpertKey); verifyNoMoreInteractionsHelper(); }