refactor: AssertJ best practices
Use this link to re-run the recipe: https://app.moderne.io/recipes/builder/bGVuS?organizationId=RGVmYXVsdA%3D%3D Co-authored-by: Moderne <team@moderne.io>
This commit is contained in:
committed by
Josh Cummings
parent
36a488a360
commit
9df9cb5aed
+4
-4
@@ -104,9 +104,9 @@ public class SpringSecurityLdapTemplateITests {
|
||||
new String[] { param }, "ou");
|
||||
|
||||
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();
|
||||
assertThat(values).contains("developer");
|
||||
assertThat(values).contains("manager");
|
||||
assertThat(values).contains("submanager");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,7 +149,7 @@ public class SpringSecurityLdapTemplateITests {
|
||||
}
|
||||
|
||||
protected void assertAttributeValue(Map<String, List<String>> record, String attributeName, String... values) {
|
||||
assertThat(record.containsKey(attributeName)).isTrue();
|
||||
assertThat(record).containsKey(attributeName);
|
||||
assertThat(record.get(attributeName)).hasSize(values.length);
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
assertThat(record.get(attributeName).get(i)).isEqualTo(values[i]);
|
||||
|
||||
+2
-2
@@ -72,8 +72,8 @@ public class DefaultLdapAuthoritiesPopulatorGetGrantedAuthoritiesTests {
|
||||
|
||||
assertThat(authorities).as("Should have 1 role").hasSize(2);
|
||||
|
||||
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_")).isTrue();
|
||||
assertThat(authorities).contains("ROLE_DEVELOPER");
|
||||
assertThat(authorities).contains("ROLE_");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
+12
-12
@@ -68,7 +68,7 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
|
||||
Collection<GrantedAuthority> authorities = this.populator.getGrantedAuthorities(ctx, "notfound");
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities)).contains("ROLE_USER");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +79,7 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
Collection<GrantedAuthority> authorities = this.populator
|
||||
.getGrantedAuthorities(new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities)).contains("ROLE_USER");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,8 +98,8 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
|
||||
assertThat(authorities).as("Should have 2 roles").hasSize(2);
|
||||
|
||||
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
assertThat(authorities).contains("ROLE_DEVELOPER");
|
||||
assertThat(authorities).contains("ROLE_MANAGER");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,7 +115,7 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
.authorityListToSet(this.populator.getGrantedAuthorities(ctx, "manager"));
|
||||
|
||||
assertThat(authorities).as("Should have 1 role").hasSize(1);
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
assertThat(authorities).contains("ROLE_MANAGER");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,8 +130,8 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
.authorityListToSet(this.populator.getGrantedAuthorities(ctx, "manager"));
|
||||
|
||||
assertThat(authorities).as("Should have 2 roles").hasSize(2);
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
|
||||
assertThat(authorities).contains("ROLE_MANAGER");
|
||||
assertThat(authorities).contains("ROLE_DEVELOPER");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,9 +147,9 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
.authorityListToSet(this.populator.getGrantedAuthorities(ctx, "manager"));
|
||||
|
||||
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();
|
||||
assertThat(authorities).contains("ROLE_MANAGER");
|
||||
assertThat(authorities).contains("ROLE_SUBMANAGER");
|
||||
assertThat(authorities).contains("ROLE_DEVELOPER");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,7 +164,7 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
Collection<GrantedAuthority> authorities = this.populator
|
||||
.getGrantedAuthorities(new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_EXTRA")).isTrue();
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities)).contains("ROLE_EXTRA");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,7 +180,7 @@ public class DefaultLdapAuthoritiesPopulatorTests {
|
||||
.authorityListToSet(this.populator.getGrantedAuthorities(ctx, "notused"));
|
||||
|
||||
assertThat(authorities).as("Should have 1 role").hasSize(1);
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
assertThat(authorities).contains("ROLE_MANAGER");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -128,14 +128,14 @@ public class NestedLdapAuthoritiesPopulatorTests {
|
||||
LdapAuthority[] ldapAuthorities = authorities.toArray(new LdapAuthority[0]);
|
||||
assertThat(ldapAuthorities).hasSize(5);
|
||||
// groovy-developers group
|
||||
assertThat(ldapAuthorities[0].getAttributes().containsKey("member")).isTrue();
|
||||
assertThat(ldapAuthorities[0].getAttributes()).containsKey("member");
|
||||
assertThat(ldapAuthorities[0].getAttributes().get("member")).isNotNull();
|
||||
assertThat(ldapAuthorities[0].getAttributes().get("member")).hasSize(3);
|
||||
assertThat(ldapAuthorities[0].getFirstAttributeValue("member"))
|
||||
.isEqualTo("cn=groovy-developers,ou=jdeveloper,dc=springframework,dc=org");
|
||||
|
||||
// java group
|
||||
assertThat(ldapAuthorities[1].getAttributes().containsKey("member")).isTrue();
|
||||
assertThat(ldapAuthorities[1].getAttributes()).containsKey("member");
|
||||
assertThat(ldapAuthorities[1].getAttributes().get("member")).isNotNull();
|
||||
assertThat(ldapAuthorities[1].getAttributes().get("member")).hasSize(3);
|
||||
assertThat(this.groovyDevelopers.getDn()).isEqualTo(ldapAuthorities[1].getFirstAttributeValue("member"));
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class InetOrgPersonTests {
|
||||
InetOrgPerson p2 = (InetOrgPerson) essence.createUserDetails();
|
||||
Set<InetOrgPerson> set = new HashSet<>();
|
||||
set.add(p);
|
||||
assertThat(set.contains(p2)).isTrue();
|
||||
assertThat(set).contains(p2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class LdapUserDetailsServiceTests {
|
||||
UserDetails user = service.loadUserByUsername("doesntmatterwegetjoeanyway");
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(user.getAuthorities());
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(authorities.contains("ROLE_FROM_POPULATOR")).isTrue();
|
||||
assertThat(authorities).contains("ROLE_FROM_POPULATOR");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public class UserDetailsServiceLdapAuthoritiesPopulatorTests {
|
||||
UserDetailsServiceLdapAuthoritiesPopulator populator = new UserDetailsServiceLdapAuthoritiesPopulator(uds);
|
||||
Collection<? extends GrantedAuthority> auths = populator.getGrantedAuthorities(new DirContextAdapter(), "joe");
|
||||
assertThat(auths).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(auths).contains("ROLE_USER")).isTrue();
|
||||
assertThat(AuthorityUtils.authorityListToSet(auths)).contains("ROLE_USER");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user