]> source.dussan.org Git - sonarqube.git/commitdiff
Code smell fix: Remove unnecessary parameters
authorBruno Andrade <bruno@artsman.dev>
Tue, 13 Jul 2021 11:38:59 +0000 (08:38 -0300)
committersonartech <sonartech@sonarsource.com>
Thu, 29 Jul 2021 20:04:50 +0000 (20:04 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java
server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java
server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java

index 93fa85f200c8f5aef5f62b6d8455ea1278bfb0f7..3912d1a8026d38d3c584ab60cd23179d56ec8a9a 100644 (file)
@@ -52,7 +52,7 @@ public class BatchMeasureToMeasure {
       case LEVEL:
         return toLevelMeasure(builder, batchMeasure);
       case NO_VALUE:
-        return toNoValueMeasure(builder, batchMeasure);
+        return toNoValueMeasure(builder);
       default:
         throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getType().getValueType());
     }
@@ -60,21 +60,21 @@ public class BatchMeasureToMeasure {
 
   private static Optional<Measure> toIntegerMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
     if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
-      return toNoValueMeasure(builder, batchMeasure);
+      return toNoValueMeasure(builder);
     }
     return of(builder.create(batchMeasure.getIntValue().getValue(), trimToNull(batchMeasure.getIntValue().getData())));
   }
 
   private static Optional<Measure> toLongMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
     if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
-      return toNoValueMeasure(builder, batchMeasure);
+      return toNoValueMeasure(builder);
     }
     return of(builder.create(batchMeasure.getLongValue().getValue(), trimToNull(batchMeasure.getLongValue().getData())));
   }
 
   private static Optional<Measure> toDoubleMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
     if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
-      return toNoValueMeasure(builder, batchMeasure);
+      return toNoValueMeasure(builder);
     }
     return of(builder.create(batchMeasure.getDoubleValue().getValue(),
       // Decimals are not truncated in scanner report, so an arbitrary decimal scale is applied when reading values from report
@@ -83,30 +83,30 @@ public class BatchMeasureToMeasure {
 
   private static Optional<Measure> toBooleanMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
     if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
-      return toNoValueMeasure(builder, batchMeasure);
+      return toNoValueMeasure(builder);
     }
     return of(builder.create(batchMeasure.getBooleanValue().getValue(), trimToNull(batchMeasure.getBooleanValue().getData())));
   }
 
   private static Optional<Measure> toStringMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
     if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
-      return toNoValueMeasure(builder, batchMeasure);
+      return toNoValueMeasure(builder);
     }
     return of(builder.create(batchMeasure.getStringValue().getValue()));
   }
 
   private static Optional<Measure> toLevelMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
     if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
-      return toNoValueMeasure(builder, batchMeasure);
+      return toNoValueMeasure(builder);
     }
     Optional<Measure.Level> level = Measure.Level.toLevel(batchMeasure.getStringValue().getValue());
-    if (!level.isPresent()) {
-      return toNoValueMeasure(builder, batchMeasure);
+    if (level.isEmpty()) {
+      return toNoValueMeasure(builder);
     }
     return of(builder.create(level.get()));
   }
 
-  private static Optional<Measure> toNoValueMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
+  private static Optional<Measure> toNoValueMeasure(Measure.NewMeasureBuilder builder) {
     return of(builder.createNoValue());
   }
 }
index 1189d83c164dffd8851c76b344c181ab728a7625..0f0323031b57d8d7cd706e64d6c1fe00c6bf5132 100644 (file)
@@ -27,8 +27,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.stream.Collectors;
 import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.System2;
-import org.sonar.ce.task.log.CeTaskMessages;
 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
 import org.sonar.ce.task.projectanalysis.component.Component;
 import org.sonar.ce.task.projectanalysis.component.ComponentVisitor;
