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.

41 lines
1.2 KiB

  1. package de.fd.fh.server.access;
  2. import de.fd.fh.server.user.UserId;
  3. import dev.morphia.Datastore;
  4. import dev.morphia.Key;
  5. import org.junit.jupiter.api.BeforeEach;
  6. import org.junit.jupiter.api.Test;
  7. import org.mockito.Mock;
  8. import static org.hamcrest.MatcherAssert.assertThat;
  9. import static org.hamcrest.Matchers.notNullValue;
  10. import static org.mockito.ArgumentMatchers.any;
  11. import static org.mockito.BDDMockito.then;
  12. import static org.mockito.Mockito.mock;
  13. import static org.mockito.Mockito.when;
  14. class AccessRepositoryTest
  15. {
  16. @Mock
  17. private Datastore datastore;
  18. @BeforeEach
  19. public void before()
  20. {
  21. datastore = mock(Datastore.class);
  22. }
  23. @Test
  24. void given_newUser_when_saveUser_should_storeUserInDatabase()
  25. {
  26. when(datastore.save(any(Access.class)))
  27. .thenReturn(new Key<>(Access.class, "collection", "id"));
  28. final Access access = new Access("testId", "testName", "testPwd", UserId.of("userId"),
  29. null, Role.USER);
  30. final Key<Access> result = new AccessRepository(datastore).save(access);
  31. assertThat("Key is null", result, notNullValue());
  32. then(datastore).should().save(any(Access.class));
  33. }
  34. }