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.

39 lines
1.1 KiB

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