aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien <100427063+aurelien-poscia-sonarsource@users.noreply.github.com>2022-06-09 17:21:42 +0200
committersonartech <sonartech@sonarsource.com>2022-06-09 20:03:15 +0000
commit02cfe015203237bd8f88906fc880731994707f8a (patch)
tree24bb944762043b2b0687624f8f60a6c3c0890e98
parent6e3634378cb02187cb807a8433bd3f69f401790e (diff)
downloadsonarqube-02cfe015203237bd8f88906fc880731994707f8a.tar.gz
sonarqube-02cfe015203237bd8f88906fc880731994707f8a.zip
NO-JIRA Fix few code smells introduced in 9.5
-rw-r--r--server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java22
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java1
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/plugins/PluginsRiskConsentFilter.java19
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/package-info.java23
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java1
-rw-r--r--sonar-core/src/main/java/org/sonar/core/util/issue/package-info.java24
-rw-r--r--sonar-core/src/main/java/org/sonar/core/util/rule/package-info.java24
10 files changed, 106 insertions, 16 deletions
diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java
index d0290b01220..52f34d47197 100644
--- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java
+++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java
@@ -28,7 +28,6 @@ import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.Assertions.entry;
@RunWith(DataProviderRunner.class)
public class CeTaskTest {
@@ -76,7 +75,10 @@ public class CeTaskTest {
assertThat(task.getSubmitter()).isEqualTo(submitter);
assertThat(task.getComponent()).contains(component);
assertThat(task.getMainComponent()).contains(mainComponent);
- assertThat(task.getCharacteristics()).containsExactly(entry("k1", "v1"), entry("k2", "v2"));
+ assertThat(task.getCharacteristics())
+ .hasSize(2)
+ .containsEntry("k1", "v1")
+ .containsEntry("k2", "v2");
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java
index 6696b22547b..f10fb58419b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java
@@ -22,12 +22,34 @@ package org.sonar.db.rule;
import org.assertj.core.api.Assertions;
import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
public class RuleDescriptionSectionDtoTest {
private static final RuleDescriptionSectionDto SECTION = RuleDescriptionSectionDto.builder()
.key("key")
.uuid("uuid")
.content("desc").build();
+
+ @Test
+ public void setDefault_whenKeyAlreadySet_shouldThrow() {
+ RuleDescriptionSectionDto.RuleDescriptionSectionDtoBuilder builderWithKey = RuleDescriptionSectionDto.builder()
+ .key("tagada");
+ assertThatExceptionOfType(IllegalArgumentException.class)
+ .isThrownBy(builderWithKey::setDefault)
+ .withMessage("Only one of setDefault and key methods can be called");
+ }
+
+ @Test
+ public void setKey_whenDefaultAlreadySet_shouldThrow() {
+ RuleDescriptionSectionDto.RuleDescriptionSectionDtoBuilder builderWithDefault = RuleDescriptionSectionDto.builder()
+ .setDefault();
+ assertThatExceptionOfType(IllegalArgumentException.class)
+ .isThrownBy(() -> builderWithDefault.key("balbal"))
+ .withMessage("Only one of setDefault and key methods can be called");
+ }
+
+
@Test
public void testToString() {
Assertions.assertThat(SECTION).hasToString("RuleDescriptionSectionDto[uuid='uuid', key='key', content='desc']");
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java
index 51ff49a6c2b..d04845aaf78 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java
@@ -26,7 +26,6 @@ import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/plugins/PluginsRiskConsentFilter.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/plugins/PluginsRiskConsentFilter.java
index 022ed65c22f..6119931c738 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/plugins/PluginsRiskConsentFilter.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/plugins/PluginsRiskConsentFilter.java
@@ -19,7 +19,15 @@
*/
package org.sonar.server.plugins;
-import com.google.common.collect.ImmutableSet;
+import java.io.IOException;
+import java.util.Set;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.sonar.api.config.Configuration;
import org.sonar.api.web.ServletFilter;
import org.sonar.core.extension.PluginRiskConsent;
@@ -30,15 +38,6 @@ import static org.sonar.core.config.CorePropertyDefinitions.PLUGINS_RISK_CONSENT
import static org.sonar.core.extension.PluginRiskConsent.NOT_ACCEPTED;
import static org.sonar.core.extension.PluginRiskConsent.REQUIRED;
import static org.sonar.server.authentication.AuthenticationRedirection.redirectTo;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.Set;
public class PluginsRiskConsentFilter extends ServletFilter {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/package-info.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/package-info.java
new file mode 100644
index 00000000000..25dadc5813e
--- /dev/null
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.issue.ws.pull;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java
index 98e0c48bfed..20ee73c8e88 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java
@@ -26,7 +26,6 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.project.ProjectDto;
-import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.qualitygate.QualityGateFinder;
import org.sonar.server.qualitygate.QualityGateFinder.QualityGateData;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
index 163d8074269..c3005e1c79b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
@@ -49,7 +49,6 @@ import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
-import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
index 86bd04823de..658cf49b49f 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.ui.ws;
-import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
diff --git a/sonar-core/src/main/java/org/sonar/core/util/issue/package-info.java b/sonar-core/src/main/java/org/sonar/core/util/issue/package-info.java
new file mode 100644
index 00000000000..cee5abc1c4b
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/util/issue/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.core.util.issue;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-core/src/main/java/org/sonar/core/util/rule/package-info.java b/sonar-core/src/main/java/org/sonar/core/util/rule/package-info.java
new file mode 100644
index 00000000000..679c66c58b7
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/util/rule/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.core.util.rule;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+