@Test
public void testUpdatePatient_when_authentication_success()
		throws AuthenticationFailedException,
		SpiritClientNotAvailableException {

	final String username = "TheUsername";
	AuthenticatedUser authenticatedUser = mock(AuthenticatedUser.class);
	when(authenticatedUser.getUsername()).thenReturn(username);
	when(userContext.getCurrentUser()).thenReturn(authenticatedUser);
	Users user = mock(Users.class);
	when(user.getUsername()).thenReturn(username);
	when(user.getPassword()).thenReturn("hashedpassword");
	when(usersRepository.loadUserByUsername(anyString())).thenReturn(user);
	when(passwordEncoder.matches("rawpassword", "hashedpassword"))
			.thenReturn(true);
	// Arrange
	PatientProfileDto patientProfileDtoInput = mock(PatientProfileDto.class);
	Patient patient = mock(Patient.class);
	when(patientProfileDtoInput.getUsername()).thenReturn(username);
	when(patientProfileDtoInput.getPassword()).thenReturn("rawpassword");
	when(patientProfileDtoInput.getFirstName()).thenReturn("albert");
	when(patientProfileDtoInput.getLastName()).thenReturn("Smith");
	when(patientProfileDtoInput.getEmail()).thenReturn(
			"albert.smith@consent2share.com");
	when(patientProfileDtoToPatientMapper.map(patientProfileDtoInput))
			.thenReturn(patient);
	Patient initialpatient = mock(Patient.class);
	when(patientRepository.findByUsername(username)).thenReturn(
			initialpatient);
	when(initialpatient.getEnterpriseIdentifier()).thenReturn("FAM.123");
	// Act
	sut.updatePatient(patientProfileDtoInput);
	// Assert
	verify(patientRepository, times(1)).save(patient);
}