Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;

Expand Down Expand Up @@ -85,37 +85,19 @@ public void testGetCredentials_TargetHasNoPrincipal() {
@Test
public void testAfterPropertiesSet_noTarget() throws Exception {
this.tested.setTarget(null);
try {
this.tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException expected) {
assertThat(true).isTrue();
}
assertThatIllegalArgumentException().isThrownBy(() -> this.tested.afterPropertiesSet());
}

@Test
public void testAfterPropertiesSet_noDefaultUser() throws Exception {
this.tested.setDefaultUser(null);
try {
this.tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException expected) {
assertThat(true).isTrue();
}
assertThatIllegalArgumentException().isThrownBy(() -> this.tested.afterPropertiesSet());
}

@Test
public void testAfterPropertiesSet_noDefaultPassword() throws Exception {
this.tested.setDefaultPassword(null);
try {
this.tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException expected) {
assertThat(true).isTrue();
}
assertThatIllegalArgumentException().isThrownBy(() -> this.tested.afterPropertiesSet());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.springframework.ldap.UncategorizedLdapException;
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.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.verify;
Expand Down Expand Up @@ -83,13 +82,8 @@ public void testRename_NameAlreadyBoundException() throws Exception {
javax.naming.NameAlreadyBoundException ne = new javax.naming.NameAlreadyBoundException();
willThrow(ne).given(this.dirContextMock).rename(this.oldName, this.newName);

try {
this.tested.modify(this.oldName).name(this.newName).execute();
fail("NameAlreadyBoundException expected");
}
catch (NameAlreadyBoundException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(NameAlreadyBoundException.class)
.isThrownBy(() -> this.tested.modify(this.oldName).name(this.newName).execute());

verify(this.dirContextMock).close();
}
Expand All @@ -102,13 +96,8 @@ public void testRename_NamingException() throws Exception {

willThrow(ne).given(this.dirContextMock).rename(this.oldName, this.newName);

try {
this.tested.modify(this.oldName).name(this.newName).execute();
fail("UncategorizedLdapException expected");
}
catch (UncategorizedLdapException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(UncategorizedLdapException.class)
.isThrownBy(() -> this.tested.modify(this.oldName).name(this.newName).execute());

verify(this.dirContextMock).close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
Expand Down Expand Up @@ -232,17 +231,9 @@ public void testSearch_NameNotFoundException() throws Exception {
argThat(new SearchControlsMatcher(controls))))
.willThrow(ne);

try {
this.tested.search()
.query((builder) -> builder.base(this.nameMock)
.searchScope(SearchScope.SUBTREE)
.filter("(ou=somevalue)"))
.toObject(this.attributesMapperMock);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(NameNotFoundException.class).isThrownBy(() -> this.tested.search()
.query((builder) -> builder.base(this.nameMock).searchScope(SearchScope.SUBTREE).filter("(ou=somevalue)"))
.toObject(this.attributesMapperMock));
verify(this.dirContextMock).close();
}

Expand All @@ -258,16 +249,9 @@ public void testSearch_NamingException() throws Exception {
argThat(new SearchControlsMatcher(controls))))
.willThrow(ne);

try {
this.tested.search()
.query((builder) -> builder.base(this.nameMock).filter("(ou=somevalue)"))
.toObject(this.attributesMapperMock);
fail("LimitExceededException expected");
}
catch (LimitExceededException expected) {
// expected
}

assertThatExceptionOfType(LimitExceededException.class).isThrownBy(() -> this.tested.search()
.query((builder) -> builder.base(this.nameMock).filter("(ou=somevalue)"))
.toObject(this.attributesMapperMock));
verify(this.dirContextMock).close();
}

Expand Down Expand Up @@ -321,14 +305,8 @@ public void testModifyAttributes_NamingException() throws Exception {

javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException();
willThrow(ne).given(this.dirContextMock).modifyAttributes(this.nameMock, mods);

try {
this.tested.modify(this.nameMock).attributes(mods).execute();
fail("LimitExceededException expected");
}
catch (LimitExceededException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(LimitExceededException.class)
.isThrownBy(() -> this.tested.modify(this.nameMock).attributes(mods).execute());

verify(this.dirContextMock).close();
}
Expand Down Expand Up @@ -369,13 +347,8 @@ public void testBind_NamingException() throws Exception {
javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException();
willThrow(ne).given(this.dirContextMock).bind(this.nameMock, expectedObject, expectedAttributes);

try {
this.tested.bind(this.nameMock).object(expectedObject).attributes(expectedAttributes).execute();
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(NameNotFoundException.class).isThrownBy(
() -> this.tested.bind(this.nameMock).object(expectedObject).attributes(expectedAttributes).execute());

verify(this.dirContextMock).close();
}
Expand Down Expand Up @@ -508,14 +481,8 @@ public void testUnbind_NamingException() throws Exception {

javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException();
willThrow(ne).given(this.dirContextMock).unbind(this.nameMock);

try {
this.tested.unbind(this.nameMock).execute();
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(NameNotFoundException.class)
.isThrownBy(() -> this.tested.unbind(this.nameMock).execute());

verify(this.dirContextMock).close();
}
Expand All @@ -526,15 +493,8 @@ public void testSearch_PartialResult_IgnoreNotSet() throws Exception {

javax.naming.PartialResultException ex = new javax.naming.PartialResultException();
given(this.dirContextMock.search(eq(this.nameMock), anyString(), any())).willThrow(ex);

try {
this.tested.search().name(this.nameMock).toEntryList();
fail("PartialResultException expected");
}
catch (PartialResultException expected) {
assertThat(true).isTrue();
}

assertThatExceptionOfType(PartialResultException.class)
.isThrownBy(() -> this.tested.search().name(this.nameMock).toEntryList());
verify(this.dirContextMock).close();
}

Expand Down Expand Up @@ -590,14 +550,10 @@ public void testAuthenticateWithTwoUsersFoundShouldThrowException() throws Excep

setupSearchResults(searchControlsRecursive(), new SearchResult[] { searchResult1, searchResult2 });

try {
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() -> {
LdapQuery query = LdapQueryBuilder.query().base(this.nameMock).filter("(ou=somevalue)");
this.tested.authenticate().query(query).password("password").execute();
fail("IncorrectResultSizeDataAccessException expected");
}
catch (IncorrectResultSizeDataAccessException expected) {
// expected
}
});

verify(this.dirContextMock).close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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.assertj.core.api.Assertions.assertThatIllegalArgumentException;

/**
* Tests the DirContextAdapter class.
Expand Down Expand Up @@ -181,13 +181,7 @@ class TestableDirContextAdapter extends DirContextAdapter {

}
this.tested = new TestableDirContextAdapter();
try {
this.tested.getStringAttributes("abc");
fail("ClassCastException expected");
}
catch (IllegalArgumentException expected) {
assertThat(true).isTrue();
}
assertThatIllegalArgumentException().isThrownBy(() -> this.tested.getStringAttributes("abc"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

/**
* Unit tests for {@link DistinguishedNameEditor}.
Expand All @@ -44,13 +44,8 @@ public void testSetAsText() throws Exception {
DistinguishedName result = (DistinguishedName) this.tested.getValue();
assertThat(result).isEqualTo(new DistinguishedName(expectedDn));

try {
result.getNames().add(new LdapRdn("cn", "john doe"));
fail("UnsupportedOperationException expected");
}
catch (UnsupportedOperationException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> result.getNames().add(new LdapRdn("cn", "john doe")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;

/**
* Unit tests for the {@link DistinguishedName} class.
Expand Down Expand Up @@ -73,13 +72,7 @@ public void testDistinguishedName_Ldap237_DestroyedByCompositeName() throws Inva
@Test
public void testEmptyPathImmutable() throws Exception {
DistinguishedName emptyPath = DistinguishedName.EMPTY_PATH;
try {
emptyPath.add("cn=John Doe");
fail("UnsupportedOperationException expected");
}
catch (UnsupportedOperationException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> emptyPath.add("cn=John Doe"));
}

@Test
Expand Down Expand Up @@ -295,13 +288,7 @@ public void testGetSuffix() {
suffix = path.getSuffix(4);
assertThat(suffix.size()).isEqualTo(0);

try {
path.getSuffix(5);
fail("ArrayIndexOutOfBoundsException expected");
}
catch (ArrayIndexOutOfBoundsException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class).isThrownBy(() -> path.getSuffix(5));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springframework.ldap.PartialResultException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.verify;
Expand Down Expand Up @@ -191,13 +191,7 @@ public void testList_PartialResultException() throws NamingException {
javax.naming.PartialResultException pre = new javax.naming.PartialResultException();
given(this.dirContextMock.list(NAME)).willThrow(pre);

try {
this.tested.list(NAME);
fail("PartialResultException expected");
}
catch (PartialResultException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(PartialResultException.class).isThrownBy(() -> this.tested.list(NAME));

verify(this.dirContextMock).close();
}
Expand Down Expand Up @@ -226,13 +220,7 @@ public void testList_NamingException() throws NamingException {
javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException();
given(this.dirContextMock.list(NAME)).willThrow(ne);

try {
this.tested.list(NAME);
fail("LimitExceededException expected");
}
catch (LimitExceededException expected) {
assertThat(true).isTrue();
}
assertThatExceptionOfType(LimitExceededException.class).isThrownBy(() -> this.tested.list(NAME));

verify(this.dirContextMock).close();
}
Expand Down
Loading