diff --git a/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java b/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java index c897c6b4..a1b66378 100644 --- a/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java +++ b/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java @@ -26,8 +26,7 @@ import javax.naming.directory.InitialDirContext; import org.junit.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the NamingException class. @@ -46,9 +45,10 @@ public class NamingExceptionTests { NamingException exception = new NameAlreadyBoundException(wrappedException); writeToStream(exception); NamingException deSerializedException = readFromStream(); - assertNotNull("Original exception resolvedObj after serialization should not be null", - exception.getResolvedObj()); - assertNull("De-serialized exception resolvedObj should be null", deSerializedException.getResolvedObj()); + assertThat(exception.getResolvedObj()) + .withFailMessage("Original exception resolvedObj after serialization should not be null").isNotNull(); + assertThat(deSerializedException.getResolvedObj()) + .withFailMessage("De-serialized exception resolvedObj should be null").isNull(); } private NamingException readFromStream() throws IOException, ClassNotFoundException { diff --git a/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java b/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java index 53cf6314..a4623681 100644 --- a/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java +++ b/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java @@ -23,8 +23,8 @@ import org.springframework.ldap.core.AuthenticationSource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; public class DefaultValuesAuthenticationSourceDecoratorTests { @@ -47,7 +47,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTests { @Test public void testGetPrincipal_TargetHasPrincipal() { - when(this.authenticationSourceMock.getPrincipal()).thenReturn("cn=someUser"); + given(this.authenticationSourceMock.getPrincipal()).willReturn("cn=someUser"); String principal = this.tested.getPrincipal(); assertThat(principal).isEqualTo("cn=someUser"); @@ -55,7 +55,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTests { @Test public void testGetPrincipal_TargetHasNoPrincipal() { - when(this.authenticationSourceMock.getPrincipal()).thenReturn(""); + given(this.authenticationSourceMock.getPrincipal()).willReturn(""); String principal = this.tested.getPrincipal(); @@ -64,8 +64,8 @@ public class DefaultValuesAuthenticationSourceDecoratorTests { @Test public void testGetCredentials_TargetHasPrincipal() { - when(this.authenticationSourceMock.getPrincipal()).thenReturn("cn=someUser"); - when(this.authenticationSourceMock.getCredentials()).thenReturn("somepassword"); + given(this.authenticationSourceMock.getPrincipal()).willReturn("cn=someUser"); + given(this.authenticationSourceMock.getCredentials()).willReturn("somepassword"); String credentials = this.tested.getCredentials(); @@ -74,8 +74,8 @@ public class DefaultValuesAuthenticationSourceDecoratorTests { @Test public void testGetCredentials_TargetHasNoPrincipal() { - when(this.authenticationSourceMock.getPrincipal()).thenReturn(""); - when(this.authenticationSourceMock.getCredentials()).thenReturn("somepassword"); + given(this.authenticationSourceMock.getPrincipal()).willReturn(""); + given(this.authenticationSourceMock.getCredentials()).willReturn("somepassword"); String credentials = this.tested.getCredentials(); diff --git a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java index 7d4545e6..b72a0ea9 100644 --- a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java +++ b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java @@ -51,7 +51,6 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertArrayEquals; /** * @author Mattias Hellborg Arthursson @@ -192,8 +191,8 @@ public class LdapTemplateNamespaceHandlerTests { assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" }, - (Object[]) getInternalState(contextSource, "urls")); + assertThat(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" }) + .isEqualTo(getInternalState(contextSource, "urls")); } @@ -207,8 +206,8 @@ public class LdapTemplateNamespaceHandlerTests { assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" }, - (Object[]) getInternalState(contextSource, "urls")); + assertThat(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" }) + .isEqualTo(getInternalState(contextSource, "urls")); } diff --git a/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java b/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java index 35727505..7bad249f 100644 --- a/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java @@ -32,8 +32,8 @@ import org.junit.Before; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; public class PagedResultsDirContextProcessorTests { @@ -82,7 +82,7 @@ public class PagedResultsDirContextProcessorTests { byte[] cookie = encodeValue(resultSize, value); PagedResultsResponseControl control = new PagedResultsResponseControl("dummy", true, cookie); - when(this.ldapContextMock.getResponseControls()).thenReturn(new Control[] { control }); + given(this.ldapContextMock.getResponseControls()).willReturn(new Control[] { control }); this.tested.postProcess(this.ldapContextMock); PagedResultsCookie returnedCookie = this.tested.getCookie(); @@ -103,7 +103,7 @@ public class PagedResultsDirContextProcessorTests { // Using another response control to verify that it is ignored DirSyncResponseControl control = new DirSyncResponseControl("dummy", true, cookie); - when(this.ldapContextMock.getResponseControls()).thenReturn(new Control[] { control }); + given(this.ldapContextMock.getResponseControls()).willReturn(new Control[] { control }); this.tested.postProcess(this.ldapContextMock); assertThat(this.tested.getCookie()).isNull(); @@ -113,7 +113,7 @@ public class PagedResultsDirContextProcessorTests { @Test public void testPostProcess_NoResponseControls() throws Exception { - when(this.ldapContextMock.getResponseControls()).thenReturn(null); + given(this.ldapContextMock.getResponseControls()).willReturn(null); this.tested.postProcess(this.ldapContextMock); diff --git a/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java b/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java index aff46d7e..f72bef39 100644 --- a/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java @@ -26,9 +26,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; public class RequestControlDirContextProcessorTests { @@ -80,7 +80,7 @@ public class RequestControlDirContextProcessorTests { @Test public void testPreProcessWithExistingControlOfDifferentClassShouldAdd() throws Exception { SortControl existingControl = new SortControl(new String[] { "cn" }, true); - when(this.ldapContextMock.getRequestControls()).thenReturn(new Control[] { existingControl }); + given(this.ldapContextMock.getRequestControls()).willReturn(new Control[] { existingControl }); this.tested.preProcess(this.ldapContextMock); @@ -89,7 +89,7 @@ public class RequestControlDirContextProcessorTests { @Test public void testPreProcessWithExistingControlOfSameClassShouldReplace() throws Exception { - when(this.ldapContextMock.getRequestControls()).thenReturn(new Control[] { this.requestControl2Mock }); + given(this.ldapContextMock.getRequestControls()).willReturn(new Control[] { this.requestControl2Mock }); this.tested.preProcess(this.ldapContextMock); @@ -98,7 +98,7 @@ public class RequestControlDirContextProcessorTests { @Test public void testPreProcessWithExistingControlOfSameClassAndPropertyFalseShouldAdd() throws Exception { - when(this.ldapContextMock.getRequestControls()).thenReturn(new Control[] { this.requestControl2Mock }); + given(this.ldapContextMock.getRequestControls()).willReturn(new Control[] { this.requestControl2Mock }); this.tested.setReplaceSameControlEnabled(false); this.tested.preProcess(this.ldapContextMock); @@ -109,7 +109,7 @@ public class RequestControlDirContextProcessorTests { @Test public void testPreProcessWithNoExistingControlsShouldAdd() throws NamingException { - when(this.ldapContextMock.getRequestControls()).thenReturn(new Control[0]); + given(this.ldapContextMock.getRequestControls()).willReturn(new Control[0]); this.tested.preProcess(this.ldapContextMock); @@ -118,7 +118,7 @@ public class RequestControlDirContextProcessorTests { @Test public void testPreProcessWithNullControlsShouldAdd() throws NamingException { - when(this.ldapContextMock.getRequestControls()).thenReturn(null); + given(this.ldapContextMock.getRequestControls()).willReturn(null); this.tested.preProcess(this.ldapContextMock); diff --git a/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java b/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java index e05d79a5..9c6ae6ae 100644 --- a/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java @@ -31,8 +31,8 @@ import org.junit.Before; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; /** * Unit tests for the SortControlDirContextProcessor class. @@ -68,7 +68,7 @@ public class SortControlDirContextProcessorTests { byte[] value = encodeValue(sortResult); SortResponseControl control = new SortResponseControl("dummy", true, value); - when(this.ldapContextMock.getResponseControls()).thenReturn(new Control[] { control }); + given(this.ldapContextMock.getResponseControls()).willReturn(new Control[] { control }); this.tested.postProcess(this.ldapContextMock); @@ -83,7 +83,7 @@ public class SortControlDirContextProcessorTests { byte[] value = encodeValue(sortResult); SortResponseControl control = new SortResponseControl("dummy", true, value); - when(this.ldapContextMock.getResponseControls()).thenReturn(new Control[] { control }); + given(this.ldapContextMock.getResponseControls()).willReturn(new Control[] { control }); this.tested.postProcess(this.ldapContextMock); @@ -103,7 +103,7 @@ public class SortControlDirContextProcessorTests { // Using another response control to verify that it is ignored DirSyncResponseControl control = new DirSyncResponseControl("dummy", true, cookie); - when(this.ldapContextMock.getResponseControls()).thenReturn(new Control[] { control }); + given(this.ldapContextMock.getResponseControls()).willReturn(new Control[] { control }); this.tested.postProcess(this.ldapContextMock); diff --git a/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java b/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java index 4960b71b..598b081f 100644 --- a/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java +++ b/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java @@ -23,8 +23,8 @@ import org.junit.Before; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; public class ContextMapperCallbackHandlerTests { @@ -49,7 +49,7 @@ public class ContextMapperCallbackHandlerTests { Object expectedResult = "result"; Binding expectedBinding = new Binding("some name", expectedObject); - when(this.mapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.mapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); Object actualResult = this.tested.getObjectFromNameClassPair(expectedBinding); assertThat(actualResult).isEqualTo(expectedResult); } diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java index 583234aa..5b72ec0a 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java @@ -37,9 +37,9 @@ import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; /** * Unit tests for the list operations in {@link LdapTemplate}. @@ -81,24 +81,24 @@ public class DefaultLdapClientListTests { } private void expectGetReadOnlyContext() { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); } private void setupListAndNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.dirContextMock.list(this.nameMock)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.list(this.nameMock)).willReturn(this.namingEnumerationMock); setupNamingEnumeration(listResult); } private void setupListBindingsAndNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.dirContextMock.listBindings(this.nameMock)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(this.nameMock)).willReturn(this.namingEnumerationMock); setupNamingEnumeration(listResult); } private void setupNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(listResult); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(listResult); } @Test @@ -141,7 +141,7 @@ public class DefaultLdapClientListTests { public void testList_PartialResultException() throws NamingException { expectGetReadOnlyContext(); javax.naming.PartialResultException pre = new javax.naming.PartialResultException(); - when(this.dirContextMock.list(this.nameMock)).thenThrow(pre); + given(this.dirContextMock.list(this.nameMock)).willThrow(pre); assertThatExceptionOfType(PartialResultException.class) .isThrownBy(() -> this.tested.list(NAME).toList(NameClassPair::getName)); @@ -153,7 +153,7 @@ public class DefaultLdapClientListTests { public void testList_Stream_PartialResultException() throws NamingException { expectGetReadOnlyContext(); javax.naming.PartialResultException pre = new javax.naming.PartialResultException(); - when(this.dirContextMock.list(this.nameMock)).thenThrow(pre); + given(this.dirContextMock.list(this.nameMock)).willThrow(pre); assertThatExceptionOfType(PartialResultException.class) .isThrownBy(() -> this.tested.list(NAME).toStream(NameClassPair::getName).collect(Collectors.toList())); @@ -166,7 +166,7 @@ public class DefaultLdapClientListTests { expectGetReadOnlyContext(); javax.naming.PartialResultException pre = new javax.naming.PartialResultException(); - when(this.dirContextMock.list(this.nameMock)).thenThrow(pre); + given(this.dirContextMock.list(this.nameMock)).willThrow(pre); this.tested.setIgnorePartialResultException(true); @@ -183,7 +183,7 @@ public class DefaultLdapClientListTests { expectGetReadOnlyContext(); javax.naming.PartialResultException pre = new javax.naming.PartialResultException(); - when(this.dirContextMock.list(this.nameMock)).thenThrow(pre); + given(this.dirContextMock.list(this.nameMock)).willThrow(pre); this.tested.setIgnorePartialResultException(true); @@ -200,7 +200,7 @@ public class DefaultLdapClientListTests { public void testList_NamingException() throws NamingException { expectGetReadOnlyContext(); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.dirContextMock.list(this.nameMock)).thenThrow(ne); + given(this.dirContextMock.list(this.nameMock)).willThrow(ne); assertThatExceptionOfType(LimitExceededException.class) .isThrownBy(() -> this.tested.list(NAME).toList(NameClassPair::getName)); verify(this.dirContextMock).close(); @@ -210,7 +210,7 @@ public class DefaultLdapClientListTests { public void testList_AsStream_NamingException() throws NamingException { expectGetReadOnlyContext(); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.dirContextMock.list(this.nameMock)).thenThrow(ne); + given(this.dirContextMock.list(this.nameMock)).willThrow(ne); assertThatExceptionOfType(LimitExceededException.class) .isThrownBy(() -> this.tested.list(NAME).toStream(NameClassPair::getName).collect(Collectors.toList())); verify(this.dirContextMock).close(); @@ -302,7 +302,7 @@ public class DefaultLdapClientListTests { setupListBindingsAndNamingEnumeration(listResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.listBindings(NAME).toList(this.contextMapperMock); @@ -324,7 +324,7 @@ public class DefaultLdapClientListTests { setupListBindingsAndNamingEnumeration(listResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); try (Stream results = this.tested.listBindings(NAME).toStream(this.contextMapperMock)) { List list = results.collect(Collectors.toList()); @@ -347,7 +347,7 @@ public class DefaultLdapClientListTests { setupListBindingsAndNamingEnumeration(listResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.listBindings(this.nameMock).toList(this.contextMapperMock); @@ -369,7 +369,7 @@ public class DefaultLdapClientListTests { setupListBindingsAndNamingEnumeration(listResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); try (Stream results = this.tested.listBindings(this.nameMock).toStream(this.contextMapperMock)) { List list = results.collect(Collectors.toList()); diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java index f3f124ea..1e323a7c 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java @@ -29,7 +29,7 @@ import javax.naming.ldap.LdapContext; import org.junit.Before; import org.junit.Test; -import org.mockito.stubbing.OngoingStubbing; +import org.mockito.BDDMockito; import org.springframework.LdapDataEntry; import org.springframework.ldap.NameNotFoundException; @@ -40,9 +40,9 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; public class DefaultLdapClientLookupTests { @@ -64,7 +64,7 @@ public class DefaultLdapClientLookupTests { } private void expectGetReadOnlyContext() { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); } @Test @@ -72,7 +72,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); LdapDataEntry expected = new DirContextAdapter(); - whenSearching(this.name).thenReturn(result(expected, null)); + whenSearching(this.name).willReturn(result(expected, null)); LdapDataEntry actual = this.tested.search().name(this.name).toEntry(); @@ -85,7 +85,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); LdapDataEntry expected = new DirContextAdapter(); - whenSearching(DEFAULT_BASE).thenReturn(result(expected, null)); + whenSearching(DEFAULT_BASE).willReturn(result(expected, null)); LdapDataEntry actual = this.tested.search().name(DEFAULT_BASE.toString()).toEntry(); @@ -98,7 +98,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - whenSearching(this.name).thenThrow(ne); + whenSearching(this.name).willThrow(ne); assertThatExceptionOfType(NameNotFoundException.class).describedAs("NameNotFoundException expected") .isThrownBy(() -> this.tested.search().name(this.name).toEntry()); @@ -110,7 +110,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); Attributes expected = new BasicAttributes(); - whenSearching(this.name).thenReturn(result(null, expected)); + whenSearching(this.name).willReturn(result(null, expected)); AttributesMapper mapper = (attributes) -> attributes; Attributes actual = this.tested.search().name(this.name).toObject(mapper); @@ -124,7 +124,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); Attributes expected = new BasicAttributes(); - whenSearching(DEFAULT_BASE).thenReturn(result(null, expected)); + whenSearching(DEFAULT_BASE).willReturn(result(null, expected)); AttributesMapper mapper = (attributes) -> attributes; Attributes actual = this.tested.search().name(DEFAULT_BASE.toString()).toObject(mapper); @@ -138,7 +138,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - whenSearching(this.name).thenThrow(ne); + whenSearching(this.name).willThrow(ne); AttributesMapper mapper = (attributes) -> attributes; assertThatExceptionOfType(NameNotFoundException.class).describedAs("NameNotFoundException expected") @@ -153,7 +153,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); Object expected = new Object(); - whenSearching(this.name).thenReturn(result(expected, null)); + whenSearching(this.name).willReturn(result(expected, null)); ContextMapper mapper = (ctx) -> ctx; Object actual = this.tested.search().name(this.name).toObject(mapper); @@ -167,7 +167,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); Object expected = new Object(); - whenSearching(DEFAULT_BASE).thenReturn(result(expected, null)); + whenSearching(DEFAULT_BASE).willReturn(result(expected, null)); ContextMapper mapper = (ctx) -> ctx; Object actual = this.tested.search().name(DEFAULT_BASE.toString()).toObject(mapper); @@ -181,7 +181,7 @@ public class DefaultLdapClientLookupTests { expectGetReadOnlyContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - whenSearching(this.name).thenThrow(ne); + whenSearching(this.name).willThrow(ne); ContextMapper mapper = (ctx) -> ctx; assertThatExceptionOfType(NameNotFoundException.class).describedAs("NameNotFoundException expected") @@ -197,8 +197,9 @@ public class DefaultLdapClientLookupTests { return new NamingEnumeration(results); } - private OngoingStubbing> whenSearching(Name name) throws Exception { - return when(this.dirContextMock.search(eq(name), anyString(), any())); + private BDDMockito.BDDMyOngoingStubbing> whenSearching(Name name) + throws Exception { + return given(this.dirContextMock.search(eq(name), anyString(), any())); } private static class NamingEnumeration implements javax.naming.NamingEnumeration { diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java index 8a47acc1..678061a7 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java @@ -29,10 +29,10 @@ import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; /** * Unit tests for the rename operations in the LdapTemplate class. @@ -63,7 +63,7 @@ public class DefaultLdapClientRenameTests { } private void expectGetReadWriteContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); } @Test @@ -81,7 +81,7 @@ public class DefaultLdapClientRenameTests { expectGetReadWriteContext(); javax.naming.NameAlreadyBoundException ne = new javax.naming.NameAlreadyBoundException(); - doThrow(ne).when(this.dirContextMock).rename(this.oldName, this.newName); + willThrow(ne).given(this.dirContextMock).rename(this.oldName, this.newName); try { this.tested.modify(this.oldName).name(this.newName).execute(); @@ -100,7 +100,7 @@ public class DefaultLdapClientRenameTests { javax.naming.NamingException ne = new javax.naming.NamingException(); - doThrow(ne).when(this.dirContextMock).rename(this.oldName, this.newName); + willThrow(ne).given(this.dirContextMock).rename(this.oldName, this.newName); try { this.tested.modify(this.oldName).name(this.newName).execute(); diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java index 73afca85..2b23e940 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java @@ -53,11 +53,11 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.times; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; /** * Unit tests for {@link LdapClient} @@ -131,11 +131,11 @@ public class DefaultLdapClientTests { } private void expectGetReadWriteContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); } private void expectGetReadOnlyContext() { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); } @Test @@ -216,8 +216,8 @@ public class DefaultLdapClientTests { controls.setReturningObjFlag(false); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException("some text"); - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenThrow(ne); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willThrow(ne); try { this.tested.search().query( @@ -239,8 +239,8 @@ public class DefaultLdapClientTests { controls.setReturningObjFlag(false); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenThrow(ne); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willThrow(ne); try { this.tested.search().query((builder) -> builder.base(this.nameMock).filter("(ou=somevalue)")) @@ -257,13 +257,13 @@ public class DefaultLdapClientTests { @Test public void verifyThatDefaultSearchControlParametersAreAutomaticallyAppliedInSearch() throws Exception { Supplier defaults = mock(Supplier.class); - when(defaults.get()).thenReturn(new SearchControls()); + given(defaults.get()).willReturn(new SearchControls()); LdapClient tested = LdapClient.builder().contextSource(this.contextSourceMock).defaultSearchControls(defaults) .build(); expectGetReadOnlyContext(); - when(this.dirContextMock.search(eq(this.nameMock), anyString(), any())).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(this.nameMock), anyString(), any())).willReturn(this.namingEnumerationMock); tested.search().name(this.nameMock).toEntry(); verify(defaults).get(); @@ -302,7 +302,7 @@ public class DefaultLdapClientTests { ModificationItem[] mods = new ModificationItem[1]; javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - doThrow(ne).when(this.dirContextMock).modifyAttributes(this.nameMock, mods); + willThrow(ne).given(this.dirContextMock).modifyAttributes(this.nameMock, mods); try { this.tested.modify(this.nameMock).attributes(mods).execute(); @@ -349,7 +349,7 @@ public class DefaultLdapClientTests { Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - doThrow(ne).when(this.dirContextMock).bind(this.nameMock, expectedObject, expectedAttributes); + willThrow(ne).given(this.dirContextMock).bind(this.nameMock, expectedObject, expectedAttributes); try { this.tested.bind(this.nameMock).object(expectedObject).attributes(expectedAttributes).execute(); @@ -366,8 +366,8 @@ public class DefaultLdapClientTests { public void testBindWithContext() throws Exception { expectGetReadWriteContext(); - when(this.dirContextOperationsMock.getDn()).thenReturn(this.nameMock); - when(this.dirContextOperationsMock.isUpdateMode()).thenReturn(false); + given(this.dirContextOperationsMock.getDn()).willReturn(this.nameMock); + given(this.dirContextOperationsMock.isUpdateMode()).willReturn(false); this.tested.bind(this.nameMock).object(this.dirContextOperationsMock).execute(); @@ -379,8 +379,8 @@ public class DefaultLdapClientTests { public void testRebindWithContext() throws Exception { expectGetReadWriteContext(); - when(this.dirContextOperationsMock.getDn()).thenReturn(this.nameMock); - when(this.dirContextOperationsMock.isUpdateMode()).thenReturn(false); + given(this.dirContextOperationsMock.getDn()).willReturn(this.nameMock); + given(this.dirContextOperationsMock.isUpdateMode()).willReturn(false); this.tested.bind(this.nameMock).object(this.dirContextOperationsMock).replaceExisting(true).execute(); @@ -440,14 +440,14 @@ public class DefaultLdapClientTests { public void testUnbindRecursive() throws Exception { expectGetReadWriteContext(); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false, false); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false, false); Binding binding = new Binding("cn=Some name", null); - when(this.namingEnumerationMock.next()).thenReturn(binding); + given(this.namingEnumerationMock.next()).willReturn(binding); LdapName listDn = LdapUtils.newLdapName(DEFAULT_BASE); - when(this.dirContextMock.listBindings(listDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(listDn)).willReturn(this.namingEnumerationMock); LdapName subListDn = LdapUtils.newLdapName("cn=Some name, o=example.com"); - when(this.dirContextMock.listBindings(subListDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(subListDn)).willReturn(this.namingEnumerationMock); this.tested.unbind(new CompositeName(DEFAULT_BASE.toString())).recursive(true).execute(); @@ -461,14 +461,14 @@ public class DefaultLdapClientTests { public void testUnbindRecursive_String() throws Exception { expectGetReadWriteContext(); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false, false); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false, false); Binding binding = new Binding("cn=Some name", null); - when(this.namingEnumerationMock.next()).thenReturn(binding); + given(this.namingEnumerationMock.next()).willReturn(binding); LdapName listDn = LdapUtils.newLdapName(DEFAULT_BASE); - when(this.dirContextMock.listBindings(listDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(listDn)).willReturn(this.namingEnumerationMock); LdapName subListDn = LdapUtils.newLdapName("cn=Some name, o=example.com"); - when(this.dirContextMock.listBindings(subListDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(subListDn)).willReturn(this.namingEnumerationMock); this.tested.unbind(DEFAULT_BASE.toString()).recursive(true).execute(); @@ -483,7 +483,7 @@ public class DefaultLdapClientTests { expectGetReadWriteContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - doThrow(ne).when(this.dirContextMock).unbind(this.nameMock); + willThrow(ne).given(this.dirContextMock).unbind(this.nameMock); try { this.tested.unbind(this.nameMock).execute(); @@ -501,7 +501,7 @@ public class DefaultLdapClientTests { expectGetReadOnlyContext(); javax.naming.PartialResultException ex = new javax.naming.PartialResultException(); - when(this.dirContextMock.search(eq(this.nameMock), anyString(), any())).thenThrow(ex); + given(this.dirContextMock.search(eq(this.nameMock), anyString(), any())).willThrow(ex); try { this.tested.search().name(this.nameMock).toEntryList(); @@ -521,8 +521,8 @@ public class DefaultLdapClientTests { expectGetReadOnlyContext(); - when(this.dirContextMock.search(eq(this.nameMock), anyString(), any())) - .thenThrow(javax.naming.PartialResultException.class); + given(this.dirContextMock.search(eq(this.nameMock), anyString(), any())) + .willThrow(javax.naming.PartialResultException.class); tested.search().name(this.nameMock).toEntryStream(); @@ -534,16 +534,16 @@ public class DefaultLdapClientTests { AuthenticatedLdapEntryContextMapper entryContextMapper = mock( AuthenticatedLdapEntryContextMapper.class); - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(searchControlsRecursive(), searchResult); - when(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) - .thenReturn(this.authenticatedContextMock); - when(entryContextMapper.mapWithContext(any(), any())).thenReturn(new Object()); + given(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) + .willReturn(this.authenticatedContextMock); + given(entryContextMapper.mapWithContext(any(), any())).willReturn(new Object()); LdapQuery query = LdapQueryBuilder.query().base(this.nameMock).filter("(ou=somevalue)"); Object result = this.tested.authenticate().query(query).password("password").execute(entryContextMapper); @@ -555,7 +555,7 @@ public class DefaultLdapClientTests { @Test public void testAuthenticateWithTwoUsersFoundShouldThrowException() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); @@ -578,7 +578,7 @@ public class DefaultLdapClientTests { @Test public void testAuthenticateWhenNoUserWasFoundShouldFail() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); noSearchResults(searchControlsRecursive()); @@ -592,7 +592,7 @@ public class DefaultLdapClientTests { @Test @SuppressWarnings("unchecked") public void testAuthenticateQueryPasswordWhenNoUserWasFoundShouldThrowEmptyResult() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); noSearchResults(searchControlsRecursive()); @@ -605,7 +605,7 @@ public class DefaultLdapClientTests { @Test public void testAuthenticateWithFailedAuthenticationShouldFail() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); @@ -613,8 +613,8 @@ public class DefaultLdapClientTests { singleSearchResult(searchControlsRecursive(), searchResult); - when(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) - .thenThrow(new UncategorizedLdapException("Authentication failed")); + given(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) + .willThrow(new UncategorizedLdapException("Authentication failed")); LdapQuery query = LdapQueryBuilder.query().base(this.nameMock).filter("(ou=somevalue)"); assertThatExceptionOfType(UncategorizedLdapException.class) @@ -623,10 +623,10 @@ public class DefaultLdapClientTests { } private void noSearchResults(SearchControls controls) throws Exception { - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(false); + given(this.namingEnumerationMock.hasMore()).willReturn(false); } private void singleSearchResult(SearchControls controls, SearchResult searchResult) throws Exception { @@ -634,16 +634,16 @@ public class DefaultLdapClientTests { } private void setupSearchResults(SearchControls controls, SearchResult... searchResults) throws Exception { - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willReturn(this.namingEnumerationMock); if (searchResults.length == 1) { - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResults[0]); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResults[0]); } else if (searchResults.length == 2) { - when(this.namingEnumerationMock.hasMore()).thenReturn(true, true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResults[0], searchResults[1]); + given(this.namingEnumerationMock.hasMore()).willReturn(true, true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResults[0], searchResults[1]); } else { throw new IllegalArgumentException("Cannot handle " + searchResults.length + " search results"); @@ -651,11 +651,11 @@ public class DefaultLdapClientTests { } private void singleSearchResultWithStringBase(SearchControls controls, SearchResult searchResult) throws Exception { - when(this.dirContextMock.search(eq(DEFAULT_BASE), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(DEFAULT_BASE), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResult); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResult); } private SearchControls searchControlsRecursive() { diff --git a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java index 60da2fe2..f8ab26f3 100644 --- a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java @@ -158,7 +158,7 @@ public class DirContextAdapterTests { } this.tested = new TestableDirContextAdapter(); - String s[] = this.tested.getStringAttributes("abc"); + String[] s = this.tested.getStringAttributes("abc"); assertThat(s[0]).isEqualTo("123"); assertThat(s[1]).isEqualTo("234"); assertThat(s.length).isEqualTo(2); @@ -200,14 +200,14 @@ public class DirContextAdapterTests { } this.tested = new TestableDirContextAdapter(); - String s[] = this.tested.getStringAttributes("abc"); + String[] s = this.tested.getStringAttributes("abc"); assertThat(s).isNotNull(); assertThat(s.length).isEqualTo(0); } @Test public void testGetStringAttributesNotExists() throws Exception { - String s[] = this.tested.getStringAttributes("abc"); + String[] s = this.tested.getStringAttributes("abc"); assertThat(s).isNull(); } @@ -1208,8 +1208,9 @@ public class DirContextAdapterTests { private ModificationItem getModificationItem(ModificationItem[] mods, int operation) { for (int i = 0; i < mods.length; i++) { - if (mods[i].getModificationOp() == operation) + if (mods[i].getModificationOp() == operation) { return mods[i]; + } } return null; } diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java index d9ab1a8a..37495479 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java @@ -34,9 +34,9 @@ import org.springframework.ldap.PartialResultException; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; /** * Unit tests for the list operations in {@link LdapTemplate}. @@ -86,36 +86,36 @@ public class LdapTemplateListTests { } private void expectGetReadOnlyContext() { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); } private void setupStringListAndNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.dirContextMock.list(NAME)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.list(NAME)).willReturn(this.namingEnumerationMock); setupNamingEnumeration(listResult); } private void setupListAndNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.dirContextMock.list(this.nameMock)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.list(this.nameMock)).willReturn(this.namingEnumerationMock); setupNamingEnumeration(listResult); } private void setupStringListBindingsAndNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.dirContextMock.listBindings(NAME)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(NAME)).willReturn(this.namingEnumerationMock); setupNamingEnumeration(listResult); } private void setupListBindingsAndNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.dirContextMock.listBindings(this.nameMock)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(this.nameMock)).willReturn(this.namingEnumerationMock); setupNamingEnumeration(listResult); } private void setupNamingEnumeration(NameClassPair listResult) throws NamingException { - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(listResult); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(listResult); } @Test @@ -189,7 +189,7 @@ public class LdapTemplateListTests { expectGetReadOnlyContext(); javax.naming.PartialResultException pre = new javax.naming.PartialResultException(); - when(this.dirContextMock.list(NAME)).thenThrow(pre); + given(this.dirContextMock.list(NAME)).willThrow(pre); try { this.tested.list(NAME); @@ -207,7 +207,7 @@ public class LdapTemplateListTests { expectGetReadOnlyContext(); javax.naming.PartialResultException pre = new javax.naming.PartialResultException(); - when(this.dirContextMock.list(NAME)).thenThrow(pre); + given(this.dirContextMock.list(NAME)).willThrow(pre); this.tested.setIgnorePartialResultException(true); @@ -224,7 +224,7 @@ public class LdapTemplateListTests { expectGetReadOnlyContext(); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.dirContextMock.list(NAME)).thenThrow(ne); + given(this.dirContextMock.list(NAME)).willThrow(ne); try { this.tested.list(NAME); @@ -285,7 +285,7 @@ public class LdapTemplateListTests { setupStringListBindingsAndNamingEnumeration(listResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.listBindings(NAME, this.contextMapperMock); @@ -307,7 +307,7 @@ public class LdapTemplateListTests { setupListBindingsAndNamingEnumeration(listResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.listBindings(this.nameMock, this.contextMapperMock); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java index 802f6510..63528d64 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java @@ -34,9 +34,9 @@ import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; public class LdapTemplateLookupTests { @@ -75,7 +75,7 @@ public class LdapTemplateLookupTests { } private void expectGetReadOnlyContext() { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); } // Tests for lookup(name) @@ -85,7 +85,7 @@ public class LdapTemplateLookupTests { expectGetReadOnlyContext(); Object expected = new Object(); - when(this.dirContextMock.lookup(this.nameMock)).thenReturn(expected); + given(this.dirContextMock.lookup(this.nameMock)).willReturn(expected); Object actual = this.tested.lookup(this.nameMock); @@ -99,7 +99,7 @@ public class LdapTemplateLookupTests { expectGetReadOnlyContext(); Object expected = new Object(); - when(this.dirContextMock.lookup(DEFAULT_BASE_STRING)).thenReturn(expected); + given(this.dirContextMock.lookup(DEFAULT_BASE_STRING)).willReturn(expected); Object actual = this.tested.lookup(DEFAULT_BASE_STRING); @@ -113,7 +113,7 @@ public class LdapTemplateLookupTests { expectGetReadOnlyContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - when(this.dirContextMock.lookup(this.nameMock)).thenThrow(ne); + given(this.dirContextMock.lookup(this.nameMock)).willThrow(ne); try { this.tested.lookup(this.nameMock); @@ -133,10 +133,10 @@ public class LdapTemplateLookupTests { expectGetReadOnlyContext(); BasicAttributes expectedAttributes = new BasicAttributes(); - when(this.dirContextMock.getAttributes(this.nameMock)).thenReturn(expectedAttributes); + given(this.dirContextMock.getAttributes(this.nameMock)).willReturn(expectedAttributes); Object expected = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expected); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expected); Object actual = this.tested.lookup(this.nameMock, this.attributesMapperMock); @@ -150,10 +150,10 @@ public class LdapTemplateLookupTests { expectGetReadOnlyContext(); BasicAttributes expectedAttributes = new BasicAttributes(); - when(this.dirContextMock.getAttributes(DEFAULT_BASE_STRING)).thenReturn(expectedAttributes); + given(this.dirContextMock.getAttributes(DEFAULT_BASE_STRING)).willReturn(expectedAttributes); Object expected = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expected); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expected); Object actual = this.tested.lookup(DEFAULT_BASE_STRING, this.attributesMapperMock); @@ -167,7 +167,7 @@ public class LdapTemplateLookupTests { expectGetReadOnlyContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - when(this.dirContextMock.getAttributes(this.nameMock)).thenThrow(ne); + given(this.dirContextMock.getAttributes(this.nameMock)).willThrow(ne); try { this.tested.lookup(this.nameMock, this.attributesMapperMock); @@ -188,9 +188,9 @@ public class LdapTemplateLookupTests { Object transformed = new Object(); Object expected = new Object(); - when(this.dirContextMock.lookup(this.nameMock)).thenReturn(expected); + given(this.dirContextMock.lookup(this.nameMock)).willReturn(expected); - when(this.contextMapperMock.mapFromContext(expected)).thenReturn(transformed); + given(this.contextMapperMock.mapFromContext(expected)).willReturn(transformed); Object actual = this.tested.lookup(this.nameMock, this.contextMapperMock); @@ -207,10 +207,10 @@ public class LdapTemplateLookupTests { Class expectedClass = Object.class; DirContextAdapter expectedContext = new DirContextAdapter(); - when(this.dirContextMock.lookup(this.nameMock)).thenReturn(expectedContext); - when(this.odmMock.mapFromLdapDataEntry(expectedContext, expectedClass)).thenReturn(transformed); + given(this.dirContextMock.lookup(this.nameMock)).willReturn(expectedContext); + given(this.odmMock.mapFromLdapDataEntry(expectedContext, expectedClass)).willReturn(transformed); - when(this.nameMock.getAll()).thenReturn(Collections.enumeration(Collections.emptyList())); + given(this.nameMock.getAll()).willReturn(Collections.enumeration(Collections.emptyList())); // Perform test Object result = this.tested.findByDn(this.nameMock, expectedClass); assertThat(result).isSameAs(transformed); @@ -224,9 +224,9 @@ public class LdapTemplateLookupTests { Object transformed = new Object(); Object expected = new Object(); - when(this.dirContextMock.lookup(DEFAULT_BASE_STRING)).thenReturn(expected); + given(this.dirContextMock.lookup(DEFAULT_BASE_STRING)).willReturn(expected); - when(this.contextMapperMock.mapFromContext(expected)).thenReturn(transformed); + given(this.contextMapperMock.mapFromContext(expected)).willReturn(transformed); Object actual = this.tested.lookup(DEFAULT_BASE_STRING, this.contextMapperMock); @@ -240,7 +240,7 @@ public class LdapTemplateLookupTests { expectGetReadOnlyContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - when(this.dirContextMock.lookup(this.nameMock)).thenThrow(ne); + given(this.dirContextMock.lookup(this.nameMock)).willThrow(ne); try { this.tested.lookup(this.nameMock, this.contextMapperMock); @@ -264,10 +264,10 @@ public class LdapTemplateLookupTests { BasicAttributes expectedAttributes = new BasicAttributes(); expectedAttributes.put("cn", "Some Name"); - when(this.dirContextMock.getAttributes(this.nameMock, attributeNames)).thenReturn(expectedAttributes); + given(this.dirContextMock.getAttributes(this.nameMock, attributeNames)).willReturn(expectedAttributes); Object expected = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expected); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expected); Object actual = this.tested.lookup(this.nameMock, attributeNames, this.attributesMapperMock); @@ -285,10 +285,10 @@ public class LdapTemplateLookupTests { BasicAttributes expectedAttributes = new BasicAttributes(); expectedAttributes.put("cn", "Some Name"); - when(this.dirContextMock.getAttributes(DEFAULT_BASE_STRING, attributeNames)).thenReturn(expectedAttributes); + given(this.dirContextMock.getAttributes(DEFAULT_BASE_STRING, attributeNames)).willReturn(expectedAttributes); Object expected = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expected); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expected); Object actual = this.tested.lookup(DEFAULT_BASE_STRING, attributeNames, this.attributesMapperMock); @@ -311,10 +311,10 @@ public class LdapTemplateLookupTests { LdapName name = LdapUtils.newLdapName(DEFAULT_BASE_STRING); DirContextAdapter adapter = new DirContextAdapter(expectedAttributes, name); - when(this.dirContextMock.getAttributes(name, attributeNames)).thenReturn(expectedAttributes); + given(this.dirContextMock.getAttributes(name, attributeNames)).willReturn(expectedAttributes); Object transformed = new Object(); - when(this.contextMapperMock.mapFromContext(adapter)).thenReturn(transformed); + given(this.contextMapperMock.mapFromContext(adapter)).willReturn(transformed); Object actual = this.tested.lookup(name, attributeNames, this.contextMapperMock); @@ -332,13 +332,13 @@ public class LdapTemplateLookupTests { BasicAttributes expectedAttributes = new BasicAttributes(); expectedAttributes.put("cn", "Some Name"); - when(this.dirContextMock.getAttributes(DEFAULT_BASE_STRING, attributeNames)).thenReturn(expectedAttributes); + given(this.dirContextMock.getAttributes(DEFAULT_BASE_STRING, attributeNames)).willReturn(expectedAttributes); LdapName name = LdapUtils.newLdapName(DEFAULT_BASE_STRING); DirContextAdapter adapter = new DirContextAdapter(expectedAttributes, name); Object transformed = new Object(); - when(this.contextMapperMock.mapFromContext(adapter)).thenReturn(transformed); + given(this.contextMapperMock.mapFromContext(adapter)).willReturn(transformed); Object actual = this.tested.lookup(DEFAULT_BASE_STRING, attributeNames, this.contextMapperMock); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java index 976bdd90..bff64add 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java @@ -28,10 +28,10 @@ import org.springframework.ldap.UncategorizedLdapException; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; /** * Unit tests for the rename operations in the LdapTemplate class. @@ -68,7 +68,7 @@ public class LdapTemplateRenameTests { } private void expectGetReadWriteContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); } @Test @@ -86,7 +86,7 @@ public class LdapTemplateRenameTests { expectGetReadWriteContext(); javax.naming.NameAlreadyBoundException ne = new javax.naming.NameAlreadyBoundException(); - doThrow(ne).when(this.dirContextMock).rename(this.oldNameMock, this.newNameMock); + willThrow(ne).given(this.dirContextMock).rename(this.oldNameMock, this.newNameMock); try { this.tested.rename(this.oldNameMock, this.newNameMock); @@ -105,7 +105,7 @@ public class LdapTemplateRenameTests { javax.naming.NamingException ne = new javax.naming.NamingException(); - doThrow(ne).when(this.dirContextMock).rename(this.oldNameMock, this.newNameMock); + willThrow(ne).given(this.dirContextMock).rename(this.oldNameMock, this.newNameMock); try { this.tested.rename(this.oldNameMock, this.newNameMock); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java index 387b044b..c77cece0 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java @@ -55,14 +55,13 @@ import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.springframework.ldap.query.LdapQueryBuilder.query; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.never; +import static org.mockito.BDDMockito.times; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willDoNothing; +import static org.mockito.BDDMockito.willThrow; /** * Unit tests for the LdapTemplate class. @@ -138,11 +137,11 @@ public class LdapTemplateTests { } private void expectGetReadWriteContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); } private void expectGetReadOnlyContext() { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); } @Test @@ -217,8 +216,8 @@ public class LdapTemplateTests { controls.setReturningObjFlag(false); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException("some text"); - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenThrow(ne); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willThrow(ne); try { this.tested.search(this.nameMock, "(ou=somevalue)", this.handlerMock); @@ -238,8 +237,8 @@ public class LdapTemplateTests { controls.setReturningObjFlag(false); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenThrow(ne); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willThrow(ne); try { this.tested.search(this.nameMock, "(ou=somevalue)", this.handlerMock); @@ -306,7 +305,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, this.attributesMapperMock, this.dirContextProcessorMock); @@ -334,7 +333,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", controls, this.attributesMapperMock, this.dirContextProcessorMock); @@ -361,7 +360,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, this.contextMapperMock, this.dirContextProcessorMock); @@ -388,7 +387,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", controls, this.contextMapperMock, this.dirContextProcessorMock); @@ -419,7 +418,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", 1, attrs, this.attributesMapperMock); @@ -447,7 +446,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, attrs, this.attributesMapperMock); @@ -479,7 +478,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", this.attributesMapperMock); @@ -504,7 +503,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", 1, this.attributesMapperMock); @@ -529,7 +528,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, this.attributesMapperMock); @@ -554,7 +553,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", this.attributesMapperMock); @@ -579,7 +578,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", this.attributesMapperMock); @@ -600,7 +599,7 @@ public class LdapTemplateTests { singleSearchResult(searchControlsOneLevel(), searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", 1, this.contextMapperMock); @@ -616,18 +615,18 @@ public class LdapTemplateTests { public void testFindOne() throws Exception { Class expectedClass = Object.class; - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); - when(this.odmMock.filterFor(expectedClass, new EqualsFilter("ou", "somevalue"))) - .thenReturn(new EqualsFilter("ou", "somevalue")); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); + given(this.odmMock.filterFor(expectedClass, new EqualsFilter("ou", "somevalue"))) + .willReturn(new EqualsFilter("ou", "somevalue")); DirContextAdapter expectedObject = new DirContextAdapter(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(searchControlsRecursive(), searchResult); Object expectedResult = expectedObject; - when(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).thenReturn(expectedResult); + given(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).willReturn(expectedResult); - Object result = this.tested.findOne(query().where("ou").is("somevalue"), expectedClass); + Object result = this.tested.findOne(LdapQueryBuilder.query().where("ou").is("somevalue"), expectedClass); verify(this.namingEnumerationMock).close(); verify(this.dirContextMock).close(); @@ -639,14 +638,14 @@ public class LdapTemplateTests { public void verifyThatFindOneThrowsEmptyResultIfNoResult() throws Exception { Class expectedClass = Object.class; - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); - when(this.odmMock.filterFor(expectedClass, new EqualsFilter("ou", "somevalue"))) - .thenReturn(new EqualsFilter("ou", "somevalue")); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); + given(this.odmMock.filterFor(expectedClass, new EqualsFilter("ou", "somevalue"))) + .willReturn(new EqualsFilter("ou", "somevalue")); noSearchResults(searchControlsRecursive()); try { - this.tested.findOne(query().where("ou").is("somevalue"), expectedClass); + this.tested.findOne(LdapQueryBuilder.query().where("ou").is("somevalue"), expectedClass); fail("EmptyResultDataAccessException expected"); } catch (EmptyResultDataAccessException expected) { @@ -662,9 +661,9 @@ public class LdapTemplateTests { public void verifyThatFindOneThrowsIncorrectResultSizeDataAccessExceptionWhenMoreResults() throws Exception { Class expectedClass = Object.class; - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); - when(this.odmMock.filterFor(expectedClass, new EqualsFilter("ou", "somevalue"))) - .thenReturn(new EqualsFilter("ou", "somevalue")); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); + given(this.odmMock.filterFor(expectedClass, new EqualsFilter("ou", "somevalue"))) + .willReturn(new EqualsFilter("ou", "somevalue")); DirContextAdapter expectedObject = new DirContextAdapter(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); @@ -672,11 +671,11 @@ public class LdapTemplateTests { setupSearchResults(searchControlsRecursive(), new SearchResult[] { searchResult, searchResult }); Object expectedResult = expectedObject; - when(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).thenReturn(expectedResult, + given(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).willReturn(expectedResult, expectedResult); try { - this.tested.findOne(query().where("ou").is("somevalue"), expectedClass); + this.tested.findOne(LdapQueryBuilder.query().where("ou").is("somevalue"), expectedClass); fail("EmptyResultDataAccessException expected"); } catch (IncorrectResultSizeDataAccessException expected) { @@ -693,15 +692,15 @@ public class LdapTemplateTests { Class expectedClass = Object.class; Filter filter = new EqualsFilter("ou", "somevalue"); - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); - when(this.odmMock.filterFor(any(Class.class), any(Filter.class))).thenReturn(filter); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); + given(this.odmMock.filterFor(any(Class.class), any(Filter.class))).willReturn(filter); SearchControls controls = new SearchControls(); controls.setReturningAttributes(new String[] { "attribute" }); DirContextAdapter expectedObject = new DirContextAdapter(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); setupSearchResults(controls, searchResult); Object expectedResult = expectedObject; - when(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).thenReturn(expectedResult, + given(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).willReturn(expectedResult, expectedResult); List results = this.tested.find(this.nameMock, filter, controls, expectedClass); @@ -722,15 +721,15 @@ public class LdapTemplateTests { expectedControls.setReturningAttributes(expectedReturningAttributes); Filter filter = new EqualsFilter("ou", "somevalue"); - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); - when(this.odmMock.filterFor(eq(expectedClass), any(Filter.class))).thenReturn(filter); - when(this.odmMock.manageClass(eq(expectedClass))).thenReturn(expectedReturningAttributes); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); + given(this.odmMock.filterFor(eq(expectedClass), any(Filter.class))).willReturn(filter); + given(this.odmMock.manageClass(eq(expectedClass))).willReturn(expectedReturningAttributes); SearchControls controls = new SearchControls(); DirContextAdapter expectedObject = new DirContextAdapter(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); setupSearchResults(expectedControls, searchResult); Object expectedResult = expectedObject; - when(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).thenReturn(expectedResult, + given(this.odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).willReturn(expectedResult, expectedResult); List results = this.tested.find(this.nameMock, filter, controls, expectedClass); @@ -756,7 +755,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", 1, attrs, this.contextMapperMock); @@ -783,7 +782,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, attrs, this.contextMapperMock); @@ -807,7 +806,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, this.contextMapperMock); @@ -829,7 +828,7 @@ public class LdapTemplateTests { singleSearchResult(searchControlsRecursive(), searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", this.contextMapperMock); @@ -853,7 +852,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", this.contextMapperMock); @@ -877,7 +876,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, this.contextMapperMock); @@ -906,7 +905,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(expectedControls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, this.contextMapperMock); @@ -930,7 +929,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", controls, this.contextMapperMock); @@ -955,7 +954,7 @@ public class LdapTemplateTests { singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, this.attributesMapperMock); @@ -980,7 +979,7 @@ public class LdapTemplateTests { singleSearchResult(controls, searchResult); Object expectedResult = new Object(); - when(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); + given(this.attributesMapperMock.mapFromAttributes(expectedAttributes)).willReturn(expectedResult); List list = this.tested.search(this.nameMock, "(ou=somevalue)", controls, this.attributesMapperMock); @@ -1023,7 +1022,7 @@ public class LdapTemplateTests { ModificationItem[] mods = new ModificationItem[0]; javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - doThrow(ne).when(this.dirContextMock).modifyAttributes(this.nameMock, mods); + willThrow(ne).given(this.dirContextMock).modifyAttributes(this.nameMock, mods); try { this.tested.modifyAttributes(this.nameMock, mods); @@ -1070,7 +1069,7 @@ public class LdapTemplateTests { Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - doThrow(ne).when(this.dirContextMock).bind(this.nameMock, expectedObject, expectedAttributes); + willThrow(ne).given(this.dirContextMock).bind(this.nameMock, expectedObject, expectedAttributes); try { this.tested.bind(this.nameMock, expectedObject, expectedAttributes); @@ -1087,8 +1086,8 @@ public class LdapTemplateTests { public void testBindWithContext() throws Exception { expectGetReadWriteContext(); - when(this.dirContextOperationsMock.getDn()).thenReturn(this.nameMock); - when(this.dirContextOperationsMock.isUpdateMode()).thenReturn(false); + given(this.dirContextOperationsMock.getDn()).willReturn(this.nameMock); + given(this.dirContextOperationsMock.isUpdateMode()).willReturn(false); this.tested.bind(this.dirContextOperationsMock); @@ -1102,10 +1101,10 @@ public class LdapTemplateTests { Object expectedObject = new Object(); LdapName expectedName = LdapUtils.newLdapName("ou=someOu"); - when(this.odmMock.getId(expectedObject)).thenReturn(expectedName); + given(this.odmMock.getId(expectedObject)).willReturn(expectedName); ArgumentCaptor ctxCaptor = ArgumentCaptor.forClass(DirContextAdapter.class); - doNothing().when(this.odmMock).mapToLdapDataEntry(eq(expectedObject), ctxCaptor.capture()); + willDoNothing().given(this.odmMock).mapToLdapDataEntry(eq(expectedObject), ctxCaptor.capture()); this.tested.create(expectedObject); @@ -1120,11 +1119,11 @@ public class LdapTemplateTests { Object expectedObject = new Object(); LdapName expectedName = LdapUtils.newLdapName("ou=someOu"); - when(this.odmMock.getId(expectedObject)).thenReturn(null); - when(this.odmMock.getCalculatedId(expectedObject)).thenReturn(expectedName); + given(this.odmMock.getId(expectedObject)).willReturn(null); + given(this.odmMock.getCalculatedId(expectedObject)).willReturn(expectedName); ArgumentCaptor ctxCaptor = ArgumentCaptor.forClass(DirContextAdapter.class); - doNothing().when(this.odmMock).mapToLdapDataEntry(eq(expectedObject), ctxCaptor.capture()); + willDoNothing().given(this.odmMock).mapToLdapDataEntry(eq(expectedObject), ctxCaptor.capture()); this.tested.create(expectedObject); @@ -1136,8 +1135,8 @@ public class LdapTemplateTests { @Test public void testCreateWithNoIdAvailableThrows() throws NamingException { Object expectedObject = new Object(); - when(this.odmMock.getId(expectedObject)).thenReturn(null); - when(this.odmMock.getCalculatedId(expectedObject)).thenReturn(null); + given(this.odmMock.getId(expectedObject)).willReturn(null); + given(this.odmMock.getCalculatedId(expectedObject)).willReturn(null); try { this.tested.create(expectedObject); @@ -1150,21 +1149,21 @@ public class LdapTemplateTests { @Test public void testUpdateWithIdSpecified() throws NamingException { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); LdapName expectedName = LdapUtils.newLdapName("ou=someOu"); ModificationItem[] expectedModificationItems = new ModificationItem[0]; DirContextOperations ctxMock = mock(DirContextOperations.class); - when(ctxMock.getDn()).thenReturn(expectedName); - when(ctxMock.isUpdateMode()).thenReturn(true); - when(ctxMock.getModificationItems()).thenReturn(expectedModificationItems); + given(ctxMock.getDn()).willReturn(expectedName); + given(ctxMock.isUpdateMode()).willReturn(true); + given(ctxMock.getModificationItems()).willReturn(expectedModificationItems); Object expectedObject = new Object(); - when(this.odmMock.getId(expectedObject)).thenReturn(expectedName); - when(this.odmMock.getCalculatedId(expectedObject)).thenReturn(null); + given(this.odmMock.getId(expectedObject)).willReturn(expectedName); + given(this.odmMock.getCalculatedId(expectedObject)).willReturn(null); - when(this.dirContextMock.lookup(expectedName)).thenReturn(ctxMock); + given(this.dirContextMock.lookup(expectedName)).willReturn(ctxMock); this.tested.update(expectedObject); @@ -1177,21 +1176,21 @@ public class LdapTemplateTests { @Test public void testUpdateWithIdCalculated() throws NamingException { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); LdapName expectedName = LdapUtils.newLdapName("ou=someOu"); ModificationItem[] expectedModificationItems = new ModificationItem[0]; DirContextOperations ctxMock = mock(DirContextOperations.class); - when(ctxMock.getDn()).thenReturn(expectedName); - when(ctxMock.isUpdateMode()).thenReturn(true); - when(ctxMock.getModificationItems()).thenReturn(expectedModificationItems); + given(ctxMock.getDn()).willReturn(expectedName); + given(ctxMock.isUpdateMode()).willReturn(true); + given(ctxMock.getModificationItems()).willReturn(expectedModificationItems); Object expectedObject = new Object(); - when(this.odmMock.getId(expectedObject)).thenReturn(null); - when(this.odmMock.getCalculatedId(expectedObject)).thenReturn(expectedName); + given(this.odmMock.getId(expectedObject)).willReturn(null); + given(this.odmMock.getCalculatedId(expectedObject)).willReturn(expectedName); - when(this.dirContextMock.lookup(expectedName)).thenReturn(ctxMock); + given(this.dirContextMock.lookup(expectedName)).willReturn(ctxMock); this.tested.update(expectedObject); @@ -1206,15 +1205,15 @@ public class LdapTemplateTests { public void testUpdateWithIdChanged() throws NamingException { Object expectedObject = new Object(); - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock, this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock, this.dirContextMock); LdapName expectedOriginalName = LdapUtils.newLdapName("ou=someOu"); LdapName expectedNewName = LdapUtils.newLdapName("ou=someOtherOu"); ArgumentCaptor ctxCaptor = ArgumentCaptor.forClass(DirContextAdapter.class); - doNothing().when(this.odmMock).mapToLdapDataEntry(eq(expectedObject), ctxCaptor.capture()); + willDoNothing().given(this.odmMock).mapToLdapDataEntry(eq(expectedObject), ctxCaptor.capture()); - when(this.odmMock.getId(expectedObject)).thenReturn(expectedOriginalName); - when(this.odmMock.getCalculatedId(expectedObject)).thenReturn(expectedNewName); + given(this.odmMock.getId(expectedObject)).willReturn(expectedOriginalName); + given(this.odmMock.getCalculatedId(expectedObject)).willReturn(expectedNewName); this.tested.update(expectedObject); @@ -1248,8 +1247,8 @@ public class LdapTemplateTests { public void testRebindWithContext() throws Exception { expectGetReadWriteContext(); - when(this.dirContextOperationsMock.getDn()).thenReturn(this.nameMock); - when(this.dirContextOperationsMock.isUpdateMode()).thenReturn(false); + given(this.dirContextOperationsMock.getDn()).willReturn(this.nameMock); + given(this.dirContextOperationsMock.isUpdateMode()).willReturn(false); this.tested.rebind(this.dirContextOperationsMock); @@ -1261,14 +1260,14 @@ public class LdapTemplateTests { public void testUnbindRecursive() throws Exception { expectGetReadWriteContext(); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false, false); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false, false); Binding binding = new Binding("cn=Some name", null); - when(this.namingEnumerationMock.next()).thenReturn(binding); + given(this.namingEnumerationMock.next()).willReturn(binding); LdapName listDn = LdapUtils.newLdapName(DEFAULT_BASE_STRING); - when(this.dirContextMock.listBindings(listDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(listDn)).willReturn(this.namingEnumerationMock); LdapName subListDn = LdapUtils.newLdapName("cn=Some name, o=example.com"); - when(this.dirContextMock.listBindings(subListDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(subListDn)).willReturn(this.namingEnumerationMock); this.tested.unbind(new CompositeName(DEFAULT_BASE_STRING), true); @@ -1282,14 +1281,14 @@ public class LdapTemplateTests { public void testUnbindRecursive_String() throws Exception { expectGetReadWriteContext(); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false, false); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false, false); Binding binding = new Binding("cn=Some name", null); - when(this.namingEnumerationMock.next()).thenReturn(binding); + given(this.namingEnumerationMock.next()).willReturn(binding); LdapName listDn = LdapUtils.newLdapName(DEFAULT_BASE_STRING); - when(this.dirContextMock.listBindings(listDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(listDn)).willReturn(this.namingEnumerationMock); LdapName subListDn = LdapUtils.newLdapName("cn=Some name, o=example.com"); - when(this.dirContextMock.listBindings(subListDn)).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.listBindings(subListDn)).willReturn(this.namingEnumerationMock); this.tested.unbind(DEFAULT_BASE_STRING, true); @@ -1330,7 +1329,7 @@ public class LdapTemplateTests { expectGetReadWriteContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - doThrow(ne).when(this.dirContextMock).unbind(this.nameMock); + willThrow(ne).given(this.dirContextMock).unbind(this.nameMock); try { this.tested.unbind(this.nameMock); @@ -1348,7 +1347,7 @@ public class LdapTemplateTests { expectGetReadOnlyContext(); Object object = new Object(); - when(this.contextExecutorMock.executeWithContext(this.dirContextMock)).thenReturn(object); + given(this.contextExecutorMock.executeWithContext(this.dirContextMock)).willReturn(object); Object result = this.tested.executeReadOnly(this.contextExecutorMock); @@ -1362,7 +1361,7 @@ public class LdapTemplateTests { expectGetReadOnlyContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - when(this.contextExecutorMock.executeWithContext(this.dirContextMock)).thenThrow(ne); + given(this.contextExecutorMock.executeWithContext(this.dirContextMock)).willThrow(ne); try { this.tested.executeReadOnly(this.contextExecutorMock); @@ -1380,7 +1379,7 @@ public class LdapTemplateTests { expectGetReadWriteContext(); Object object = new Object(); - when(this.contextExecutorMock.executeWithContext(this.dirContextMock)).thenReturn(object); + given(this.contextExecutorMock.executeWithContext(this.dirContextMock)).willReturn(object); Object result = this.tested.executeReadWrite(this.contextExecutorMock); @@ -1394,7 +1393,7 @@ public class LdapTemplateTests { expectGetReadWriteContext(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); - when(this.contextExecutorMock.executeWithContext(this.dirContextMock)).thenThrow(ne); + given(this.contextExecutorMock.executeWithContext(this.dirContextMock)).willThrow(ne); try { this.tested.executeReadWrite(this.contextExecutorMock); @@ -1413,10 +1412,10 @@ public class LdapTemplateTests { SearchResult searchResult = new SearchResult(null, null, null); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)).thenReturn(this.namingEnumerationMock); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)).willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResult); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResult); this.tested.search(this.searchExecutorMock, this.handlerMock, this.dirContextProcessorMock); @@ -1432,7 +1431,7 @@ public class LdapTemplateTests { expectGetReadOnlyContext(); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)).thenThrow(ne); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)).willThrow(ne); try { this.tested.search(this.searchExecutorMock, this.handlerMock, this.dirContextProcessorMock); @@ -1453,10 +1452,10 @@ public class LdapTemplateTests { SearchResult searchResult = new SearchResult(null, null, null); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)).thenReturn(this.namingEnumerationMock); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)).willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResult); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResult); this.tested.search(this.searchExecutorMock, this.handlerMock); @@ -1470,7 +1469,7 @@ public class LdapTemplateTests { expectGetReadOnlyContext(); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)).thenThrow(ne); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)).willThrow(ne); try { this.tested.search(this.searchExecutorMock, this.handlerMock); @@ -1487,10 +1486,10 @@ public class LdapTemplateTests { public void testDoSearch_NamingException_NamingEnumeration() throws Exception { expectGetReadOnlyContext(); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)).thenReturn(this.namingEnumerationMock); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)).willReturn(this.namingEnumerationMock); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); - when(this.namingEnumerationMock.hasMore()).thenThrow(ne); + given(this.namingEnumerationMock.hasMore()).willThrow(ne); try { this.tested.search(this.searchExecutorMock, this.handlerMock); @@ -1508,8 +1507,8 @@ public class LdapTemplateTests { public void testDoSearch_NameNotFoundException() throws Exception { expectGetReadOnlyContext(); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)) - .thenThrow(new javax.naming.NameNotFoundException()); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)) + .willThrow(new javax.naming.NameNotFoundException()); try { this.tested.search(this.searchExecutorMock, this.handlerMock); @@ -1527,7 +1526,7 @@ public class LdapTemplateTests { expectGetReadOnlyContext(); javax.naming.PartialResultException ex = new javax.naming.PartialResultException(); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)).thenThrow(ex); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)).willThrow(ex); try { this.tested.search(this.searchExecutorMock, this.handlerMock, this.dirContextProcessorMock); @@ -1548,8 +1547,8 @@ public class LdapTemplateTests { expectGetReadOnlyContext(); - when(this.searchExecutorMock.executeSearch(this.dirContextMock)) - .thenThrow(new javax.naming.PartialResultException()); + given(this.searchExecutorMock.executeSearch(this.dirContextMock)) + .willThrow(new javax.naming.PartialResultException()); this.tested.search(this.searchExecutorMock, this.handlerMock, this.dirContextProcessorMock); @@ -1596,9 +1595,9 @@ public class LdapTemplateTests { final ModificationItem[] expectedModifications = new ModificationItem[0]; final LdapName epectedDn = LdapUtils.emptyLdapName(); - when(this.dirContextOperationsMock.getDn()).thenReturn(epectedDn); - when(this.dirContextOperationsMock.isUpdateMode()).thenReturn(true); - when(this.dirContextOperationsMock.getModificationItems()).thenReturn(expectedModifications); + given(this.dirContextOperationsMock.getDn()).willReturn(epectedDn); + given(this.dirContextOperationsMock.isUpdateMode()).willReturn(true); + given(this.dirContextOperationsMock.getModificationItems()).willReturn(expectedModifications); LdapTemplate tested = new LdapTemplate() { public void modifyAttributes(Name dn, ModificationItem[] mods) { @@ -1613,8 +1612,8 @@ public class LdapTemplateTests { @Test public void testModifyAttributesWithDirContextOperationsNotInitializedDn() throws Exception { - when(this.dirContextOperationsMock.getDn()).thenReturn(LdapUtils.emptyLdapName()); - when(this.dirContextOperationsMock.isUpdateMode()).thenReturn(false); + given(this.dirContextOperationsMock.getDn()).willReturn(LdapUtils.emptyLdapName()); + given(this.dirContextOperationsMock.isUpdateMode()).willReturn(false); LdapTemplate tested = new LdapTemplate() { public void modifyAttributes(Name dn, ModificationItem[] mods) { @@ -1633,7 +1632,7 @@ public class LdapTemplateTests { @Test public void testModifyAttributesWithDirContextOperationsNotInitializedInUpdateMode() throws Exception { - when(this.dirContextOperationsMock.getDn()).thenReturn(null); + given(this.dirContextOperationsMock.getDn()).willReturn(null); LdapTemplate tested = new LdapTemplate() { public void modifyAttributes(Name dn, ModificationItem[] mods) { @@ -1660,7 +1659,7 @@ public class LdapTemplateTests { singleSearchResult(searchControlsRecursive(), searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); Object result = this.tested.searchForObject(this.nameMock, "(ou=somevalue)", this.contextMapperMock); @@ -1679,15 +1678,15 @@ public class LdapTemplateTests { Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResult, searchResult); + given(this.namingEnumerationMock.hasMore()).willReturn(true, true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResult, searchResult); Object expectedResult = expectedObject; - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); - when(this.contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); + given(this.contextMapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); try { this.tested.searchForObject(this.nameMock, "(ou=somevalue)", this.contextMapperMock); @@ -1720,7 +1719,7 @@ public class LdapTemplateTests { @Test public void testAuthenticateWithSingleUserFoundShouldBeSuccessful() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); @@ -1728,8 +1727,8 @@ public class LdapTemplateTests { singleSearchResult(searchControlsRecursive(), searchResult); - when(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) - .thenReturn(this.authenticatedContextMock); + given(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) + .willReturn(this.authenticatedContextMock); this.entryContextCallbackMock.executeWithContext(this.authenticatedContextMock, new LdapEntryIdentification( LdapUtils.newLdapName("cn=john doe,dc=jayway,dc=se"), LdapUtils.newLdapName("cn=john doe"))); @@ -1744,7 +1743,7 @@ public class LdapTemplateTests { @Test public void testAuthenticateWithTwoUsersFoundShouldThrowException() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); @@ -1766,7 +1765,7 @@ public class LdapTemplateTests { @Test public void testAuthenticateWhenNoUserWasFoundShouldFail() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); noSearchResults(searchControlsRecursive()); @@ -1782,12 +1781,12 @@ public class LdapTemplateTests { @SuppressWarnings("unchecked") public void testAuthenticateQueryPasswordMapperWhenNoUserWasFoundShouldThrowEmptyResult() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); - when(this.dirContextMock.search(any(Name.class), any(String.class), any(SearchControls.class))) - .thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(any(Name.class), any(String.class), any(SearchControls.class))) + .willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(false); + given(this.namingEnumerationMock.hasMore()).willReturn(false); try { this.tested.authenticate(this.query, "", this.authContextMapperMock); @@ -1802,12 +1801,12 @@ public class LdapTemplateTests { @SuppressWarnings("unchecked") public void testAuthenticateQueryPasswordWhenNoUserWasFoundShouldThrowEmptyResult() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); - when(this.dirContextMock.search(any(Name.class), any(String.class), any(SearchControls.class))) - .thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(any(Name.class), any(String.class), any(SearchControls.class))) + .willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(false); + given(this.namingEnumerationMock.hasMore()).willReturn(false); try { this.tested.authenticate(this.query, ""); @@ -1820,7 +1819,7 @@ public class LdapTemplateTests { @Test public void testAuthenticateWithFailedAuthenticationShouldFail() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); @@ -1828,8 +1827,8 @@ public class LdapTemplateTests { singleSearchResult(searchControlsRecursive(), searchResult); - when(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) - .thenThrow(new UncategorizedLdapException("Authentication failed")); + given(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) + .willThrow(new UncategorizedLdapException("Authentication failed")); boolean result = this.tested.authenticate(this.nameMock, "(ou=somevalue)", "password", this.entryContextCallbackMock); @@ -1841,7 +1840,7 @@ public class LdapTemplateTests { @Test public void testAuthenticateWithErrorInCallbackShouldFail() throws Exception { - when(this.contextSourceMock.getReadOnlyContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadOnlyContext()).willReturn(this.dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); @@ -1849,9 +1848,9 @@ public class LdapTemplateTests { singleSearchResult(searchControlsRecursive(), searchResult); - when(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) - .thenReturn(this.authenticatedContextMock); - doThrow(new UncategorizedLdapException("Authentication failed")).when(this.entryContextCallbackMock) + given(this.contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) + .willReturn(this.authenticatedContextMock); + willThrow(new UncategorizedLdapException("Authentication failed")).given(this.entryContextCallbackMock) .executeWithContext(this.authenticatedContextMock, new LdapEntryIdentification( LdapUtils.newLdapName("cn=john doe,dc=jayway,dc=se"), LdapUtils.newLdapName("cn=john doe"))); @@ -1865,10 +1864,10 @@ public class LdapTemplateTests { } private void noSearchResults(SearchControls controls) throws Exception { - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(false); + given(this.namingEnumerationMock.hasMore()).willReturn(false); } private void singleSearchResult(SearchControls controls, SearchResult searchResult) throws Exception { @@ -1876,16 +1875,16 @@ public class LdapTemplateTests { } private void setupSearchResults(SearchControls controls, SearchResult... searchResults) throws Exception { - when(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(this.nameMock), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willReturn(this.namingEnumerationMock); if (searchResults.length == 1) { - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResults[0]); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResults[0]); } else if (searchResults.length == 2) { - when(this.namingEnumerationMock.hasMore()).thenReturn(true, true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResults[0], searchResults[1]); + given(this.namingEnumerationMock.hasMore()).willReturn(true, true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResults[0], searchResults[1]); } else { throw new IllegalArgumentException("Cannot handle " + searchResults.length + " search results"); @@ -1893,11 +1892,11 @@ public class LdapTemplateTests { } private void singleSearchResultWithStringBase(SearchControls controls, SearchResult searchResult) throws Exception { - when(this.dirContextMock.search(eq(DEFAULT_BASE_STRING), eq("(ou=somevalue)"), - argThat(new SearchControlsMatcher(controls)))).thenReturn(this.namingEnumerationMock); + given(this.dirContextMock.search(eq(DEFAULT_BASE_STRING), eq("(ou=somevalue)"), + argThat(new SearchControlsMatcher(controls)))).willReturn(this.namingEnumerationMock); - when(this.namingEnumerationMock.hasMore()).thenReturn(true, false); - when(this.namingEnumerationMock.next()).thenReturn(searchResult); + given(this.namingEnumerationMock.hasMore()).willReturn(true, false); + given(this.namingEnumerationMock.next()).willReturn(searchResult); } private SearchControls searchControlsRecursive() { diff --git a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java index b6bcb34b..192b01a4 100644 --- a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java +++ b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java @@ -26,7 +26,6 @@ import org.junit.Test; import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; /** * @author Mattias Hellborg Arthursson @@ -283,8 +282,8 @@ public class NameAwareAttributeTests { // then final NameAwareAttribute expectedAttribute = new NameAwareAttribute("test attribute"); expectedAttribute.add(b); - assertTrue(attribute.equals(expectedAttribute)); - assertTrue(attribute.hashCode() == expectedAttribute.hashCode()); + assertThat(attribute).isEqualTo(expectedAttribute); + assertThat(attribute.hashCode()).isEqualTo(expectedAttribute.hashCode()); } } diff --git a/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java b/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java index 8ade9b00..c9d2c497 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java @@ -27,9 +27,9 @@ import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; /** * Unit tests for {@link BaseLdapPathBeanPostProcessor}. @@ -122,8 +122,8 @@ public class BaseLdapPathBeanPostProcessorTests { @Test public void testGetAbstractContextSourceFromApplicationContext() throws Exception { - when(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)) - .thenReturn(new String[] { "contextSource" }); + given(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)) + .willReturn(new String[] { "contextSource" }); final LdapContextSource expectedContextSource = new LdapContextSource(); HashMap expectedBeans = new HashMap() { @@ -131,7 +131,7 @@ public class BaseLdapPathBeanPostProcessorTests { put("dummy", expectedContextSource); } }; - when(this.applicationContextMock.getBeansOfType(BaseLdapPathSource.class)).thenReturn(expectedBeans); + given(this.applicationContextMock.getBeansOfType(BaseLdapPathSource.class)).willReturn(expectedBeans); BaseLdapPathSource result = this.tested.getBaseLdapPathSourceFromApplicationContext(); @@ -140,14 +140,14 @@ public class BaseLdapPathBeanPostProcessorTests { @Test(expected = NoSuchBeanDefinitionException.class) public void testGetAbstractContextSourceFromApplicationContextNoContextSource() throws Exception { - when(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).thenReturn(new String[0]); + given(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).willReturn(new String[0]); this.tested.getBaseLdapPathSourceFromApplicationContext(); } @Test(expected = NoSuchBeanDefinitionException.class) public void testGetAbstractContextSourceFromApplicationContextTwoContextSources() throws Exception { - when(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).thenReturn(new String[2]); + given(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).willReturn(new String[2]); this.tested.getBaseLdapPathSourceFromApplicationContext(); } @@ -157,7 +157,7 @@ public class BaseLdapPathBeanPostProcessorTests { LdapContextSource expectedContextSource = new LdapContextSource(); this.tested.setBaseLdapPathSourceName("myContextSource"); - when(this.applicationContextMock.getBean("myContextSource")).thenReturn(expectedContextSource); + given(this.applicationContextMock.getBean("myContextSource")).willReturn(expectedContextSource); this.tested.getBaseLdapPathSourceFromApplicationContext(); } diff --git a/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java index df2f3a7d..73f6ff1d 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java @@ -27,8 +27,8 @@ import org.junit.Test; import org.springframework.ldap.core.ObjectRetrievalException; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; /** * @Ulrik Sandberg @@ -40,20 +40,6 @@ public class ContextMapperCallbackHandlerWithControlsTests { private ContextMapperCallbackHandlerWithControls tested; - private static class MyBindingThatHasControls extends Binding implements HasControls { - - private static final long serialVersionUID = 1L; - - MyBindingThatHasControls(String name, Object obj) { - super(name, obj); - } - - public Control[] getControls() throws NamingException { - return null; - } - - } - @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { @@ -72,7 +58,7 @@ public class ContextMapperCallbackHandlerWithControlsTests { Object expectedResult = "result"; Binding expectedBinding = new Binding("some name", expectedObject); - when(this.mapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + given(this.mapperMock.mapFromContext(expectedObject)).willReturn(expectedResult); Object actualResult = this.tested.getObjectFromNameClassPair(expectedBinding); @@ -85,7 +71,7 @@ public class ContextMapperCallbackHandlerWithControlsTests { Object expectedResult = "result"; MyBindingThatHasControls expectedBinding = new MyBindingThatHasControls("some name", expectedObject); - when(this.mapperMock.mapFromContextWithControls(expectedObject, expectedBinding)).thenReturn(expectedResult); + given(this.mapperMock.mapFromContextWithControls(expectedObject, expectedBinding)).willReturn(expectedResult); Object actualResult = this.tested.getObjectFromNameClassPair(expectedBinding); @@ -99,4 +85,18 @@ public class ContextMapperCallbackHandlerWithControlsTests { this.tested.getObjectFromNameClassPair(expectedBinding); } + private static class MyBindingThatHasControls extends Binding implements HasControls { + + private static final long serialVersionUID = 1L; + + MyBindingThatHasControls(String name, Object obj) { + super(name, obj); + } + + public Control[] getControls() throws NamingException { + return null; + } + + } + } diff --git a/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java b/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java index 64bcda3b..a0ea20bf 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java @@ -33,9 +33,9 @@ import org.springframework.ldap.core.NameAwareAttributes; import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; public class DefaultDirObjectFactoryTests { @@ -121,7 +121,7 @@ public class DefaultDirObjectFactoryTests { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); - when(this.contextMock2.getNameInNamespace()).thenReturn("dc=jayway, dc=se"); + given(this.contextMock2.getNameInNamespace()).willReturn("dc=jayway, dc=se"); DirContextAdapter adapter = (DirContextAdapter) this.tested.getObjectInstance(this.contextMock, LdapUtils.newLdapName("ou=some unit"), this.contextMock2, new Hashtable(), expectedAttributes); diff --git a/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java b/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java index caf86077..a8928f0a 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java @@ -45,4 +45,4 @@ public class DefaultTlsDirContextAuthenticationStrategyTests { verify(this.context).lookup(""); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java index 06d88306..156a8303 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java @@ -31,9 +31,9 @@ import org.springframework.ldap.core.LdapOperations; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verifyNoMoreInteractions; /** * @author Mattias Hellborg Arthursson @@ -52,7 +52,7 @@ public class SingleContextSourceTests { @Test public void testDoWithSingleContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); verifyNoMoreInteractions(this.contextSourceMock); SingleContextSource.doWithSingleContext(this.contextSourceMock, new LdapOperationsCallback() { diff --git a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java index bcc31106..63c58f1e 100644 --- a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java +++ b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java @@ -29,12 +29,12 @@ import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.core.SpringVersion; +import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * @author Mattias Hellborg Arthursson @@ -68,8 +68,9 @@ public class DefaultObjectDirectoryMapperTests { DefaultObjectDirectoryMapper.EntityData entityData = this.tested.getMetaDataMap().get(UnitTestPerson.class); assertThat(entityData).isNotNull(); - assertThat(entityData.ocFilter).isEqualTo(query().where("objectclass").is("inetOrgPerson").and("objectclass") - .is("organizationalPerson").and("objectclass").is("person").and("objectclass").is("top").filter()); + assertThat(entityData.ocFilter).isEqualTo(LdapQueryBuilder.query().where("objectclass").is("inetOrgPerson") + .and("objectclass").is("organizationalPerson").and("objectclass").is("person").and("objectclass") + .is("top").filter()); assertThat(entityData.metaData).hasSize(8); diff --git a/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedAndUnindexedDnAttributes.java b/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedAndUnindexedDnAttributes.java index 7c9eb6fc..754fa2f2 100644 --- a/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedAndUnindexedDnAttributes.java +++ b/core/src/test/java/org/springframework/ldap/odm/core/impl/UnitTestPersonWithIndexedAndUnindexedDnAttributes.java @@ -35,7 +35,7 @@ public class UnitTestPersonWithIndexedAndUnindexedDnAttributes { private String fullName; // This makes the entry invalid - @DnAttribute(value = "ou") + @DnAttribute("ou") private String company; @DnAttribute(value = "c", index = 0) diff --git a/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java b/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java index 169d4bc2..8a682355 100644 --- a/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java @@ -25,10 +25,10 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.times; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; /** * @author Eric Dalquist @@ -421,7 +421,7 @@ public class DelegatingContextTests extends AbstractPoolTestCase { @Test public void testPoolExceptionOnClose() throws Exception { - doThrow(new Exception("Fake Pool returnObject Exception")).when(keyedObjectPoolMock) + willThrow(new Exception("Fake Pool returnObject Exception")).given(keyedObjectPoolMock) .returnObject(DirContextType.READ_ONLY, contextMock); final DelegatingContext delegatingContext = new DelegatingContext(keyedObjectPoolMock, contextMock, diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java b/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java index a351b74a..62f02225 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java @@ -33,10 +33,10 @@ import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; /** * @author Eric Dalquist @@ -101,7 +101,7 @@ public class DirContextPoolableObjectFactoryTests extends AbstractPoolTestCase { DirContext readOnlyContextMock = mock(DirContext.class); - when(contextSourceMock.getReadOnlyContext()).thenReturn(readOnlyContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(readOnlyContextMock); objectFactory.setContextSource(contextSourceMock); final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY); @@ -115,7 +115,7 @@ public class DirContextPoolableObjectFactoryTests extends AbstractPoolTestCase { DirContext readWriteContextMock = mock(DirContext.class); - when(contextSourceMock.getReadWriteContext()).thenReturn(readWriteContextMock); + given(contextSourceMock.getReadWriteContext()).willReturn(readWriteContextMock); objectFactory.setContextSource(contextSourceMock); final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE); @@ -173,7 +173,7 @@ public class DirContextPoolableObjectFactoryTests extends AbstractPoolTestCase { @Test public void testValidateObject() throws Exception { - when(dirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)).thenReturn(true); + given(dirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)).willReturn(true); final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory(); objectFactory.setDirContextValidator(dirContextValidatorMock); @@ -184,8 +184,8 @@ public class DirContextPoolableObjectFactoryTests extends AbstractPoolTestCase { // Check exception in validator DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class); - when(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)) - .thenThrow(new RuntimeException("Failed to validate")); + given(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)) + .willThrow(new RuntimeException("Failed to validate")); objectFactory.setDirContextValidator(secondDirContextValidatorMock); final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock); @@ -221,7 +221,7 @@ public class DirContextPoolableObjectFactoryTests extends AbstractPoolTestCase { DirContext throwingDirContextMock = Mockito.mock(DirContext.class); - doThrow(new RuntimeException("Failed to close")).when(throwingDirContextMock).close(); + willThrow(new RuntimeException("Failed to close")).given(throwingDirContextMock).close(); objectFactory.destroyObject(DirContextType.READ_ONLY, throwingDirContextMock); verify(dirContextMock).close(); diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java index 771544bb..7f82c0a7 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java @@ -24,7 +24,7 @@ import org.springframework.ldap.pool.AbstractPoolTestCase; import org.springframework.ldap.pool.MutableDelegatingLdapContext; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; /** * Unit tests for the MutablePoolingContextSource class. @@ -36,7 +36,7 @@ public class MutablePoolingContextSourceTests extends AbstractPoolTestCase { @Test public void testGetReadOnlyLdapContext() throws Exception { - when(contextSourceMock.getReadOnlyContext()).thenReturn(ldapContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(ldapContextMock); final MutablePoolingContextSource poolingContextSource = new MutablePoolingContextSource(); poolingContextSource.setContextSource(contextSourceMock); diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java index c73eff4b..4babbe58 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java @@ -29,8 +29,8 @@ import org.springframework.ldap.pool.validation.DirContextValidator; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; /** * @author Eric Dalquist @@ -122,7 +122,7 @@ public class PoolingContextSourceTests extends AbstractPoolTestCase { public void testGetReadOnlyContextPool() throws Exception { DirContext secondDirContextMock = mock(DirContext.class); - when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock, secondDirContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(dirContextMock, secondDirContextMock); final PoolingContextSource poolingContextSource = new PoolingContextSource(); poolingContextSource.setContextSource(contextSourceMock); @@ -173,7 +173,7 @@ public class PoolingContextSourceTests extends AbstractPoolTestCase { public void testGetReadWriteContextPool() throws Exception { DirContext secondDirContextMock = mock(DirContext.class); - when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock, secondDirContextMock); + given(contextSourceMock.getReadWriteContext()).willReturn(dirContextMock, secondDirContextMock); final PoolingContextSource poolingContextSource = new PoolingContextSource(); poolingContextSource.setContextSource(contextSourceMock); @@ -222,7 +222,7 @@ public class PoolingContextSourceTests extends AbstractPoolTestCase { @Test public void testGetContextException() throws Exception { - when(contextSourceMock.getReadWriteContext()).thenThrow(new RuntimeException("Problem getting context")); + given(contextSourceMock.getReadWriteContext()).willThrow(new RuntimeException("Problem getting context")); final PoolingContextSource poolingContextSource = new PoolingContextSource(); poolingContextSource.setContextSource(contextSourceMock); @@ -240,7 +240,7 @@ public class PoolingContextSourceTests extends AbstractPoolTestCase { public void testGetReadOnlyLdapContext() throws Exception { LdapContext secondLdapContextMock = mock(LdapContext.class); - when(contextSourceMock.getReadOnlyContext()).thenReturn(ldapContextMock, secondLdapContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(ldapContextMock, secondLdapContextMock); final PoolingContextSource poolingContextSource = new PoolingContextSource(); poolingContextSource.setContextSource(contextSourceMock); diff --git a/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java b/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java index ad3bc9bb..452b6ee4 100644 --- a/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java @@ -28,8 +28,8 @@ import org.springframework.ldap.pool.DirContextType; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; /** * @author Eric Dalquist @@ -132,8 +132,8 @@ public class DefaultDirContextValidatorTests { final String filter = dirContextValidator.getFilter(); final SearchControls searchControls = dirContextValidator.getSearchControls(); - when(this.namingEnumerationMock.hasMore()).thenReturn(true); - when(this.dirContextMock.search(baseName, filter, searchControls)).thenReturn(this.namingEnumerationMock); + given(this.namingEnumerationMock.hasMore()).willReturn(true); + given(this.dirContextMock.search(baseName, filter, searchControls)).willReturn(this.namingEnumerationMock); final boolean valid = dirContextValidator.validateDirContext(DirContextType.READ_ONLY, this.dirContextMock); assertThat(valid).isTrue(); @@ -147,8 +147,8 @@ public class DefaultDirContextValidatorTests { final String filter = dirContextValidator.getFilter(); final SearchControls searchControls = dirContextValidator.getSearchControls(); - when(this.namingEnumerationMock.hasMore()).thenReturn(false); - when(this.dirContextMock.search(baseName, filter, searchControls)).thenReturn(this.namingEnumerationMock); + given(this.namingEnumerationMock.hasMore()).willReturn(false); + given(this.dirContextMock.search(baseName, filter, searchControls)).willReturn(this.namingEnumerationMock); final boolean valid = dirContextValidator.validateDirContext(DirContextType.READ_ONLY, this.dirContextMock); @@ -163,8 +163,8 @@ public class DefaultDirContextValidatorTests { final String filter = dirContextValidator.getFilter(); final SearchControls searchControls = dirContextValidator.getSearchControls(); - when(this.dirContextMock.search(baseName, filter, searchControls)) - .thenThrow(new NamingException("Failed to search")); + given(this.dirContextMock.search(baseName, filter, searchControls)) + .willThrow(new NamingException("Failed to search")); final boolean valid = dirContextValidator.validateDirContext(DirContextType.READ_ONLY, this.dirContextMock); diff --git a/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java b/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java index 2c8b4e7b..b63d7c9b 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java @@ -25,10 +25,10 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.times; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; /** * @author Eric Dalquist @@ -421,7 +421,7 @@ public class DelegatingContextTests extends AbstractPoolTestCase { @Test public void testPoolExceptionOnClose() throws Exception { - doThrow(new Exception("Fake Pool returnObject Exception")).when(keyedObjectPoolMock) + willThrow(new Exception("Fake Pool returnObject Exception")).given(keyedObjectPoolMock) .returnObject(DirContextType.READ_ONLY, contextMock); final DelegatingContext delegatingContext = new DelegatingContext(keyedObjectPoolMock, contextMock, diff --git a/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java b/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java index 1a4e1f64..e029fdda 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java @@ -34,10 +34,10 @@ import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; /** * @author Eric Dalquist @@ -103,7 +103,7 @@ public class DirContextPooledObjectFactoryTests extends AbstractPoolTestCase { DirContext readOnlyContextMock = mock(DirContext.class); - when(contextSourceMock.getReadOnlyContext()).thenReturn(readOnlyContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(readOnlyContextMock); objectFactory.setContextSource(contextSourceMock); final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY); @@ -117,7 +117,7 @@ public class DirContextPooledObjectFactoryTests extends AbstractPoolTestCase { DirContext readWriteContextMock = mock(DirContext.class); - when(contextSourceMock.getReadWriteContext()).thenReturn(readWriteContextMock); + given(contextSourceMock.getReadWriteContext()).willReturn(readWriteContextMock); objectFactory.setContextSource(contextSourceMock); final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE); @@ -179,7 +179,7 @@ public class DirContextPooledObjectFactoryTests extends AbstractPoolTestCase { @Test public void testValidateObject() throws Exception { - when(dirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)).thenReturn(true); + given(dirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)).willReturn(true); final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory(); objectFactory.setDirContextValidator(dirContextValidatorMock); @@ -191,8 +191,8 @@ public class DirContextPooledObjectFactoryTests extends AbstractPoolTestCase { // Check exception in validator DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class); - when(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)) - .thenThrow(new RuntimeException("Failed to validate")); + given(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)) + .willThrow(new RuntimeException("Failed to validate")); objectFactory.setDirContextValidator(secondDirContextValidatorMock); final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject); @@ -230,7 +230,7 @@ public class DirContextPooledObjectFactoryTests extends AbstractPoolTestCase { DirContext throwingDirContextMock = mock(DirContext.class); - doThrow(new RuntimeException("Failed to close")).when(throwingDirContextMock).close(); + willThrow(new RuntimeException("Failed to close")).given(throwingDirContextMock).close(); pooledObject = new DefaultPooledObject(throwingDirContextMock); objectFactory.destroyObject(DirContextType.READ_ONLY, pooledObject); diff --git a/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java index c0b85d40..2db11539 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java @@ -24,7 +24,7 @@ import org.springframework.ldap.pool2.AbstractPoolTestCase; import org.springframework.ldap.pool2.MutableDelegatingLdapContext; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; /** * Unit tests for the MutablePoolingContextSource class. @@ -37,7 +37,7 @@ public class MutablePooledContextSourceTests extends AbstractPoolTestCase { @Test public void testGetReadOnlyLdapContext() throws Exception { - when(contextSourceMock.getReadOnlyContext()).thenReturn(ldapContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(ldapContextMock); final MutablePooledContextSource poolingContextSource = new MutablePooledContextSource(null); poolingContextSource.setContextSource(contextSourceMock); diff --git a/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java index 9bdd6193..185ddc7d 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java @@ -28,8 +28,8 @@ import org.springframework.ldap.pool2.validation.DirContextValidator; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; /** * @author Eric Dalquist @@ -95,7 +95,7 @@ public class PooledContextSourceTests extends AbstractPoolTestCase { public void testGetReadOnlyContextPool() throws Exception { DirContext secondDirContextMock = mock(DirContext.class); - when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock, secondDirContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(dirContextMock, secondDirContextMock); final PooledContextSource PooledContextSource = new PooledContextSource(null); PooledContextSource.setContextSource(contextSourceMock); @@ -146,7 +146,7 @@ public class PooledContextSourceTests extends AbstractPoolTestCase { public void testGetReadWriteContextPool() throws Exception { DirContext secondDirContextMock = mock(DirContext.class); - when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock, secondDirContextMock); + given(contextSourceMock.getReadWriteContext()).willReturn(dirContextMock, secondDirContextMock); final PooledContextSource PooledContextSource = new PooledContextSource(null); PooledContextSource.setContextSource(contextSourceMock); @@ -195,7 +195,7 @@ public class PooledContextSourceTests extends AbstractPoolTestCase { @Test public void testGetContextException() throws Exception { - when(contextSourceMock.getReadWriteContext()).thenThrow(new RuntimeException("Problem getting context")); + given(contextSourceMock.getReadWriteContext()).willThrow(new RuntimeException("Problem getting context")); final PooledContextSource PooledContextSource = new PooledContextSource(null); PooledContextSource.setContextSource(contextSourceMock); @@ -213,7 +213,7 @@ public class PooledContextSourceTests extends AbstractPoolTestCase { public void testGetReadOnlyLdapContext() throws Exception { LdapContext secondLdapContextMock = mock(LdapContext.class); - when(contextSourceMock.getReadOnlyContext()).thenReturn(ldapContextMock, secondLdapContextMock); + given(contextSourceMock.getReadOnlyContext()).willReturn(ldapContextMock, secondLdapContextMock); final PooledContextSource pooledContextSource = new PooledContextSource(null); pooledContextSource.setContextSource(contextSourceMock); diff --git a/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java b/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java index cd68de44..f1909914 100644 --- a/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java +++ b/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java @@ -21,7 +21,6 @@ import org.junit.Test; import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * @author Mattias Hellborg Arthursson @@ -30,7 +29,7 @@ public class LdapQueryBuilderTests { @Test public void buildSimpleWithDefaults() { - LdapQuery result = query().where("cn").is("John Doe"); + LdapQuery result = LdapQueryBuilder.query().where("cn").is("John Doe"); assertThat(result.base()).isEqualTo(LdapUtils.emptyLdapName()); assertThat(result.searchScope()).isNull(); @@ -41,71 +40,71 @@ public class LdapQueryBuilderTests { @Test public void buildGreaterThanOrEquals() { - LdapQuery result = query().where("cn").gte("John Doe"); + LdapQuery result = LdapQueryBuilder.query().where("cn").gte("John Doe"); assertThat(result.filter().encode()).isEqualTo("(cn>=John Doe)"); } @Test public void buildLessThanOrEquals() { - LdapQuery result = query().where("cn").lte("John Doe"); + LdapQuery result = LdapQueryBuilder.query().where("cn").lte("John Doe"); assertThat(result.filter().encode()).isEqualTo("(cn<=John Doe)"); } @Test public void buildLike() { - LdapQuery result = query().where("cn").like("J*hn Doe"); + LdapQuery result = LdapQueryBuilder.query().where("cn").like("J*hn Doe"); assertThat(result.filter().encode()).isEqualTo("(cn=J*hn Doe)"); } @Test public void buildWhitespaceWildcards() { - LdapQuery result = query().where("cn").whitespaceWildcardsLike("John Doe"); + LdapQuery result = LdapQueryBuilder.query().where("cn").whitespaceWildcardsLike("John Doe"); assertThat(result.filter().encode()).isEqualTo("(cn=*John*Doe*)"); } @Test public void buildPresent() { - LdapQuery result = query().where("cn").isPresent(); + LdapQuery result = LdapQueryBuilder.query().where("cn").isPresent(); assertThat(result.filter().encode()).isEqualTo("(cn=*)"); } @Test public void buildHardcodedFilter() { - LdapQuery result = query().filter("(cn=Person*)"); + LdapQuery result = LdapQueryBuilder.query().filter("(cn=Person*)"); assertThat(result.filter().encode()).isEqualTo("(cn=Person*)"); } @Test(expected = IllegalStateException.class) public void verifyThatHardcodedFilterFailsIfFilterAlreadySpecified() { - LdapQueryBuilder query = query(); + LdapQueryBuilder query = LdapQueryBuilder.query(); query.where("sn").is("Doe"); query.filter("(cn=Person*)"); } @Test(expected = IllegalStateException.class) public void verifyThatFilterFormatFailsIfFilterAlreadySpecified() { - LdapQueryBuilder query = query(); + LdapQueryBuilder query = LdapQueryBuilder.query(); query.where("sn").is("Doe"); query.filter("(|(cn={0})(cn={1}))", "Person*", "Parson*"); } @Test public void buildFilterFormat() { - LdapQuery result = query().filter("(|(cn={0})(cn={1}))", "Person*", "Parson*"); + LdapQuery result = LdapQueryBuilder.query().filter("(|(cn={0})(cn={1}))", "Person*", "Parson*"); assertThat(result.filter().encode()).isEqualTo("(|(cn=Person\\2a)(cn=Parson\\2a))"); } @Test public void testBuildSimpleAnd() { - LdapQuery query = query().base("dc=261consulting, dc=com").searchScope(SearchScope.ONELEVEL).timeLimit(200) - .countLimit(221).where("objectclass").is("person").and("cn").is("John Doe"); + LdapQuery query = LdapQueryBuilder.query().base("dc=261consulting, dc=com").searchScope(SearchScope.ONELEVEL) + .timeLimit(200).countLimit(221).where("objectclass").is("person").and("cn").is("John Doe"); assertThat(query.base()).isEqualTo(LdapUtils.newLdapName("dc=261consulting, dc=com")); assertThat(query.searchScope()).isEqualTo(SearchScope.ONELEVEL); @@ -116,54 +115,54 @@ public class LdapQueryBuilderTests { @Test public void buildSimpleOr() { - LdapQuery result = query().where("objectclass").is("person").or("cn").is("John Doe"); + LdapQuery result = LdapQueryBuilder.query().where("objectclass").is("person").or("cn").is("John Doe"); assertThat(result.filter().encode()).isEqualTo("(|(objectclass=person)(cn=John Doe))"); } @Test public void buildAndOrPrecedence() { - LdapQuery result = query().where("objectclass").is("person").and("cn").is("John Doe") - .or(query().where("sn").is("Doe")); + LdapQuery result = LdapQueryBuilder.query().where("objectclass").is("person").and("cn").is("John Doe") + .or(LdapQueryBuilder.query().where("sn").is("Doe")); assertThat(result.filter().encode()).isEqualTo("(|(&(objectclass=person)(cn=John Doe))(sn=Doe))"); } @Test public void buildOrNegatedSubQueries() { - LdapQuery result = query().where("objectclass").not().is("person").or("sn").not().is("Doe"); + LdapQuery result = LdapQueryBuilder.query().where("objectclass").not().is("person").or("sn").not().is("Doe"); assertThat(result.filter().encode()).isEqualTo("(|(!(objectclass=person))(!(sn=Doe)))"); } @Test public void buildNestedAnd() { - LdapQuery result = query().where("objectclass").is("person") - .and(query().where("sn").is("Doe").or("sn").like("Die")); + LdapQuery result = LdapQueryBuilder.query().where("objectclass").is("person") + .and(LdapQueryBuilder.query().where("sn").is("Doe").or("sn").like("Die")); assertThat(result.filter().encode()).isEqualTo("(&(objectclass=person)(|(sn=Doe)(sn=Die)))"); } @Test(expected = IllegalStateException.class) public void verifyEmptyFilterThrowsIllegalState() { - query().filter(); + LdapQueryBuilder.query().filter(); } @Test(expected = IllegalStateException.class) public void verifyThatNewAttemptToStartSpecifyingFilterThrowsIllegalState() { - LdapQueryBuilder query = query(); + LdapQueryBuilder query = LdapQueryBuilder.query(); query.where("sn").is("Doe"); query.where("cn").is("John Doe"); } @Test(expected = IllegalStateException.class) public void verifyThatAttemptToStartSpecifyingBasePropertiesThrowsIllegalStateWhenFilterStarted() { - LdapQueryBuilder query = query(); + LdapQueryBuilder query = LdapQueryBuilder.query(); query.where("sn").is("Doe"); query.base("dc=261consulting,dc=com"); } @Test(expected = IllegalStateException.class) public void verifyThatOperatorChangeIsIllegal() { - query().where("cn").is("John Doe").and("sn").is("Doe").or("objectclass").is("person"); + LdapQueryBuilder.query().where("cn").is("John Doe").and("sn").is("Doe").or("objectclass").is("person"); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java index 777a69b4..99b2e5bc 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java @@ -27,7 +27,6 @@ import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; public class BindOperationRecorderTests { @@ -56,7 +55,7 @@ public class BindOperationRecorderTests { assertThat(rollbackOperation.getDn()).isSameAs(expectedDn); assertThat(rollbackOperation.getLdapOperations()).isSameAs(this.ldapOperationsMock); assertThat(rollbackOperation.getOriginalObject()).isSameAs(expectedObject); - assertSame(expectedAttributes, rollbackOperation.getOriginalAttributes()); + assertThat(expectedAttributes).isSameAs(rollbackOperation.getOriginalAttributes()); } @Test diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java index 16bfd6c6..dcb396cc 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java @@ -25,8 +25,7 @@ import org.junit.Test; import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.support.TransactionSynchronizationManager; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -56,13 +55,13 @@ public class LdapTransactionUtilsTests { @Test public void testIsSupportedWriteTransactionOperation() { - assertTrue(LdapTransactionUtils.isSupportedWriteTransactionOperation("bind")); - assertTrue(LdapTransactionUtils.isSupportedWriteTransactionOperation("rebind")); - assertTrue(LdapTransactionUtils.isSupportedWriteTransactionOperation("unbind")); - assertTrue(LdapTransactionUtils.isSupportedWriteTransactionOperation("modifyAttributes")); - assertTrue(LdapTransactionUtils.isSupportedWriteTransactionOperation("rename")); - assertFalse(LdapTransactionUtils.isSupportedWriteTransactionOperation("lookup")); - assertFalse(LdapTransactionUtils.isSupportedWriteTransactionOperation("search")); + assertThat(LdapTransactionUtils.isSupportedWriteTransactionOperation("bind")).isTrue(); + assertThat(LdapTransactionUtils.isSupportedWriteTransactionOperation("rebind")).isTrue(); + assertThat(LdapTransactionUtils.isSupportedWriteTransactionOperation("unbind")).isTrue(); + assertThat(LdapTransactionUtils.isSupportedWriteTransactionOperation("modifyAttributes")).isTrue(); + assertThat(LdapTransactionUtils.isSupportedWriteTransactionOperation("rename")).isTrue(); + assertThat(LdapTransactionUtils.isSupportedWriteTransactionOperation("lookup")).isFalse(); + assertThat(LdapTransactionUtils.isSupportedWriteTransactionOperation("search")).isFalse(); } public void dummyMethod() { diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java index 3649328b..df376e36 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java @@ -34,8 +34,8 @@ import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; public class ModifyAttributesOperationRecorderTests { @@ -78,11 +78,11 @@ public class ModifyAttributesOperationRecorderTests { LdapName expectedName = LdapUtils.newLdapName("cn=john doe"); - when(this.attributesMapperMock.hasMore()).thenReturn(true, false); - when(this.attributesMapperMock.getAttributesForLookup()).thenReturn(new String[] { "attribute1" }); - when(this.ldapOperationsMock.lookup(expectedName, new String[] { "attribute1" }, this.attributesMapperMock)) - .thenReturn(expectedAttributes); - when(this.attributesMapperMock.getCollectedAttributes()).thenReturn(expectedAttributes); + given(this.attributesMapperMock.hasMore()).willReturn(true, false); + given(this.attributesMapperMock.getAttributesForLookup()).willReturn(new String[] { "attribute1" }); + given(this.ldapOperationsMock.lookup(expectedName, new String[] { "attribute1" }, this.attributesMapperMock)) + .willReturn(expectedAttributes); + given(this.attributesMapperMock.getCollectedAttributes()).willReturn(expectedAttributes); // Perform test CompensatingTransactionOperationExecutor operation = this.tested diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java index b9c0e115..0f9ccaeb 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java @@ -27,8 +27,8 @@ import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; public class RebindOperationRecorderTests { @@ -50,7 +50,7 @@ public class RebindOperationRecorderTests { RebindOperationRecorder tested = new RebindOperationRecorder(this.ldapOperationsMock, this.renamingStrategyMock); - when(this.renamingStrategyMock.getTemporaryName(expectedDn)).thenReturn(expectedTempDn); + given(this.renamingStrategyMock.getTemporaryName(expectedDn)).willReturn(expectedTempDn); Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java index 61c73f0e..d2118053 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java @@ -35,7 +35,6 @@ public class RenameOperationExecutorTests { @Before public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); - ; } @Test diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java index 59517ab4..cb9414b3 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java @@ -32,7 +32,6 @@ public class RenameOperationRecorderTests { @Before public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); - ; } @Test diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java index 3a26108d..2dc956ca 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java @@ -34,7 +34,6 @@ public class UnbindOperationExecutorTests { @Before public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); - ; } @Test diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java index baa79e52..ef42f7a1 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java @@ -26,8 +26,8 @@ import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; public class UnbindOperationRecorderTests { @@ -38,7 +38,6 @@ public class UnbindOperationRecorderTests { @Before public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); - ; this.renamingStrategyMock = mock(TempEntryRenamingStrategy.class); } @@ -50,7 +49,7 @@ public class UnbindOperationRecorderTests { UnbindOperationRecorder tested = new UnbindOperationRecorder(this.ldapOperationsMock, this.renamingStrategyMock); - when(this.renamingStrategyMock.getTemporaryName(expectedDn)).thenReturn(expectedTempName); + given(this.renamingStrategyMock.getTemporaryName(expectedDn)).willReturn(expectedTempName); // Perform test CompensatingTransactionOperationExecutor operation = tested.recordOperation(new Object[] { expectedDn }); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java index ce2df7f0..28bf805d 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java @@ -41,9 +41,9 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; public class ContextSourceTransactionManagerTests { @@ -96,7 +96,7 @@ public class ContextSourceTransactionManagerTests { @Test public void testDoBegin() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.contextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.contextMock); CompensatingTransactionObject expectedTransactionObject = new CompensatingTransactionObject(null); this.tested.doBegin(expectedTransactionObject, this.transactionDefinitionMock); @@ -148,13 +148,13 @@ public class ContextSourceTransactionManagerTests { Connection connectionMock = mock(Connection.class); DataSource dataSourceMock = mock(DataSource.class); - when(dataSourceMock.getConnection()).thenReturn(connectionMock); - when(connectionMock.getAutoCommit()).thenReturn(false); + given(dataSourceMock.getConnection()).willReturn(connectionMock); + given(connectionMock.getAutoCommit()).willReturn(false); ContextSource unconnectableContextSourceMock = mock(ContextSource.class); UncategorizedLdapException connectException = new UncategorizedLdapException("dummy"); - when(unconnectableContextSourceMock.getReadWriteContext()).thenThrow(connectException); + given(unconnectableContextSourceMock.getReadWriteContext()).willThrow(connectException); try { // Create an outer transaction @@ -178,16 +178,16 @@ public class ContextSourceTransactionManagerTests { txMgrInner.commit(txInner); } - catch (Exception e) { + catch (Exception ex) { txMgrInner.rollback(txInner); - throw e; + throw ex; } txMgrOuter.commit(txOuter); } - catch (Exception e) { + catch (Exception ex) { txMgrOuter.rollback(txOuter); - throw e; + throw ex; } fail("Exception should be thrown"); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java index 1d0e944b..d0033a7b 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java @@ -26,8 +26,8 @@ import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.DirContextProxy; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; /** * Tests for {@link TransactionAwareContextSourceProxy}. @@ -55,7 +55,7 @@ public class TransactionAwareContextSourceProxyTests { @Test public void testGetReadWriteContext_LdapContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.ldapContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.ldapContextMock); DirContext result = this.tested.getReadWriteContext(); @@ -66,7 +66,7 @@ public class TransactionAwareContextSourceProxyTests { @Test public void testGetReadWriteContext_DirContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.dirContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.dirContextMock); DirContext result = this.tested.getReadWriteContext(); @@ -78,7 +78,7 @@ public class TransactionAwareContextSourceProxyTests { @Test public void testGetReadOnlyContext_LdapContext() { - when(this.contextSourceMock.getReadWriteContext()).thenReturn(this.ldapContextMock); + given(this.contextSourceMock.getReadWriteContext()).willReturn(this.ldapContextMock); DirContext result = this.tested.getReadOnlyContext(); diff --git a/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java b/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java index 0432d5d7..65cb4ce9 100644 --- a/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java +++ b/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java @@ -27,10 +27,10 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera import org.springframework.transaction.compensating.CompensatingTransactionOperationRecorder; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; public class DefaultCompensatingTransactionOperationManagerTests { @@ -53,9 +53,9 @@ public class DefaultCompensatingTransactionOperationManagerTests { Object[] expectedArgs = new Object[0]; Object expectedResource = new Object(); - when(this.operationFactoryMock.createRecordingOperation(expectedResource, "some method")) - .thenReturn(this.operationRecorderMock); - when(this.operationRecorderMock.recordOperation(expectedArgs)).thenReturn(this.operationExecutorMock); + given(this.operationFactoryMock.createRecordingOperation(expectedResource, "some method")) + .willReturn(this.operationRecorderMock); + given(this.operationRecorderMock.recordOperation(expectedArgs)).willReturn(this.operationExecutorMock); DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager( this.operationFactoryMock); @@ -83,7 +83,7 @@ public class DefaultCompensatingTransactionOperationManagerTests { this.operationFactoryMock); tested.getOperationExecutors().push(this.operationExecutorMock); - doThrow(new RuntimeException()).when(this.operationExecutorMock).rollback(); + willThrow(new RuntimeException()).given(this.operationExecutorMock).rollback(); tested.rollback(); } @@ -104,7 +104,7 @@ public class DefaultCompensatingTransactionOperationManagerTests { this.operationFactoryMock); tested.getOperationExecutors().push(this.operationExecutorMock); - doThrow(new RuntimeException()).when(this.operationExecutorMock).commit(); + willThrow(new RuntimeException()).given(this.operationExecutorMock).commit(); tested.commit(); }