UserCreationServiceImpl implements UserCreationService { @Override @Transactional(readOnly = true) public UserCreationResponseDto findUserCreationInfoByPatientId(Long patientId) { final PatientDto patientDto = phrService.findPatientProfileById(patientId); final UserCreation userCreation = userCreationRepository.findOneByPatientId(patientId).orElseThrow(() -> new UserCreationNotFoundException("No user creation record found for patient id: " + patientId)); final UserCreationResponseDto response = modelMapper.map(patientDto, UserCreationResponseDto.class); response.setBirthDate(patientDto.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); response.setVerificationCode(userCreation.getVerificationCode()); response.setEmailTokenExpiration(userCreation.getEmailTokenExpirationAsInstant()); response.setVerified(userCreation.isVerified()); return response; }  @Override @Transactional UserCreationResponseDto initiateUserCreation(UserCreationRequestDto userCreationRequest, String xForwardedProto, String xForwardedHost, int xForwardedPort); @Override @Transactional(readOnly = true) UserCreationResponseDto findUserCreationInfoByPatientId(Long patientId); @Override UserActivationResponseDto activateUser(UserActivationRequestDto userActivationRequest, String xForwardedProto, String xForwardedHost, int xForwardedPort); @Override @Transactional(readOnly = true) VerificationResponseDto verify(String emailToken, Optional<String> verificationCode, Optional<LocalDate> birthDate); ScopeAssignmentResponseDto assignScopeToUser(ScopeAssignmentRequestDto scopeAssignmentRequestDto);  }
@Test public void testFindUserCreationInfoByPatientId() throws Exception { final Long patientId = 10L; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final Date birthDate = new Date(year, month, day); final Instant emailTokenExpiration = Instant.now(); final PatientDto patientDto = mock(PatientDto.class); when(phrService.findPatientProfileById(patientId)).thenReturn(patientDto); when(patientDto.getBirthDate()).thenReturn(birthDate); final UserCreation userCreation = mock(UserCreation.class); when(userCreationRepository.findOneByPatientId(patientId)).thenReturn(Optional.of(userCreation)); when(userCreation.getVerificationCode()).thenReturn(verificationCode); when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration); final UserCreationResponseDto userCreationResponseDto = mock(UserCreationResponseDto.class); when(modelMapper.map(patientDto, UserCreationResponseDto.class)).thenReturn(userCreationResponseDto); final UserCreationResponseDto response = sut.findUserCreationInfoByPatientId(patientId); assertEquals(userCreationResponseDto, response); verify(userCreationResponseDto, times(1)).setVerificationCode(verificationCode); verify(userCreationResponseDto, times(1)).setEmailTokenExpiration(emailTokenExpiration); }
@Test public void testFindUserCreationInfoByPatientId_Throws_UserCreationNotFoundException_When_Not_Found() throws Exception { thrown.expect(UserCreationNotFoundException.class); final Long patientId = 10L; final PatientDto patientDto = mock(PatientDto.class); when(phrService.findPatientProfileById(patientId)).thenReturn(patientDto); when(userCreationRepository.findOneByPatientId(patientId)).thenReturn(Optional.empty()); final UserCreationResponseDto response = sut.findUserCreationInfoByPatientId(patientId); assertNull(response); }