fix unit tests

This commit is contained in:
Eduard Heimbuch
2020-10-30 11:12:32 +01:00
parent baefc9f9a3
commit 333de7c404

View File

@@ -32,6 +32,7 @@ import org.apache.shiro.authc.AuthenticationInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import sonia.scm.AlreadyExistsException;
@@ -48,6 +49,7 @@ import java.io.IOException;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
@@ -149,10 +151,15 @@ public class SyncingRealmHelperTest {
*/
@Test
public void testStoreUserCreate() {
ArgumentCaptor<User> userArgumentCaptor = ArgumentCaptor.forClass(User.class);
User user = new User("tricia");
helper.store(user);
verify(userManager, times(1)).create(user);
verify(userManager, times(1)).create(userArgumentCaptor.capture());
User value = userArgumentCaptor.getValue();
assertEquals(user.getDisplayName(), value.getDisplayName());
assertEquals(user.getName(), value.getName());
}
/**
@@ -160,9 +167,10 @@ public class SyncingRealmHelperTest {
*/
@Test(expected = IllegalStateException.class)
public void testStoreUserFailure() {
ArgumentCaptor<User> userArgumentCaptor = ArgumentCaptor.forClass(User.class);
User user = new User("tricia");
doThrow(AlreadyExistsException.class).when(userManager).create(user);
doThrow(AlreadyExistsException.class).when(userManager).create(userArgumentCaptor.capture());
helper.store(user);
}