aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-core/src
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-db-core/src
parentaa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff)
downloadsonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz
sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip
Improve code quality
Diffstat (limited to 'server/sonar-db-core/src')
-rw-r--r--server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java6
-rw-r--r--server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java8
-rw-r--r--server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java4
-rw-r--r--server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java4
-rw-r--r--server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java2
-rw-r--r--server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java2
-rw-r--r--server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java2
-rw-r--r--server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java8
8 files changed, 14 insertions, 22 deletions
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
index 4a74e8771a3..0c70bb0b0c1 100644
--- a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
+++ b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
@@ -19,7 +19,6 @@
*/
package org.sonar.db;
-import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -42,9 +41,9 @@ import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.IntSupplier;
-import java.util.function.Supplier;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@@ -54,7 +53,6 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.collect.Lists.newArrayList;
import static java.lang.String.format;
public class DatabaseUtils {
@@ -216,7 +214,7 @@ public class DatabaseUtils {
return;
}
- List<List<T>> partitions = Lists.partition(newArrayList(input), PARTITION_SIZE_FOR_ORACLE);
+ List<List<T>> partitions = Lists.partition(new ArrayList<>(input), PARTITION_SIZE_FOR_ORACLE);
for (List<T> partition : partitions) {
consumer.accept(partition);
}
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
index 33e58ca8716..ce341c7f897 100644
--- a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
+++ b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
@@ -19,12 +19,8 @@
*/
package org.sonar.db.version;
-import java.util.HashSet;
import java.util.Set;
-import static java.util.Arrays.asList;
-import static java.util.Collections.unmodifiableSet;
-
public final class SqTables {
/**
@@ -32,7 +28,7 @@ public final class SqTables {
* This list is hardcoded because we didn't succeed in using java.sql.DatabaseMetaData#getTables() in the same way
* for all the supported databases, particularly due to Oracle results.
*/
- public static final Set<String> TABLES = unmodifiableSet(new HashSet<>(asList(
+ public static final Set<String> TABLES = Set.of(
"active_rules",
"active_rule_parameters",
"alm_settings",
@@ -107,7 +103,7 @@ public final class SqTables {
"user_roles",
"user_tokens",
"webhooks",
- "webhook_deliveries")));
+ "webhook_deliveries");
private SqTables() {
// prevents instantiation
diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java
index 118518ab2e7..ba1515ff724 100644
--- a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java
+++ b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java
@@ -462,9 +462,7 @@ public class DatabaseUtilsTest {
@Test
public void executeLargeUpdates_on_empty_list() {
- DatabaseUtils.executeLargeUpdates(Collections.<Integer>emptyList(), input -> {
- fail("No partition should be made on empty list");
- });
+ DatabaseUtils.executeLargeUpdates(Collections.<Integer>emptyList(), input -> fail("No partition should be made on empty list"));
}
@Test
diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java
index e19b90ce649..da572c8b059 100644
--- a/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java
+++ b/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java
@@ -50,7 +50,7 @@ public class DefaultDatabaseTest {
Properties props = db.getProperties();
assertThat(props.getProperty("sonar.jdbc.url")).isEqualTo("jdbc:h2:tcp://localhost/sonar");
assertThat(props.getProperty("sonar.jdbc.driverClassName")).isEqualTo("org.h2.Driver");
- assertThat(db.toString()).isEqualTo("Database[jdbc:h2:tcp://localhost/sonar]");
+ assertThat(db).hasToString("Database[jdbc:h2:tcp://localhost/sonar]");
}
@Test
@@ -124,7 +124,7 @@ public class DefaultDatabaseTest {
db.stop();
assertThat(db.getDialect().getId()).isEqualTo("h2");
- assertThat(((BasicDataSource) db.getDataSource()).getMaxTotal()).isEqualTo(1);
+ assertThat(((BasicDataSource) db.getDataSource()).getMaxTotal()).isOne();
}
@Test
diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java
index 7949ede9e48..558a8dd4e44 100644
--- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java
+++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java
@@ -66,7 +66,7 @@ public class H2Test {
@Test
public void getSqlFromDual() {
- assertThat(underTest.getSqlFromDual()).isEqualTo("");
+ assertThat(underTest.getSqlFromDual()).isEmpty();
}
@Test
diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java
index b07dfd64c8e..f9bf6a4f070 100644
--- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java
+++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java
@@ -68,7 +68,7 @@ public class MsSqlTest {
@Test
public void getSqlFromDual() {
- assertThat(underTest.getSqlFromDual()).isEqualTo("");
+ assertThat(underTest.getSqlFromDual()).isEmpty();
}
@Test
diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java
index cc76081db42..2b40b91cc57 100644
--- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java
+++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java
@@ -76,7 +76,7 @@ public class PostgreSqlTest {
@Test
public void getSqlFromDual() {
- assertThat(underTest.getSqlFromDual()).isEqualTo("");
+ assertThat(underTest.getSqlFromDual()).isEmpty();
}
@Test
diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java
index 8866d1d3944..93d265dedaa 100644
--- a/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java
+++ b/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java
@@ -28,7 +28,7 @@ public class SqlLogFormatterTest {
@Test
public void reformatSql() {
- assertThat(SqlLogFormatter.reformatSql("")).isEqualTo("");
+ assertThat(SqlLogFormatter.reformatSql("")).isEmpty();
assertThat(SqlLogFormatter.reformatSql("select *")).isEqualTo("select *");
assertThat(SqlLogFormatter.reformatSql("select *\nfrom issues")).isEqualTo("select * from issues");
assertThat(SqlLogFormatter.reformatSql("select *\n from issues")).isEqualTo("select * from issues");
@@ -40,7 +40,7 @@ public class SqlLogFormatterTest {
@Test
public void reformatParam() {
assertThat(SqlLogFormatter.reformatParam(null)).isEqualTo("[null]");
- assertThat(SqlLogFormatter.reformatParam("")).isEqualTo("");
+ assertThat(SqlLogFormatter.reformatParam("")).isEmpty();
assertThat(SqlLogFormatter.reformatParam("foo")).isEqualTo("foo");
assertThat(SqlLogFormatter.reformatParam("foo bar ")).isEqualTo("foo bar ");
}
@@ -69,13 +69,13 @@ public class SqlLogFormatterTest {
@Test
public void reformatParams_returns_blank_if_zero_params() {
String formattedParams = SqlLogFormatter.reformatParams(new Object[0]);
- assertThat(formattedParams).isEqualTo("");
+ assertThat(formattedParams).isEmpty();
}
@Test
public void countArguments() {
assertThat(SqlLogFormatter.countArguments("select * from issues")).isZero();
- assertThat(SqlLogFormatter.countArguments("select * from issues where id=?")).isEqualTo(1);
+ assertThat(SqlLogFormatter.countArguments("select * from issues where id=?")).isOne();
assertThat(SqlLogFormatter.countArguments("select * from issues where id=? and kee=?")).isEqualTo(2);
}
}