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.

42 lines
1.2 KiB

package de.fd.fh.server.access;
import de.fd.fh.server.user.UserId;
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 AccessRepositoryTest
{
@Mock
private Datastore datastore;
@BeforeEach
public void before()
{
datastore = mock(Datastore.class);
}
@Test
void given_newUser_when_saveUser_should_storeUserInDatabase()
{
when(datastore.save(any(Access.class)))
.thenReturn(new Key<>(Access.class, "collection", "id"));
final Access access = new Access("testId", "testName", "testPwd", UserId.of("userId"),
null, Role.USER);
final Key<Access> result = new AccessRepository(datastore).save(access);
assertThat("Key is null", result, notNullValue());
then(datastore).should().save(any(Access.class));
}
}