aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-auth-ldap/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-11-18 16:45:02 -0600
committersonartech <sonartech@sonarsource.com>2021-11-20 20:03:51 +0000
commit3f9445c25962f914ccdd889c002ddd8e19b0cf89 (patch)
treeeb4f34a62b7164a71fd0bbe34d6f59621a687d8d /server/sonar-auth-ldap/src/test
parentaa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff)
downloadsonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz
sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip
Improve code quality
Diffstat (limited to 'server/sonar-auth-ldap/src/test')
-rw-r--r--server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java9
-rw-r--r--server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java16
-rw-r--r--server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java4
-rw-r--r--server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java2
4 files changed, 16 insertions, 15 deletions
diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java
index 367f0759a8b..367859b3c3a 100644
--- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java
+++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java
@@ -59,9 +59,10 @@ public class LdapSearchTest {
assertThat(search.toString()).isEqualTo("LdapSearch{baseDn=dc=example,dc=org, scope=subtree, request=(objectClass={0}), parameters=[inetOrgPerson], attributes=[objectClass]}");
assertThat(enumerationToArrayList(search.find()).size()).isEqualTo(3);
- assertThatThrownBy(() -> search.findUnique())
+ assertThatThrownBy(search::findUnique)
.isInstanceOf(NamingException.class)
.hasMessage("Non unique result for " + search.toString());
+
}
@Test
@@ -78,7 +79,7 @@ public class LdapSearchTest {
assertThat(search.getRequest()).isEqualTo("(objectClass={0})");
assertThat(search.getParameters()).isEqualTo(new String[] {"inetOrgPerson"});
assertThat(search.getReturningAttributes()).isEqualTo(new String[] {"cn"});
- assertThat(search.toString()).isEqualTo("LdapSearch{baseDn=dc=example,dc=org, scope=onelevel, request=(objectClass={0}), parameters=[inetOrgPerson], attributes=[cn]}");
+ assertThat(search).hasToString("LdapSearch{baseDn=dc=example,dc=org, scope=onelevel, request=(objectClass={0}), parameters=[inetOrgPerson], attributes=[cn]}");
assertThat(enumerationToArrayList(search.find()).size()).isZero();
assertThat(search.findUnique()).isNull();
}
@@ -97,9 +98,9 @@ public class LdapSearchTest {
assertThat(search.getRequest()).isEqualTo("(objectClass={0})");
assertThat(search.getParameters()).isEqualTo(new String[] {"uidObject"});
assertThat(search.getReturningAttributes()).isEqualTo(new String[] {"uid"});
- assertThat(search.toString()).isEqualTo(
+ assertThat(search).hasToString(
"LdapSearch{baseDn=cn=bind,ou=users,dc=example,dc=org, scope=object, request=(objectClass={0}), parameters=[uidObject], attributes=[uid]}");
- assertThat(enumerationToArrayList(search.find()).size()).isEqualTo(1);
+ assertThat(enumerationToArrayList(search.find())).hasSize(1);
assertThat(search.findUnique()).isNotNull();
}
diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java
index 446b09b3462..8dfb35e893a 100644
--- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java
+++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java
@@ -57,7 +57,7 @@ public class LdapSettingsManagerTest {
public void testContextFactoriesWithSingleLdap() {
LdapSettingsManager settingsManager = new LdapSettingsManager(
generateSingleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery());
- assertThat(settingsManager.getContextFactories().size()).isEqualTo(1);
+ assertThat(settingsManager.getContextFactories()).hasSize(1);
}
/**
@@ -68,9 +68,9 @@ public class LdapSettingsManagerTest {
public void testContextFactoriesWithMultipleLdap() {
LdapSettingsManager settingsManager = new LdapSettingsManager(
generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery());
- assertThat(settingsManager.getContextFactories().size()).isEqualTo(2);
+ assertThat(settingsManager.getContextFactories()).hasSize(2);
// We do it twice to make sure the settings keep the same.
- assertThat(settingsManager.getContextFactories().size()).isEqualTo(2);
+ assertThat(settingsManager.getContextFactories()).hasSize(2);
}
@Test
@@ -81,7 +81,7 @@ public class LdapSettingsManagerTest {
when(ldapAutodiscovery.getLdapServers("example.org")).thenReturn(Arrays.asList(ldap1, ldap2));
LdapSettingsManager settingsManager = new LdapSettingsManager(
generateAutodiscoverSettings().asConfig(), ldapAutodiscovery);
- assertThat(settingsManager.getContextFactories().size()).isEqualTo(2);
+ assertThat(settingsManager.getContextFactories()).hasSize(2);
}
@Test
@@ -104,9 +104,9 @@ public class LdapSettingsManagerTest {
public void testUserMappings() {
LdapSettingsManager settingsManager = new LdapSettingsManager(
generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery());
- assertThat(settingsManager.getUserMappings().size()).isEqualTo(2);
+ assertThat(settingsManager.getUserMappings()).hasSize(2);
// We do it twice to make sure the settings keep the same.
- assertThat(settingsManager.getUserMappings().size()).isEqualTo(2);
+ assertThat(settingsManager.getUserMappings()).hasSize(2);
}
/**
@@ -117,9 +117,9 @@ public class LdapSettingsManagerTest {
public void testGroupMappings() {
LdapSettingsManager settingsManager = new LdapSettingsManager(
generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery());
- assertThat(settingsManager.getGroupMappings().size()).isEqualTo(2);
+ assertThat(settingsManager.getGroupMappings()).hasSize(2);
// We do it twice to make sure the settings keep the same.
- assertThat(settingsManager.getGroupMappings().size()).isEqualTo(2);
+ assertThat(settingsManager.getGroupMappings()).hasSize(2);
}
/**
diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java
index c74f3746b0c..26d8df97e54 100644
--- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java
+++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java
@@ -34,7 +34,7 @@ public class LdapUserMappingTest {
assertThat(userMapping.getRealNameAttribute()).isEqualTo("cn");
assertThat(userMapping.getEmailAttribute()).isEqualTo("mail");
- assertThat(userMapping.toString()).isEqualTo("LdapUserMapping{" +
+ assertThat(userMapping).hasToString("LdapUserMapping{" +
"baseDn=null," +
" request=(&(objectClass=inetOrgPerson)(uid={0}))," +
" realNameAttribute=cn," +
@@ -54,7 +54,7 @@ public class LdapUserMappingTest {
assertThat(search.getParameters()).isEqualTo(new String[] {"tester"});
assertThat(search.getReturningAttributes()).isNull();
- assertThat(userMapping.toString()).isEqualTo("LdapUserMapping{" +
+ assertThat(userMapping).hasToString("LdapUserMapping{" +
"baseDn=cn=users," +
" request=(&(objectClass=user)(sAMAccountName={0}))," +
" realNameAttribute=cn," +
diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java
index 5e99c223187..e82a602f05b 100644
--- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java
+++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java
@@ -60,7 +60,7 @@ public class LdapUsersProviderTest {
details = usersProvider.getUserDetails("without_email");
assertThat(details.getName()).isEqualTo("Without Email");
- assertThat(details.getEmail()).isEqualTo("");
+ assertThat(details.getEmail()).isEmpty();
details = usersProvider.getUserDetails("notfound");
assertThat(details).isNull();