]> source.dussan.org Git - sonarqube.git/commitdiff
NO-JIRA Fix few code smells introduced in 9.5
authorAurelien <100427063+aurelien-poscia-sonarsource@users.noreply.github.com>
Thu, 9 Jun 2022 15:21:42 +0000 (17:21 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 9 Jun 2022 20:03:15 +0000 (20:03 +0000)
server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDescriptionSectionDtoTest.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java
server/sonar-webserver-core/src/main/java/org/sonar/server/plugins/PluginsRiskConsentFilter.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/package-info.java [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
sonar-core/src/main/java/org/sonar/core/util/issue/package-info.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/util/rule/package-info.java [new file with mode: 0644]

index d0290b012207904bf3246a7062d9ca634a82595c..52f34d471978cf4ef56e624dba65aa970670602f 100644 (file)
@@ -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
index 6696b22547b2200163f2a0633f8e9d09c1006692..f10fb58419bb2a09e5dacea3e287f214b308bec0 100644 (file)
@@ -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']");
index 51ff49a6c2b6adead8e89446837154ff1cb0b9a5..d04845aaf7826b3ad95c67f18cd480adc3ed8391 100644 (file)
@@ -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;
index 022ed65c22fbcdeae94fecde8e58d3076d324b43..6119931c7385099e759fb44e0627f3b470c7d7e3 100644 (file)
  */
 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 (file)
index 0000000..25dadc5
--- /dev/null
@@ -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;
index 98e0c48bfed533abf633c49e63af3acbc2b9752e..20ee73c8e8870555fe15004516f33b5720ec1499 100644 (file)
@@ -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;
index 163d8074269ce474de9fe5251330afde1c08548a..c3005e1c79b59b659467a43209817193f4b2a0a3 100644 (file)
@@ -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;
index 86bd04823de886948a44ef115f807dd8987ec6a4..658cf49b49f1a2d393981420517af3b5557085d5 100644 (file)
@@ -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 (file)
index 0000000..cee5abc
--- /dev/null
@@ -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 (file)
index 0000000..679c66c
--- /dev/null
@@ -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;
+