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.
40 lines
1.1 KiB
40 lines
1.1 KiB
package de.fd.fh.server.user;
|
|
|
|
import dev.morphia.Datastore;
|
|
import dev.morphia.Key;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.Mock;
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.BDDMockito.then;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
class UserRepositoryTest
|
|
{
|
|
@Mock
|
|
private Datastore datastore;
|
|
|
|
@BeforeEach
|
|
public void before()
|
|
{
|
|
datastore = mock(Datastore.class);
|
|
}
|
|
|
|
@Test
|
|
void given_newUser_when_saveUser_should_storeUserInDatabase()
|
|
{
|
|
when(datastore.save(any(User.class)))
|
|
.thenReturn(new Key<>(User.class, "collection", "id"));
|
|
|
|
final User access = new User(UserId.of("userId"), "testName");
|
|
|
|
final Key<User> result = new UserRepository(datastore).save(access);
|
|
|
|
assertThat("Key is null", result, notNullValue());
|
|
then(datastore).should().save(any(User.class));
|
|
}
|
|
}
|