You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.3 KiB
36 lines
1.3 KiB
package de.fd.fh.server.access;
|
|
|
|
import de.fd.fh.server.user.UserId;
|
|
import de.fd.fh.server.user.UserRepository;
|
|
import de.fd.fh.server.user.UserService;
|
|
import de.fd.fh.server.user.events.ChangePasswordEvent;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.BDDMockito.then;
|
|
import static org.mockito.Mockito.*;
|
|
|
|
class AccessContextEventListenerTest
|
|
{
|
|
@Test
|
|
void given_changePasswordEvent_when_passwordChanged_should_changePassword()
|
|
{
|
|
final ChangePasswordEvent event = new ChangePasswordEvent(UserId.of("12345"), "newPwd");
|
|
|
|
final AccessRepository repository = mock(AccessRepository.class);
|
|
when(repository.findByUserId(any(UserId.class)))
|
|
.thenReturn(new Access());
|
|
|
|
final ArgumentCaptor<Access> captor = ArgumentCaptor.forClass(Access.class);
|
|
|
|
new AccessContextEventListener(repository).update(null, event);
|
|
verify(repository).save(captor.capture());
|
|
|
|
assertEquals("newPwd", captor.getValue().getPassword(), "Have to be the new password");
|
|
then(repository).should().findByUserId(any(UserId.class));
|
|
then(repository).should().save(any(Access.class));
|
|
then(repository).shouldHaveNoMoreInteractions();
|
|
}
|
|
}
|