Start AssertJ Migration
Issue gh-3175
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
@@ -48,7 +48,7 @@ public class LdapUtilsTests {
|
||||
|
||||
when(mockCtx.getNameInNamespace()).thenReturn("dc=springframework,dc=org");
|
||||
|
||||
assertEquals("", LdapUtils.getRelativeName("dc=springframework,dc=org", mockCtx));
|
||||
assertThat(dc=org").as("").isCloseTo(LdapUtils.getRelativeName("dc=springframework, within(mockCtx)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,10 +71,10 @@ public class LdapUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testRootDnsAreParsedFromUrlsCorrectly() {
|
||||
assertEquals("", LdapUtils.parseRootDnFromUrl("ldap://monkeymachine"));
|
||||
assertEquals("", LdapUtils.parseRootDnFromUrl("ldap://monkeymachine:11389"));
|
||||
assertEquals("", LdapUtils.parseRootDnFromUrl("ldap://monkeymachine/"));
|
||||
assertEquals("", LdapUtils.parseRootDnFromUrl("ldap://monkeymachine.co.uk/"));
|
||||
assertThat(LdapUtils.parseRootDnFromUrl("ldap://monkeymachine")).isEqualTo("");
|
||||
assertThat(LdapUtils.parseRootDnFromUrl("ldap://monkeymachine:11389")).isEqualTo("");
|
||||
assertThat(LdapUtils.parseRootDnFromUrl("ldap://monkeymachine/")).isEqualTo("");
|
||||
assertThat(LdapUtils.parseRootDnFromUrl("ldap://monkeymachine.co.uk/")).isEqualTo("");
|
||||
assertEquals(
|
||||
"dc=springframework,dc=org",
|
||||
LdapUtils
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.ldap.core.AuthenticationSource;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -27,8 +27,8 @@ public class SpringSecurityAuthenticationSourceTests {
|
||||
@Test
|
||||
public void principalAndCredentialsAreEmptyWithNoAuthentication() {
|
||||
AuthenticationSource source = new SpringSecurityAuthenticationSource();
|
||||
assertEquals("", source.getPrincipal());
|
||||
assertEquals("", source.getCredentials());
|
||||
assertThat(source.getPrincipal()).isEqualTo("");
|
||||
assertThat(source.getCredentials()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -38,7 +38,7 @@ public class SpringSecurityAuthenticationSourceTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new AnonymousAuthenticationToken("key", "anonUser", AuthorityUtils
|
||||
.createAuthorityList("ignored")));
|
||||
assertEquals("", source.getPrincipal());
|
||||
assertThat(source.getPrincipal()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -56,7 +56,7 @@ public class SpringSecurityAuthenticationSourceTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken(new Object(), "password"));
|
||||
|
||||
assertEquals("password", source.getCredentials());
|
||||
assertThat(source.getCredentials()).isEqualTo("password");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,6 +68,6 @@ public class SpringSecurityAuthenticationSourceTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken(user.createUserDetails(), null));
|
||||
|
||||
assertEquals("uid=joe,ou=users", source.getPrincipal());
|
||||
assertThat(source.getPrincipal()).isEqualTo("uid=joe,ou=users");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.security.ldap;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -52,7 +52,7 @@ public class LdapAuthenticationProviderTests {
|
||||
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(
|
||||
new MockAuthenticator(), new MockAuthoritiesPopulator());
|
||||
|
||||
assertTrue(ldapProvider.supports(UsernamePasswordAuthenticationToken.class));
|
||||
assertThat(ldapProvider.supports(UsernamePasswordAuthenticationToken.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +60,7 @@ public class LdapAuthenticationProviderTests {
|
||||
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(
|
||||
new MockAuthenticator(), new MockAuthoritiesPopulator());
|
||||
|
||||
assertTrue(ldapProvider.getUserDetailsContextMapper() instanceof LdapUserDetailsMapper);
|
||||
assertThat(ldapProvider.getUserDetailsContextMapper() instanceof LdapUserDetailsMapper).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,24 +121,24 @@ public class LdapAuthenticationProviderTests {
|
||||
userMapper.setRoleAttributes(new String[] { "ou" });
|
||||
ldapProvider.setUserDetailsContextMapper(userMapper);
|
||||
|
||||
assertNotNull(ldapProvider.getAuthoritiesPopulator());
|
||||
assertThat(ldapProvider.getAuthoritiesPopulator()).isNotNull();
|
||||
|
||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
|
||||
"ben", "benspassword");
|
||||
Object authDetails = new Object();
|
||||
authRequest.setDetails(authDetails);
|
||||
Authentication authResult = ldapProvider.authenticate(authRequest);
|
||||
assertEquals("benspassword", authResult.getCredentials());
|
||||
assertSame(authDetails, authResult.getDetails());
|
||||
assertThat(authResult.getCredentials()).isEqualTo("benspassword");
|
||||
assertThat(authResult.getDetails()).isSameAs(authDetails);
|
||||
UserDetails user = (UserDetails) authResult.getPrincipal();
|
||||
assertEquals(2, user.getAuthorities().size());
|
||||
assertEquals("{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=", user.getPassword());
|
||||
assertEquals("ben", user.getUsername());
|
||||
assertEquals("ben", populator.getRequestedUsername());
|
||||
assertThat(user.getAuthorities()).hasSize(2);
|
||||
assertThat(user.getPassword()).isEqualTo("{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=");
|
||||
assertThat(user.getUsername()).isEqualTo("ben");
|
||||
assertThat(populator.getRequestedUsername()).isEqualTo("ben");
|
||||
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_FROM_ENTRY"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_FROM_POPULATOR"));
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class LdapAuthenticationProviderTests {
|
||||
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
|
||||
"ben", "benspassword");
|
||||
Authentication authResult = ldapProvider.authenticate(authRequest);
|
||||
assertEquals("{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=", authResult.getCredentials());
|
||||
assertThat(authResult.getCredentials()).isEqualTo("{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=");
|
||||
|
||||
}
|
||||
|
||||
@@ -166,8 +166,8 @@ public class LdapAuthenticationProviderTests {
|
||||
"ben", "benspassword");
|
||||
UserDetails user = (UserDetails) ldapProvider.authenticate(authRequest)
|
||||
.getPrincipal();
|
||||
assertEquals(1, user.getAuthorities().size());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(user.getAuthorities()).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_FROM_ENTRY"));
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public class LdapAuthenticationProviderTests {
|
||||
fail("Expected Exception");
|
||||
}
|
||||
catch (InternalAuthenticationServiceException success) {
|
||||
assertSame(expectedCause, success.getCause());
|
||||
assertThat(success.getCause()).isSameAs(expectedCause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -109,13 +109,13 @@ public class LdapShaPasswordEncoderTests {
|
||||
sha.setForceLowerCasePrefix(false);
|
||||
assertEquals("{SHA}ddSFGmjXYPbZC+NXR2kCzBRjqiE=",
|
||||
sha.encodePassword("boabspasswurd", null));
|
||||
assertTrue(sha.encodePassword("somepassword", "salt".getBytes()).startsWith(
|
||||
assertThat(sha.encodePassword("somepassword", "salt".getBytes()).isTrue().startsWith(
|
||||
"{SSHA}"));
|
||||
|
||||
sha.setForceLowerCasePrefix(true);
|
||||
assertEquals("{sha}ddSFGmjXYPbZC+NXR2kCzBRjqiE=",
|
||||
sha.encodePassword("boabspasswurd", null));
|
||||
assertTrue(sha.encodePassword("somepassword", "salt".getBytes()).startsWith(
|
||||
assertThat(sha.encodePassword("somepassword", "salt".getBytes()).isTrue().startsWith(
|
||||
"{ssha}"));
|
||||
|
||||
}
|
||||
|
||||
@@ -45,10 +45,10 @@ import javax.naming.directory.SearchResult;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider.ContextFactory;
|
||||
|
||||
@@ -72,8 +72,8 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
|
||||
@Test
|
||||
public void bindPrincipalIsCreatedCorrectly() throws Exception {
|
||||
assertEquals("joe@mydomain.eu", provider.createBindPrincipal("joe"));
|
||||
assertEquals("joe@mydomain.eu", provider.createBindPrincipal("joe@mydomain.eu"));
|
||||
assertThat(provider.createBindPrincipal("joe")).isEqualTo("joe@mydomain.eu");
|
||||
assertThat(provider.createBindPrincipal("joe@mydomain.eu")).isEqualTo("joe@mydomain.eu");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,7 +107,7 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
Authentication result = customProvider.authenticate(joe);
|
||||
|
||||
// then
|
||||
assertTrue(result.isAuthenticated());
|
||||
assertThat(result.isAuthenticated()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,7 +134,7 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
Authentication result = customProvider.authenticate(joe);
|
||||
|
||||
// then
|
||||
assertTrue(result.isAuthenticated());
|
||||
assertThat(result.isAuthenticated()).isTrue();
|
||||
verify(ctx).search(any(DistinguishedName.class), eq(defaultSearchFilter),
|
||||
any(Object[].class), any(SearchControls.class));
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
|
||||
// then
|
||||
assertThat(captor.getValue()).containsOnly("joe@mydomain.eu");
|
||||
assertTrue(result.isAuthenticated());
|
||||
assertThat(result.isAuthenticated()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -429,13 +429,13 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
|
||||
Authentication result = provider.authenticate(joe);
|
||||
|
||||
assertEquals(0, result.getAuthorities().size());
|
||||
assertThat(result.getAuthorities()).isEmpty();
|
||||
|
||||
dca.addAttributeValue("memberOf", "CN=Admin,CN=Users,DC=mydomain,DC=eu");
|
||||
|
||||
result = provider.authenticate(joe);
|
||||
|
||||
assertEquals(1, result.getAuthorities().size());
|
||||
assertThat(result.getAuthorities()).hasSize(1);
|
||||
}
|
||||
|
||||
static class MockNamingEnumeration implements NamingEnumeration<SearchResult> {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class PasswordPolicyAwareContextSourceTests {
|
||||
@Test
|
||||
public void contextIsReturnedWhenNoControlsAreSetAndReconnectIsSuccessful()
|
||||
throws Exception {
|
||||
assertNotNull(ctxSource.getContext("user", "ignored"));
|
||||
assertThat(ctxSource.getContext("user", "ignored")).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = UncategorizedLdapException.class)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.ldap.ppolicy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.*;
|
||||
@@ -19,7 +19,7 @@ public class PasswordPolicyControlFactoryTests {
|
||||
Control wrongCtrl = mock(Control.class);
|
||||
|
||||
when(wrongCtrl.getID()).thenReturn("wrongId");
|
||||
assertNull(ctrlFactory.getControlInstance(wrongCtrl));
|
||||
assertThat(ctrlFactory.getControlInstance(wrongCtrl)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -31,7 +31,7 @@ public class PasswordPolicyControlFactoryTests {
|
||||
when(control.getEncodedValue()).thenReturn(
|
||||
PasswordPolicyResponseControlTests.OPENLDAP_LOCKED_CTRL);
|
||||
Control result = ctrlFactory.getControlInstance(control);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
assertTrue(Arrays.equals(PasswordPolicyResponseControlTests.OPENLDAP_LOCKED_CTRL,
|
||||
result.getEncodedValue()));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap.ppolicy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class PasswordPolicyResponseControlTests {
|
||||
// PasswordPolicyResponseControl ctrl = getPPolicyResponseCtl(ctx);
|
||||
// System.out.println(ctrl);
|
||||
//
|
||||
// assertNotNull(ctrl);
|
||||
// assertThat(ctrl).isNotNull();
|
||||
//
|
||||
// //com.sun.jndi.ldap.LdapPoolManager.showStats(System.out);
|
||||
// }
|
||||
@@ -90,8 +90,8 @@ public class PasswordPolicyResponseControlTests {
|
||||
|
||||
PasswordPolicyResponseControl ctrl = new PasswordPolicyResponseControl(ctrlBytes);
|
||||
|
||||
assertTrue(ctrl.hasWarning());
|
||||
assertEquals(33, ctrl.getTimeBeforeExpiration());
|
||||
assertThat(ctrl.hasWarning()).isTrue();
|
||||
assertThat(ctrl.getTimeBeforeExpiration()).isEqualTo(33);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,8 +101,8 @@ public class PasswordPolicyResponseControlTests {
|
||||
|
||||
PasswordPolicyResponseControl ctrl = new PasswordPolicyResponseControl(ctrlBytes);
|
||||
|
||||
assertTrue(ctrl.hasWarning());
|
||||
assertEquals(496, ctrl.getGraceLoginsRemaining());
|
||||
assertThat(ctrl.hasWarning()).isTrue();
|
||||
assertThat(ctrl.getGraceLoginsRemaining()).isEqualTo(496);
|
||||
}
|
||||
|
||||
static final byte[] OPENLDAP_5_LOGINS_REMAINING_CTRL = { 0x30, 0x05, (byte) 0xA0,
|
||||
@@ -113,8 +113,8 @@ public class PasswordPolicyResponseControlTests {
|
||||
PasswordPolicyResponseControl ctrl = new PasswordPolicyResponseControl(
|
||||
OPENLDAP_5_LOGINS_REMAINING_CTRL);
|
||||
|
||||
assertTrue(ctrl.hasWarning());
|
||||
assertEquals(5, ctrl.getGraceLoginsRemaining());
|
||||
assertThat(ctrl.hasWarning()).isTrue();
|
||||
assertThat(ctrl.getGraceLoginsRemaining()).isEqualTo(5);
|
||||
}
|
||||
|
||||
static final byte[] OPENLDAP_LOCKED_CTRL = { 0x30, 0x03, (byte) 0xA1, 0x01, 0x01 };
|
||||
@@ -124,8 +124,8 @@ public class PasswordPolicyResponseControlTests {
|
||||
PasswordPolicyResponseControl ctrl = new PasswordPolicyResponseControl(
|
||||
OPENLDAP_LOCKED_CTRL);
|
||||
|
||||
assertTrue(ctrl.hasError() && ctrl.isLocked());
|
||||
assertFalse(ctrl.hasWarning());
|
||||
assertThat(ctrl.hasError() && ctrl.isLocked()).isTrue();
|
||||
assertThat(ctrl.hasWarning()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,7 +134,7 @@ public class PasswordPolicyResponseControlTests {
|
||||
|
||||
PasswordPolicyResponseControl ctrl = new PasswordPolicyResponseControl(ctrlBytes);
|
||||
|
||||
assertTrue(ctrl.hasError() && ctrl.isExpired());
|
||||
assertFalse(ctrl.hasWarning());
|
||||
assertThat(ctrl.hasError() && ctrl.isExpired()).isTrue();
|
||||
assertThat(ctrl.hasWarning()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.ldap.userdetails;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -19,7 +19,7 @@ public class InetOrgPersonTests {
|
||||
InetOrgPerson.Essence essence = new InetOrgPerson.Essence(createUserContext());
|
||||
InetOrgPerson p = (InetOrgPerson) essence.createUserDetails();
|
||||
|
||||
assertEquals("ghengis", p.getUsername());
|
||||
assertThat(p.getUsername()).isEqualTo("ghengis");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -30,7 +30,7 @@ public class InetOrgPersonTests {
|
||||
InetOrgPerson p2 = (InetOrgPerson) essence.createUserDetails();
|
||||
Set<InetOrgPerson> set = new HashSet<InetOrgPerson>();
|
||||
set.add(p);
|
||||
assertTrue(set.contains(p2));
|
||||
assertThat(set.contains(p2)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,8 +39,8 @@ public class InetOrgPersonTests {
|
||||
essence.setUsername("joe");
|
||||
InetOrgPerson p = (InetOrgPerson) essence.createUserDetails();
|
||||
|
||||
assertEquals("joe", p.getUsername());
|
||||
assertEquals("ghengis", p.getUid());
|
||||
assertThat(p.getUsername()).isEqualTo("joe");
|
||||
assertThat(p.getUid()).isEqualTo("ghengis");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,24 +48,24 @@ public class InetOrgPersonTests {
|
||||
InetOrgPerson.Essence essence = new InetOrgPerson.Essence(createUserContext());
|
||||
InetOrgPerson p = (InetOrgPerson) essence.createUserDetails();
|
||||
|
||||
assertEquals("HORS1", p.getCarLicense());
|
||||
assertEquals("ghengis@mongolia", p.getMail());
|
||||
assertEquals("Ghengis", p.getGivenName());
|
||||
assertEquals("Khan", p.getSn());
|
||||
assertEquals("Ghengis Khan", p.getCn()[0]);
|
||||
assertEquals("00001", p.getEmployeeNumber());
|
||||
assertEquals("+442075436521", p.getTelephoneNumber());
|
||||
assertEquals("Steppes", p.getHomePostalAddress());
|
||||
assertEquals("+467575436521", p.getHomePhone());
|
||||
assertEquals("Hordes", p.getO());
|
||||
assertEquals("Horde1", p.getOu());
|
||||
assertEquals("On the Move", p.getPostalAddress());
|
||||
assertEquals("Changes Frequently", p.getPostalCode());
|
||||
assertEquals("Yurt 1", p.getRoomNumber());
|
||||
assertEquals("Westward Avenue", p.getStreet());
|
||||
assertEquals("Scary", p.getDescription());
|
||||
assertEquals("Ghengis McCann", p.getDisplayName());
|
||||
assertEquals("G", p.getInitials());
|
||||
assertThat(p.getCarLicense()).isEqualTo("HORS1");
|
||||
assertThat(p.getMail()).isEqualTo("ghengis@mongolia");
|
||||
assertThat(p.getGivenName()).isEqualTo("Ghengis");
|
||||
assertThat(p.getSn()).isEqualTo("Khan");
|
||||
assertThat(p.getCn()[0]).isEqualTo("Ghengis Khan");
|
||||
assertThat(p.getEmployeeNumber()).isEqualTo("00001");
|
||||
assertThat(p.getTelephoneNumber()).isEqualTo("+442075436521");
|
||||
assertThat(p.getHomePostalAddress()).isEqualTo("Steppes");
|
||||
assertThat(p.getHomePhone()).isEqualTo("+467575436521");
|
||||
assertThat(p.getO()).isEqualTo("Hordes");
|
||||
assertThat(p.getOu()).isEqualTo("Horde1");
|
||||
assertThat(p.getPostalAddress()).isEqualTo("On the Move");
|
||||
assertThat(p.getPostalCode()).isEqualTo("Changes Frequently");
|
||||
assertThat(p.getRoomNumber()).isEqualTo("Yurt 1");
|
||||
assertThat(p.getStreet()).isEqualTo("Westward Avenue");
|
||||
assertThat(p.getDescription()).isEqualTo("Scary");
|
||||
assertThat(p.getDisplayName()).isEqualTo("Ghengis McCann");
|
||||
assertThat(p.getInitials()).isEqualTo("G");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class InetOrgPersonTests {
|
||||
InetOrgPerson.Essence essence = new InetOrgPerson.Essence(createUserContext());
|
||||
InetOrgPerson p = (InetOrgPerson) essence.createUserDetails();
|
||||
|
||||
assertEquals("pillage", p.getPassword());
|
||||
assertThat(p.getPassword()).isEqualTo("pillage");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +87,7 @@ public class InetOrgPersonTests {
|
||||
.createUserDetails();
|
||||
p.populateContext(ctx2);
|
||||
|
||||
assertEquals(ctx1, ctx2);
|
||||
assertThat(ctx2).isEqualTo(ctx1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,7 +103,7 @@ public class InetOrgPersonTests {
|
||||
.createUserDetails();
|
||||
p2.populateContext(ctx2);
|
||||
|
||||
assertEquals(ctx1, ctx2);
|
||||
assertThat(ctx2).isEqualTo(ctx1);
|
||||
}
|
||||
|
||||
private DirContextAdapter createUserContext() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
@@ -31,9 +31,9 @@ public class LdapAuthorityTests {
|
||||
|
||||
@Test
|
||||
public void testGetDn() throws Exception {
|
||||
assertEquals(DN, authority.getDn());
|
||||
assertNotNull(authority.getAttributeValues(SpringSecurityLdapTemplate.DN_KEY));
|
||||
assertEquals(1, authority.getAttributeValues(SpringSecurityLdapTemplate.DN_KEY)
|
||||
assertThat(authority.getDn()).isEqualTo(DN);
|
||||
assertThat(authority.getAttributeValues(SpringSecurityLdapTemplate.DN_KEY)).isNotNull();
|
||||
assertThat(authority.getAttributeValues(SpringSecurityLdapTemplate.DN_KEY).isEqualTo(1)
|
||||
.size());
|
||||
assertEquals(DN,
|
||||
authority.getFirstAttributeValue(SpringSecurityLdapTemplate.DN_KEY));
|
||||
@@ -41,17 +41,17 @@ public class LdapAuthorityTests {
|
||||
|
||||
@Test
|
||||
public void testGetAttributes() throws Exception {
|
||||
assertNotNull(authority.getAttributes());
|
||||
assertNotNull(authority.getAttributeValues("mail"));
|
||||
assertEquals(2, authority.getAttributeValues("mail").size());
|
||||
assertEquals("filip@ldap.test.org", authority.getFirstAttributeValue("mail"));
|
||||
assertEquals("filip@ldap.test.org", authority.getAttributeValues("mail").get(0));
|
||||
assertEquals("filip@ldap.test2.org", authority.getAttributeValues("mail").get(1));
|
||||
assertThat(authority.getAttributes()).isNotNull();
|
||||
assertThat(authority.getAttributeValues("mail")).isNotNull();
|
||||
assertThat(authority.getAttributeValues("mail")).hasSize(2);
|
||||
assertThat(authority.getFirstAttributeValue("mail")).isEqualTo("filip@ldap.test.org");
|
||||
assertThat(authority.getAttributeValues("mail").get(0)).isEqualTo("filip@ldap.test.org");
|
||||
assertThat(authority.getAttributeValues("mail").get(1)).isEqualTo("filip@ldap.test2.org");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthority() throws Exception {
|
||||
assertNotNull(authority.getAuthority());
|
||||
assertEquals("testRole", authority.getAuthority());
|
||||
assertThat(authority.getAuthority()).isNotNull();
|
||||
assertThat(authority.getAuthority()).isEqualTo("testRole");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class LdapUserDetailsMapperTests extends TestCase {
|
||||
LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx,
|
||||
"ani", AuthorityUtils.NO_AUTHORITIES);
|
||||
|
||||
assertEquals(3, user.getAuthorities().size());
|
||||
assertThat(user.getAuthorities()).hasSize(3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,8 +67,8 @@ public class LdapUserDetailsMapperTests extends TestCase {
|
||||
LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx,
|
||||
"ani", AuthorityUtils.NO_AUTHORITIES);
|
||||
|
||||
assertEquals(1, user.getAuthorities().size());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(user.getAuthorities()).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_X"));
|
||||
}
|
||||
|
||||
@@ -86,6 +86,6 @@ public class LdapUserDetailsMapperTests extends TestCase {
|
||||
LdapUserDetails user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx,
|
||||
"ani", AuthorityUtils.NO_AUTHORITIES);
|
||||
|
||||
assertEquals("mypassword", user.getPassword());
|
||||
assertThat(user.getPassword()).isEqualTo("mypassword");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.ldap.userdetails;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
@@ -45,8 +45,8 @@ public class LdapUserDetailsServiceTests {
|
||||
|
||||
Set<String> authorities = AuthorityUtils
|
||||
.authorityListToSet(user.getAuthorities());
|
||||
assertEquals(1, authorities.size());
|
||||
assertTrue(authorities.contains("ROLE_FROM_POPULATOR"));
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(authorities.contains("ROLE_FROM_POPULATOR")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,7 +57,7 @@ public class LdapUserDetailsServiceTests {
|
||||
LdapUserDetailsService service = new LdapUserDetailsService(new MockUserSearch(
|
||||
userData));
|
||||
UserDetails user = service.loadUserByUsername("doesntmatterwegetjoeanyway");
|
||||
assertEquals(0, user.getAuthorities().size());
|
||||
assertThat(user.getAuthorities()).isEmpty();
|
||||
}
|
||||
|
||||
class MockAuthoritiesPopulator implements LdapAuthoritiesPopulator {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.ldap.userdetails;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -32,7 +32,7 @@ public class UserDetailsServiceLdapAuthoritiesPopulatorTests {
|
||||
Collection<? extends GrantedAuthority> auths = populator.getGrantedAuthorities(
|
||||
new DirContextAdapter(), "joe");
|
||||
|
||||
assertEquals(1, auths.size());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(auths).contains("ROLE_USER"));
|
||||
assertThat(auths).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(auths).contains("ROLE_USER")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user