@@ -51,14 +49,13 @@ import static org.sonar.core.component.ComponentKeys.ALLOWED_CHARACTERS_MESSAGE;
 import static org.sonar.core.component.ComponentKeys.isValidProjectKey;
 
 public class ValidateProjectStep implements ComputationStep {
-
   private static final Joiner MESSAGES_JOINER = Joiner.on("\n  o ");
 
   private final DbClient dbClient;
   private final TreeRootHolder treeRootHolder;
   private final AnalysisMetadataHolder analysisMetadataHolder;
 
-  public ValidateProjectStep(DbClient dbClient, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder, CeTaskMessages taskMessages, System2 system2) {
+  public ValidateProjectStep(DbClient dbClient, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder) {
     this.dbClient = dbClient;
     this.treeRootHolder = treeRootHolder;
     this.analysisMetadataHolder = analysisMetadataHolder;
@@ -151,5 +148,4 @@ public class ValidateProjectStep implements ComputationStep {
       return Optional.of(baseComponent);
     }
   }
-
 }
index ed9087b10eaf19239a3c85a2c7ec4900630a6717..781e3fed82b32756bedb8038d3959cd02af36c42 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Date;
 import javax.annotation.Nullable;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.impl.utils.TestSystem2;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.System2;
@@ -48,10 +47,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 
 public class ValidateProjectStepTest {
-
   static long PAST_ANALYSIS_TIME = 1_420_088_400_000L; // 2015-01-01
   static long DEFAULT_ANALYSIS_TIME = 1_433_131_200_000L; // 2015-06-01
-  static long NOW = 1_500_000_000_000L;
 
   static final String PROJECT_KEY = "PROJECT_KEY";
   static final Branch DEFAULT_BRANCH = new DefaultBranchImpl();
@@ -64,12 +61,11 @@ public class ValidateProjectStepTest {
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
     .setAnalysisDate(new Date(DEFAULT_ANALYSIS_TIME))
     .setBranch(DEFAULT_BRANCH);
-  private final System2 system2 = new TestSystem2().setNow(NOW);
 
   private final CeTaskMessages taskMessages = mock(CeTaskMessages.class);
   private final DbClient dbClient = db.getDbClient();
 
-  private final ValidateProjectStep underTest = new ValidateProjectStep(dbClient, treeRootHolder, analysisMetadataHolder, taskMessages, system2);
+  private final ValidateProjectStep underTest = new ValidateProjectStep(dbClient, treeRootHolder, analysisMetadataHolder);
 
   @Test
   public void dont_fail_for_long_forked_from_master_with_modules() {
index a65daae278a1ed4ff177e01982538148d68d0381..f229dca1beee816161ba3d94c4e6f539ae28729e 100644 (file)
@@ -31,17 +31,14 @@ import org.sonar.api.server.ServerSide;
 @ComputeEngineSide
 @ServerSide
 public class ServerImpl extends Server {
-
   private final Configuration config;
   private final StartupMetadata state;
-  private final ServerFileSystem fs;
   private final UrlSettings urlSettings;
   private final SonarRuntime runtime;
 
-  public ServerImpl(Configuration config, StartupMetadata state, ServerFileSystem fs, UrlSettings urlSettings, SonarRuntime runtime) {
+  public ServerImpl(Configuration config, StartupMetadata state, UrlSettings urlSettings, SonarRuntime runtime) {
     this.config = config;
     this.state = state;
-    this.fs = fs;
     this.urlSettings = urlSettings;
     this.runtime = runtime;
   }
@@ -84,5 +81,4 @@ public class ServerImpl extends Server {
   public boolean isSecured() {
     return urlSettings.isSecured();
   }
-
 }
index 81763f18947c34068ea3ab852b6ba387d5441a09..73c1f1875f6a6323c66690d716e416d0e2293b70 100644 (file)
@@ -45,7 +45,6 @@ import static org.sonar.core.util.stream.MoreCollectors.toList;
 import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
 
 public class UserIndexer implements ResilientIndexer {
-
   private final DbClient dbClient;
   private final EsClient esClient;
 
@@ -93,14 +92,10 @@ public class UserIndexer implements ResilientIndexer {
 
     dbClient.esQueueDao().insert(dbSession, items);
     dbSession.commit();
-    postCommit(dbSession, users.stream().map(UserDto::getLogin).collect(toList()), items);
+    postCommit(dbSession, items);
   }
 
-  /**
-   * Entry point for Byteman tests. See directory tests/resilience.
-   * The parameter "logins" is used only by the Byteman script.
-   */
-  private void postCommit(DbSession dbSession, Collection<String> logins, Collection<EsQueueDto> items) {
+  private void postCommit(DbSession dbSession, Collection<EsQueueDto> items) {
     index(dbSession, items);
   }
 
index 79657e160eae0c16c871b051e29eeef9b033996d..800424d0ea67ebe23cbaf3547084da3819fb49d5 100644 (file)
  */
 package org.sonar.server.platform;
 
-import java.io.File;
-import java.io.IOException;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.config.internal.MapSettings;
@@ -34,16 +30,11 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class ServerImplTest {
-
   private MapSettings settings = new MapSettings();
   private StartupMetadata state = mock(StartupMetadata.class);
-  private ServerFileSystem fs = mock(ServerFileSystem.class);
   private UrlSettings urlSettings = mock(UrlSettings.class);
   private SonarRuntime runtime = mock(SonarRuntime.class);
-  private ServerImpl underTest = new ServerImpl(settings.asConfig(), state, fs, urlSettings, runtime);
-
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
+  private ServerImpl underTest = new ServerImpl(settings.asConfig(), state, urlSettings, runtime);
 
   @Test
   public void test_url_information() {
@@ -56,12 +47,6 @@ public class ServerImplTest {
     assertThat(underTest.isSecured()).isFalse();
   }
 
-  @Test
-  public void test_file_system_information() throws IOException {
-    File home = temp.newFolder();
-    when(fs.getHomeDir()).thenReturn(home);
-  }
-
   @Test
   public void test_startup_information() {
     long time = 123_456_789L;