1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Start AssertJ Migration

Issue gh-3175
This commit is contained in:
Rob Winch
2015-12-16 10:38:31 -06:00
parent 6cbb439701
commit bb600a473e
355 changed files with 3036 additions and 3133 deletions
@@ -1,6 +1,6 @@
package org.springframework.security.ldap;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.ArrayList;
import java.util.Hashtable;
@@ -21,8 +21,8 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
public void instantiationSucceedsWithExpectedProperties() {
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
"ldap://blah:789/dc=springframework,dc=org");
assertFalse(ctxSrc.isAnonymousReadOnly());
assertTrue(ctxSrc.isPooled());
assertThat(ctxSrc.isAnonymousReadOnly()).isFalse();
assertThat(ctxSrc.isPooled()).isTrue();
}
@Test
@@ -39,7 +39,7 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
ctxSrc.setUserDn("manager");
ctxSrc.setPassword("password");
ctxSrc.afterPropertiesSet();
assertTrue(ctxSrc.getAuthenticatedEnvForTest("manager", "password").containsKey(
assertThat(ctxSrc.getAuthenticatedEnvForTest("manager", "password").isTrue().containsKey(
AbstractContextSource.SUN_LDAP_POOLING_FLAG));
}
@@ -51,7 +51,7 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
ctxSrc.setUserDn("manager");
ctxSrc.setPassword("password");
ctxSrc.afterPropertiesSet();
assertFalse(ctxSrc.getAuthenticatedEnvForTest("user", "password").containsKey(
assertThat(ctxSrc.getAuthenticatedEnvForTest("user", "password").isFalse().containsKey(
AbstractContextSource.SUN_LDAP_POOLING_FLAG));
}
@@ -66,7 +66,7 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
}
catch (Exception e) {
}
assertNotNull(ctx);
assertThat(ctx).isNotNull();
// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out);
ctx.close();
// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out);
@@ -104,8 +104,8 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
serverUrls, "dc=springframework,dc=org");
assertFalse(ctxSrc.isAnonymousReadOnly());
assertTrue(ctxSrc.isPooled());
assertThat(ctxSrc.isAnonymousReadOnly()).isFalse();
assertThat(ctxSrc.isPooled()).isTrue();
}
// SEC-2308
@@ -119,8 +119,8 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
serverUrls, baseDn);
assertFalse(ctxSrc.isAnonymousReadOnly());
assertTrue(ctxSrc.isPooled());
assertThat(ctxSrc.isAnonymousReadOnly()).isFalse();
assertThat(ctxSrc.isPooled()).isTrue();
}
@Test(expected = IllegalArgumentException.class)
@@ -15,7 +15,7 @@
package org.springframework.security.ldap;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
import java.util.Map;
@@ -51,7 +51,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
@Test
public void compareOfCorrectValueSucceeds() {
assertTrue(template.compare("uid=bob,ou=people", "uid", "bob"));
assertThat(template.compare("uid=bob,ou=people", "uid", "bob")).isTrue();
}
@Test
@@ -68,17 +68,17 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
@Test
public void compareOfWrongValueFails() {
assertFalse(template.compare("uid=bob,ou=people", "uid", "wrongvalue"));
assertThat(template.compare("uid=bob,ou=people", "uid", "wrongvalue")).isFalse();
}
// @Test
// public void testNameExistsForInValidNameFails() {
// assertFalse(template.nameExists("ou=doesntexist,dc=springframework,dc=org"));
// assertThat(template.nameExists("ou=doesntexist,dc=springframework,dc=org")).isFalse();
// }
//
// @Test
// public void testNameExistsForValidNameSucceeds() {
// assertTrue(template.nameExists("ou=groups,dc=springframework,dc=org"));
// assertThat(template.nameExists("ou=groups,dc=springframework,dc=org")).isTrue();
// }
@Test
@@ -103,10 +103,10 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
Set<String> values = template.searchForSingleAttributeValues("ou=groups",
"(member={0})", new String[] { param }, "ou");
assertEquals("Expected 3 results from search", 3, values.size());
assertTrue(values.contains("developer"));
assertTrue(values.contains("manager"));
assertTrue(values.contains("submanager"));
assertThat(values).as("Expected 3 results from search").hasSize(3);
assertThat(values.contains("developer")).isTrue();
assertThat(values.contains("manager")).isTrue();
assertThat(values.contains("submanager")).isTrue();
}
@Test
@@ -114,14 +114,14 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
Set<Map<String, List<String>>> values = template
.searchForMultipleAttributeValues("ou=people", "(uid={0})",
new String[] { "bob" }, null);
assertEquals(1, values.size());
assertThat(values).hasSize(1);
Map<String, List<String>> record = values.iterator().next();
assertAttributeValue(record, "uid", "bob");
assertAttributeValue(record, "objectclass", "top", "person",
"organizationalPerson", "inetOrgPerson");
assertAttributeValue(record, "cn", "Bob Hamilton");
assertAttributeValue(record, "sn", "Hamilton");
assertFalse(record.containsKey("userPassword"));
assertThat(record.containsKey("userPassword")).isFalse();
}
@Test
@@ -129,14 +129,14 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
Set<Map<String, List<String>>> values = template
.searchForMultipleAttributeValues("ou=people", "(uid={0})",
new String[] { "bob" }, new String[0]);
assertEquals(1, values.size());
assertThat(values).hasSize(1);
Map<String, List<String>> record = values.iterator().next();
assertAttributeValue(record, "uid", "bob");
assertAttributeValue(record, "objectclass", "top", "person",
"organizationalPerson", "inetOrgPerson");
assertAttributeValue(record, "cn", "Bob Hamilton");
assertAttributeValue(record, "sn", "Hamilton");
assertFalse(record.containsKey("userPassword"));
assertThat(record.containsKey("userPassword")).isFalse();
}
@Test
@@ -144,21 +144,21 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
Set<Map<String, List<String>>> values = template
.searchForMultipleAttributeValues("ou=people", "(uid={0})",
new String[] { "bob" }, new String[] { "uid", "cn", "sn" });
assertEquals(1, values.size());
assertThat(values).hasSize(1);
Map<String, List<String>> record = values.iterator().next();
assertAttributeValue(record, "uid", "bob");
assertAttributeValue(record, "cn", "Bob Hamilton");
assertAttributeValue(record, "sn", "Hamilton");
assertFalse(record.containsKey("userPassword"));
assertFalse(record.containsKey("objectclass"));
assertThat(record.containsKey("userPassword")).isFalse();
assertThat(record.containsKey("objectclass")).isFalse();
}
protected void assertAttributeValue(Map<String, List<String>> record,
String attributeName, String... values) {
assertTrue(record.containsKey(attributeName));
assertEquals(values.length, record.get(attributeName).size());
assertThat(record.containsKey(attributeName)).isTrue();
assertThat(record.get(attributeName).size()).isEqualTo(values.length);
for (int i = 0; i < values.length; i++) {
assertEquals(values[i], record.get(attributeName).get(i));
assertThat(record.get(attributeName).get(i)).isEqualTo(values[i]);
}
}
@@ -169,7 +169,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
Set<String> values = template.searchForSingleAttributeValues("ou=groups",
"(member={0})", new String[] { param }, "mail");
assertEquals(0, values.size());
assertThat(values).isEmpty();
}
@Test
@@ -179,7 +179,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
Set<String> values = template.searchForSingleAttributeValues("ou=groups",
"(member={0})", new String[] { param }, "cn");
assertEquals(1, values.size());
assertThat(values).hasSize(1);
}
@Test
@@ -202,7 +202,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
"ou=groups,dc=springframework,dc=org", "(member={0})",
new String[] { param }, controls);
assertTrue("Expected a result", results.hasMore());
assertThat(results.hasMore()).as("Expected a result").isTrue();
}
@Test
@@ -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.*;
import org.springframework.ldap.core.DirContextOperations;
@@ -60,7 +60,7 @@ public class BindAuthenticatorTests extends AbstractLdapIntegrationTests {
"cn={0},ou=people" });
DirContextOperations user = authenticator.authenticate(bob);
assertEquals("bob", user.getStringAttribute("uid"));
assertThat(user.getStringAttribute("uid")).isEqualTo("bob");
authenticator.authenticate(new UsernamePasswordAuthenticationToken(
"mouse, jerry", "jerryspassword"));
}
@@ -141,6 +141,6 @@ public class BindAuthenticatorTests extends AbstractLdapIntegrationTests {
@Test
public void testUserDnPatternReturnsCorrectDn() {
authenticator.setUserDnPatterns(new String[] { "cn={0},ou=people" });
assertEquals("cn=Joe,ou=people", authenticator.getUserDns("Joe").get(0));
assertThat(authenticator.getUserDns("Joe").get(0)).isEqualTo("cn=Joe,ou=people");
}
}
@@ -28,7 +28,7 @@ import org.springframework.security.ldap.AbstractLdapIntegrationTests;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
/**
* Tests for {@link PasswordComparisonAuthenticator}.
@@ -59,7 +59,7 @@ public class PasswordComparisonAuthenticatorTests extends AbstractLdapIntegratio
public void testAllAttributesAreRetrievedByDefault() {
DirContextAdapter user = (DirContextAdapter) authenticator.authenticate(bob);
// System.out.println(user.getAttributes().toString());
assertEquals("User should have 5 attributes", 5, user.getAttributes().size());
assertThat(user.getAttributes()).as("User should have 5 attributes").hasSize(5);
}
@Test
@@ -99,7 +99,7 @@ public class PasswordComparisonAuthenticatorTests extends AbstractLdapIntegratio
authenticator.setUserAttributes(new String[] { "uid", "userPassword" });
DirContextAdapter user = (DirContextAdapter) authenticator.authenticate(bob);
assertEquals("Should have retrieved 2 attribute (uid, userPassword)", 2, user
assertThat(userPassword).isEqualTo("Should have retrieved 2 attribute (uid)", 2, user
.getAttributes().size());
}
@@ -15,7 +15,7 @@
package org.springframework.security.ldap.search;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import javax.naming.ldap.LdapName;
@@ -41,9 +41,9 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
locator.setDerefLinkFlag(false);
DirContextOperations bob = locator.searchForUser("bob");
assertEquals("bob", bob.getStringAttribute("uid"));
assertThat(bob.getStringAttribute("uid")).isEqualTo("bob");
assertEquals(new LdapName("uid=bob,ou=people"), bob.getDn());
assertThat(bob.getDn()).isEqualTo(new LdapName("uid=bob,ou=people"));
}
@Test
@@ -53,9 +53,9 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
locator.setSearchSubtree(false);
DirContextOperations jerry = locator.searchForUser("jerry");
assertEquals("jerry", jerry.getStringAttribute("uid"));
assertThat(jerry.getStringAttribute("uid")).isEqualTo("jerry");
assertEquals(new LdapName("cn=mouse\\, jerry,ou=people"), jerry.getDn());
assertThat(jerry.getDn()).isEqualTo(new LdapName("cn=mouse\\, jerry,ou=people"));
}
// Try some funny business with filters.
@@ -68,7 +68,7 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
// Search for bob, get back ben...
DirContextOperations ben = locator.searchForUser("bob");
assertEquals("Ben Alex", ben.getStringAttribute("cn"));
assertThat(ben.getStringAttribute("cn")).isEqualTo("Ben Alex");
}
@Test(expected = IncorrectResultSizeDataAccessException.class)
@@ -93,9 +93,9 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
locator.setSearchSubtree(true);
DirContextOperations ben = locator.searchForUser("Ben Alex");
assertEquals("ben", ben.getStringAttribute("uid"));
assertThat(ben.getStringAttribute("uid")).isEqualTo("ben");
assertEquals(new LdapName("uid=ben,ou=people"), ben.getDn());
assertThat(ben.getDn()).isEqualTo(new LdapName("uid=ben,ou=people"));
}
@Test
@@ -103,7 +103,7 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch(
"ou=otherpeople", "(cn={0})", getContextSource());
DirContextOperations joe = locator.searchForUser("Joe Smeth");
assertEquals("Joe Smeth", joe.getStringAttribute("cn"));
assertThat(joe.getStringAttribute("cn")).isEqualTo("Joe Smeth");
}
}
@@ -15,7 +15,7 @@
package org.springframework.security.ldap.userdetails;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.*;
import org.springframework.ldap.core.DirContextAdapter;
@@ -47,15 +47,15 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
@Test
public void defaultRoleIsAssignedWhenSet() {
populator.setDefaultRole("ROLE_USER");
assertSame(getContextSource(), populator.getContextSource());
assertThat(populator.getContextSource()).isSameAs(getContextSource());
DirContextAdapter ctx = new DirContextAdapter(
new DistinguishedName("cn=notfound"));
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
"notfound");
assertEquals(1, authorities.size());
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
assertThat(authorities).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
}
@Test
@@ -65,8 +65,8 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(
new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
assertEquals(1, authorities.size());
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
assertThat(authorities).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
}
@Test
@@ -84,10 +84,10 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
.getGrantedAuthorities(ctx, "ben"));
assertEquals("Should have 2 roles", 2, authorities.size());
assertThat(authorities).as("Should have 2 roles").hasSize(2);
assertTrue(authorities.contains("ROLE_DEVELOPER"));
assertTrue(authorities.contains("ROLE_MANAGER"));
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
}
@Test
@@ -102,8 +102,8 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
.getGrantedAuthorities(ctx, "manager"));
assertEquals("Should have 1 role", 1, authorities.size());
assertTrue(authorities.contains("ROLE_MANAGER"));
assertThat(authorities).as("Should have 1 role").hasSize(1);
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
}
@Test
@@ -117,9 +117,9 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
.getGrantedAuthorities(ctx, "manager"));
assertEquals("Should have 2 roles", 2, authorities.size());
assertTrue(authorities.contains("ROLE_MANAGER"));
assertTrue(authorities.contains("ROLE_DEVELOPER"));
assertThat(authorities).as("Should have 2 roles").hasSize(2);
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
}
@Test
@@ -134,10 +134,10 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
.getGrantedAuthorities(ctx, "manager"));
assertEquals("Should have 3 roles", 3, authorities.size());
assertTrue(authorities.contains("ROLE_MANAGER"));
assertTrue(authorities.contains("ROLE_SUBMANAGER"));
assertTrue(authorities.contains("ROLE_DEVELOPER"));
assertThat(authorities).as("Should have 3 roles").hasSize(3);
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
assertThat(authorities.contains("ROLE_SUBMANAGER")).isTrue();
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
}
@Test
@@ -153,8 +153,8 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(
new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
assertEquals(1, authorities.size());
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_EXTRA"));
assertThat(authorities).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_EXTRA")).isTrue();
}
@Test
@@ -169,7 +169,7 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
.getGrantedAuthorities(ctx, "notused"));
assertEquals("Should have 1 role", 1, authorities.size());
assertTrue(authorities.contains("ROLE_MANAGER"));
assertThat(authorities).as("Should have 1 role").hasSize(1);
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
}
}
@@ -14,10 +14,10 @@
*/
package org.springframework.security.ldap.userdetails;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
import java.util.List;
@@ -100,11 +100,11 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));
mgr.setGroupSearchBase("ou=groups");
LdapUserDetails bob = (LdapUserDetails) mgr.loadUserByUsername("bob");
assertEquals("bob", bob.getUsername());
assertEquals("uid=bob,ou=people,dc=springframework,dc=org", bob.getDn());
assertEquals("bobspassword", bob.getPassword());
assertThat(bob.getUsername()).isEqualTo("bob");
assertThat(bob.getDn()).isEqualTo("uid=bob,ou=people,dc=springframework,dc=org");
assertThat(bob.getPassword()).isEqualTo("bobspassword");
assertEquals(1, bob.getAuthorities().size());
assertThat(bob.getAuthorities()).hasSize(1);
}
@Test(expected = UsernameNotFoundException.class)
@@ -115,12 +115,12 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
@Test
public void testUserExistsReturnsTrueForValidUser() {
mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));
assertTrue(mgr.userExists("bob"));
assertThat(mgr.userExists("bob")).isTrue();
}
@Test
public void testUserExistsReturnsFalseForInValidUser() {
assertFalse(mgr.userExists("jim"));
assertThat(mgr.userExists("jim")).isFalse();
}
@Test
@@ -160,7 +160,7 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
InetOrgPerson don = (InetOrgPerson) mgr.loadUserByUsername("don");
assertEquals(2, don.getAuthorities().size());
assertThat(don.getAuthorities()).hasSize(2);
mgr.deleteUser("don");
@@ -173,7 +173,7 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
}
// Check that no authorities are left
assertEquals(0, mgr.getUserAuthorities(mgr.usernameMapper.buildDn("don"), "don")
assertThat("don").isEqualTo(0, mgr.getUserAuthorities(mgr.usernameMapper.buildDn("don"))
.size());
}
@@ -24,7 +24,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
/**
* @author Filip Hanik
@@ -71,7 +71,7 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
"uid=scaladude,ou=people,dc=springframework,dc=org");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
"scaladude");
assertEquals(5, authorities.size());
assertThat(authorities).hasSize(5);
assertEquals(Arrays.asList(javaDevelopers, scalaDevelopers,
circularJavaDevelopers, jDevelopers, groovyDevelopers), authorities);
}
@@ -82,8 +82,8 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
"uid=javadude,ou=people,dc=springframework,dc=org");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
"javadude");
assertEquals(3, authorities.size());
assertEquals(Arrays.asList(javaDevelopers, circularJavaDevelopers, jDevelopers),
assertThat(authorities).hasSize(3);
assertThat(circularJavaDevelopers).isCloseTo(Arrays.asList(javaDevelopers, within(jDevelopers)),
authorities);
}
@@ -94,8 +94,8 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
"uid=scaladude,ou=people,dc=springframework,dc=org");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
"scaladude");
assertEquals(1, authorities.size());
assertEquals(Arrays.asList(scalaDevelopers), authorities);
assertThat(authorities).hasSize(1);
assertThat(authorities).isEqualTo(Arrays.asList(scalaDevelopers));
}
@Test
@@ -104,7 +104,7 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
"uid=groovydude,ou=people,dc=springframework,dc=org");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
"groovydude");
assertEquals(4, authorities.size());
assertThat(authorities).hasSize(4);
assertEquals(Arrays.asList(javaDevelopers, circularJavaDevelopers, jDevelopers,
groovyDevelopers), authorities);
}
@@ -117,34 +117,34 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
"uid=closuredude,ou=people,dc=springframework,dc=org");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
"closuredude");
assertEquals(5, authorities.size());
assertThat(authorities).hasSize(5);
assertEquals(Arrays.asList(closureDevelopers, javaDevelopers,
circularJavaDevelopers, jDevelopers, groovyDevelopers), authorities);
LdapAuthority[] ldapAuthorities = authorities.toArray(new LdapAuthority[0]);
assertEquals(5, ldapAuthorities.length);
assertThat(ldapAuthorities.length).isEqualTo(5);
// closure group
assertTrue(ldapAuthorities[0].getAttributes().containsKey("member"));
assertNotNull(ldapAuthorities[0].getAttributes().get("member"));
assertEquals(1, ldapAuthorities[0].getAttributes().get("member").size());
assertThat(ldapAuthorities[0].getAttributes().containsKey("member")).isTrue();
assertThat(ldapAuthorities[0].getAttributes().get("member")).isNotNull();
assertThat(ldapAuthorities[0].getAttributes().get("member")).hasSize(1);
assertEquals("uid=closuredude,ou=people,dc=springframework,dc=org",
ldapAuthorities[0].getFirstAttributeValue("member"));
// java group
assertTrue(ldapAuthorities[1].getAttributes().containsKey("member"));
assertNotNull(ldapAuthorities[1].getAttributes().get("member"));
assertEquals(3, ldapAuthorities[1].getAttributes().get("member").size());
assertThat(ldapAuthorities[1].getAttributes().containsKey("member")).isTrue();
assertThat(ldapAuthorities[1].getAttributes().get("member")).isNotNull();
assertThat(ldapAuthorities[1].getAttributes().get("member")).hasSize(3);
assertEquals(groovyDevelopers.getDn(),
ldapAuthorities[1].getFirstAttributeValue("member"));
assertEquals(new String[] { groovyDevelopers.getDn(), scalaDevelopers.getDn(),
assertThat(scalaDevelopers.getDn().isEqualTo(new String[] { groovyDevelopers.getDn()),
"uid=javadude,ou=people,dc=springframework,dc=org" }, ldapAuthorities[1]
.getAttributes().get("member"));
// test non existent attribute
assertNull(ldapAuthorities[2].getFirstAttributeValue("test"));
assertNotNull(ldapAuthorities[2].getAttributeValues("test"));
assertEquals(0, ldapAuthorities[2].getAttributeValues("test").size());
assertThat(ldapAuthorities[2].getFirstAttributeValue("test")).isNull();
assertThat(ldapAuthorities[2].getAttributeValues("test")).isNotNull();
assertThat(ldapAuthorities[2].getAttributeValues("test")).isEmpty();
// test role name
assertEquals(jDevelopers.getAuthority(), ldapAuthorities[3].getAuthority());
assertThat(ldapAuthorities[3].getAuthority()).isEqualTo(jDevelopers.getAuthority());
}
}
@@ -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();
}
}