Address JavaFormat Violations in Core Tests

Issue gh-743
This commit is contained in:
Josh Cummings
2023-05-09 15:18:04 -06:00
parent 127e738201
commit 6e3b6ee688
45 changed files with 518 additions and 525 deletions

View File

@@ -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 {

View File

@@ -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();

View File

@@ -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"));
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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 <code>list</code> 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<Object> results = this.tested.listBindings(NAME).toStream(this.contextMapperMock)) {
List<Object> 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<Object> results = this.tested.listBindings(this.nameMock).toStream(this.contextMapperMock)) {
List<Object> list = results.collect(Collectors.toList());

View File

@@ -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<Attributes> 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<Attributes> 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<javax.naming.NamingEnumeration<SearchResult>> whenSearching(Name name) throws Exception {
return when(this.dirContextMock.search(eq(name), anyString(), any()));
private BDDMockito.BDDMyOngoingStubbing<javax.naming.NamingEnumeration<SearchResult>> whenSearching(Name name)
throws Exception {
return given(this.dirContextMock.search(eq(name), anyString(), any()));
}
private static class NamingEnumeration implements javax.naming.NamingEnumeration<SearchResult> {

View File

@@ -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();

View File

@@ -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<SearchControls> 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<Object> 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() {

View File

@@ -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;
}

View File

@@ -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 <code>list</code> 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);

View File

@@ -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<Object> 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.<String>enumeration(Collections.<String>emptyList()));
given(this.nameMock.getAll()).willReturn(Collections.<String>enumeration(Collections.<String>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);

View File

@@ -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);

View File

@@ -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<Object> 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<Object> 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<Object> 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<Object> 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<Object> 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<Object> 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<DirContextAdapter> 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<DirContextAdapter> 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<DirContextAdapter> 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() {

View File

@@ -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());
}
}

View File

@@ -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<String, BaseLdapPathSource> expectedBeans = new HashMap<String, BaseLdapPathSource>() {
@@ -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();
}

View File

@@ -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;
}
}
}

View File

@@ -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);

View File

@@ -45,4 +45,4 @@ public class DefaultTlsDirContextAuthenticationStrategyTests {
verify(this.context).lookup("");
}
}
}

View File

@@ -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<Object>() {

View File

@@ -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);

View File

@@ -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)

View File

@@ -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,

View File

@@ -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();

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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,

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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");
}
}

View File

@@ -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

View File

@@ -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() {

View File

@@ -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

View File

@@ -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();

View File

@@ -35,7 +35,6 @@ public class RenameOperationExecutorTests {
@Before
public void setUp() throws Exception {
this.ldapOperationsMock = mock(LdapOperations.class);
;
}
@Test

View File

@@ -32,7 +32,6 @@ public class RenameOperationRecorderTests {
@Before
public void setUp() throws Exception {
this.ldapOperationsMock = mock(LdapOperations.class);
;
}
@Test

View File

@@ -34,7 +34,6 @@ public class UnbindOperationExecutorTests {
@Before
public void setUp() throws Exception {
this.ldapOperationsMock = mock(LdapOperations.class);
;
}
@Test

View File

@@ -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 });

View File

@@ -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");

View File

@@ -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();

View File

@@ -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();
}