From 333de7c404806017907788b1cb61648ccb9cec09 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Fri, 30 Oct 2020 11:12:32 +0100 Subject: [PATCH] fix unit tests --- .../sonia/scm/security/SyncingRealmHelperTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scm-core/src/test/java/sonia/scm/security/SyncingRealmHelperTest.java b/scm-core/src/test/java/sonia/scm/security/SyncingRealmHelperTest.java index cd0a1c47c6..81bf6d1a09 100644 --- a/scm-core/src/test/java/sonia/scm/security/SyncingRealmHelperTest.java +++ b/scm-core/src/test/java/sonia/scm/security/SyncingRealmHelperTest.java @@ -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 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 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); }