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.
51 lines
2.1 KiB
51 lines
2.1 KiB
package de.fd.fh.server.user;
|
|
|
|
import de.fd.fh.server.access.events.AccountCreatedEvent;
|
|
import de.fd.fh.server.access.events.AccountDeletedEvent;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.BDDMockito.then;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
class UserContextEventListenerTest
|
|
{
|
|
@Test
|
|
void given_accountCreatedEvent_when_accountWasCreated_should_createUser()
|
|
{
|
|
final AccountCreatedEvent event = new AccountCreatedEvent("testName", UserId.of("12345"));
|
|
final UserRepository repository = mock(UserRepository.class);
|
|
|
|
final ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
|
|
|
|
new UserContextEventListener(repository).update(null, event);
|
|
verify(repository).save(captor.capture());
|
|
|
|
assertNotNull(captor.getValue());
|
|
assertEquals("testName", captor.getValue().getName(), "Should have the correct name");
|
|
assertEquals("12345", captor.getValue().getId().getIdentifier(), "Should have the correct userId");
|
|
then(repository).should().save(any());
|
|
then(repository).shouldHaveNoMoreInteractions();
|
|
}
|
|
|
|
@Test
|
|
void given_accountDeletedEvent_when_accountWasDeleted_should_deleteUser()
|
|
{
|
|
final AccountDeletedEvent event = new AccountDeletedEvent(UserId.of("12345"));
|
|
final UserRepository repository = mock(UserRepository.class);
|
|
|
|
final ArgumentCaptor<UserId> captor = ArgumentCaptor.forClass(UserId.class);
|
|
|
|
new UserContextEventListener(repository).update(null, event);
|
|
verify(repository).deleteUserById(captor.capture());
|
|
|
|
assertNotNull(captor.getValue());
|
|
assertEquals("12345", captor.getValue().getIdentifier(), "No correct userId");
|
|
then(repository).should().deleteUserById(any(UserId.class));
|
|
then(repository).shouldHaveNoMoreInteractions();
|
|
}
|
|
}
|