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