]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15574 improving the code quality
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Thu, 4 Nov 2021 09:20:46 +0000 (10:20 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 4 Nov 2021 20:03:25 +0000 (20:03 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpElement.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/MutableDumpReaderImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Protobuf2.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/RuleTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java

index 708fc3746886a5c3a2f421626af485ced866fd0c..8f6e6783215d7ff2d623fb0e00baadeffa0326e6 100644 (file)
@@ -28,7 +28,7 @@ import javax.annotation.concurrent.Immutable;
  * File element in the dump report.
  */
 @Immutable
-public class DumpElement<MSG extends Message> {
+public class DumpElement<M extends Message> {
   public static final long NO_DATETIME = 0;
 
   public static final DumpElement<ProjectDump.Metadata> METADATA = new DumpElement<>("metadata.pb", ProjectDump.Metadata.parser());
@@ -50,9 +50,9 @@ public class DumpElement<MSG extends Message> {
   public static final DumpElement<ProjectDump.NewCodePeriod> NEW_CODE_PERIODS = new DumpElement<>("new_code_periods.pb", ProjectDump.NewCodePeriod.parser());
 
   private final String filename;
-  private final Parser<MSG> parser;
+  private final Parser<M> parser;
 
-  private DumpElement(String filename, Parser<MSG> parser) {
+  private DumpElement(String filename, Parser<M> parser) {
     this.filename = filename;
     this.parser = parser;
   }
@@ -61,14 +61,14 @@ public class DumpElement<MSG extends Message> {
     return filename;
   }
 
-  public Parser<MSG> parser() {
+  public Parser<M> parser() {
     return parser;
   }
 
   public static class IssueDumpElement extends DumpElement<ProjectDump.Issue> {
-    public final int NO_LINE = 0;
-    public final double NO_GAP = -1;
-    public final long NO_EFFORT = -1;
+    public static final int NO_LINE = 0;
+    public static final double NO_GAP = -1;
+    public static final long NO_EFFORT = -1;
 
     public IssueDumpElement() {
       super("issues.pb", ProjectDump.Issue.parser());
index 3905550a96d690b3f732e7cabe7408256be00090..bd24d132063bcc2859b559dddafbcf24bdd77a7d 100644 (file)
@@ -69,7 +69,7 @@ public class DumpWriterImpl implements DumpWriter {
   }
 
   @Override
-  public <MSG extends Message> StreamWriter<MSG> newStreamWriter(DumpElement<MSG> elt) {
+  public <M extends Message> StreamWriter<M> newStreamWriter(DumpElement<M> elt) {
     checkNotPublished();
     File file = new File(rootDir, elt.filename());
     return StreamWriterImpl.create(file);
index 70b74b15f5ebc97d8aa225b254997c401a0048e8..7be3b98bb1674b408f50c2d0621ef99be7d9ad69 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.ce.task.projectexport.steps;
 
-import com.google.common.collect.ImmutableSet;
 import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
 import java.util.List;
 import java.util.Set;
@@ -41,7 +40,7 @@ public class ExportSettingsStep implements ComputationStep {
    * These properties are not exported as values depend on environment data that are not
    * exported within the dump (Quality Gate, users).
    */
-  private static final Set<String> IGNORED_KEYS = ImmutableSet.of("sonar.issues.defaultAssigneeLogin");
+  private static final Set<String> IGNORED_KEYS = Set.of("sonar.issues.defaultAssigneeLogin");
 
   private final DbClient dbClient;
   private final ProjectHolder projectHolder;
index e6ef3605f429612ce89defce36e8bffa60d8beb1..b9dc5b9929ce18efac2bb2788d9a78e3caea0ac3 100644 (file)
@@ -78,7 +78,7 @@ public class MutableDumpReaderImpl implements MutableDumpReader {
   }
 
   @Override
-  public <MSG extends Message> MessageStream<MSG> stream(DumpElement<MSG> elt) {
+  public <M extends Message> MessageStream<M> stream(DumpElement<M> elt) {
     File file = new File(tempRootDir(), elt.filename());
     checkState(file.exists(), "Missing file: %s", file);
 
index ec1ef74aa24f47bcb35f6bb369c2f9c42b36dd94..86c8d76d39b983acf1ebec77d3a8aabfdfae3e71 100644 (file)
@@ -52,7 +52,7 @@ public class Protobuf2 {
     return this;
   }
 
-  public <MSG extends Message> MSG parseFrom(Parser<MSG> parser, InputStream input) {
+  public <M extends Message> M parseFrom(Parser<M> parser, InputStream input) {
     try {
       return parser.parseFrom(input);
     } catch (InvalidProtocolBufferException e) {
@@ -61,7 +61,7 @@ public class Protobuf2 {
   }
 
   @CheckForNull
-  public <MSG extends Message> MSG parseDelimitedFrom(Parser<MSG> parser, InputStream input) {
+  public <M extends Message> M parseDelimitedFrom(Parser<M> parser, InputStream input) {
     try {
       return parser.parseDelimitedFrom(input);
     } catch (InvalidProtocolBufferException e) {
index 7a0bade945f036d7b005baa919beba7bd860f163..c24cd2c7a1043021126676787be857187ddd9adf 100644 (file)
@@ -168,9 +168,4 @@ public class ExportComponentsStepTest {
     assertThat(underTest.getDescription()).isEqualTo("Export components");
   }
 
-  @Test
-  public void name() {
-    System.err.println(new Date(1313272860000L));
-
-  }
 }
index 4a1705280b694ad711812b27ea484ac9b9c5b304..2db984504da711514df8d93374fa25c7b1e6a7b5 100644 (file)
@@ -197,7 +197,7 @@ public class ExportIssuesChangelogStepTest {
     underTest.execute(new TestComputationStepContext());
 
     ProjectDump.IssueChange issueChange = getSingleMessage();
-    assertThat(issueChange.getCreatedAt()).isEqualTo(0L);
+    assertThat(issueChange.getCreatedAt()).isZero();
   }
 
   @Test
index f33cff5dcc64c6fd4e64d41d412b6cda782a4a40..28cab509a77e2179f0746640af9a74de4649bbd1 100644 (file)
@@ -64,7 +64,7 @@ public class RuleTest {
 
   @Test
   public void hashcode_is_based_on_repository_and_key() {
-    assertThat(underTest.hashCode()).isEqualTo(new Rule(SOME_DUMP_UUID, SOME_REPOSITORY, SOME_KEY).hashCode());
+    assertThat(underTest).hasSameHashCodeAs(new Rule(SOME_DUMP_UUID, SOME_REPOSITORY, SOME_KEY));
     assertThat(underTest.hashCode()).isNotEqualTo(new Rule(SOME_DUMP_UUID, SOME_KEY, SOME_REPOSITORY).hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(new Rule(SOME_DUMP_UUID, "other repository", SOME_KEY).hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(new Rule(SOME_DUMP_UUID, SOME_REPOSITORY, "other key").hashCode());
@@ -72,12 +72,12 @@ public class RuleTest {
 
   @Test
   public void hashcode_ignores_dump_id() {
-    assertThat(underTest.hashCode()).isEqualTo(new Rule("uuid-8888", SOME_REPOSITORY, SOME_KEY).hashCode());
+    assertThat(underTest).hasSameHashCodeAs(new Rule("uuid-8888", SOME_REPOSITORY, SOME_KEY));
   }
 
   @Test
   public void toString_displays_all_fields() {
-    assertThat(underTest.toString()).isEqualTo("Rule{ref='uuid-12334', repository='some repository', key='some key'}");
+    assertThat(underTest).hasToString("Rule{ref='uuid-12334', repository='some repository', key='some key'}");
 
   }
 }
index b46e772ee776a38ca35d5d38db0a8fea482bf7ed..0ed2e499887cc042086fe9a4452e117c4f8ea429 100644 (file)
@@ -89,7 +89,7 @@ public class ExportLiveMeasuresStepTest {
       .extracting(ProjectDump.LiveMeasure::getMetricRef, m -> m.getDoubleValue().getValue(), ProjectDump.LiveMeasure::hasVariation)
       .containsOnly(tuple(0, 4711.0d, false));
     assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
-    assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(metric.getUuid());
+    assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
   }
 
   @Test
@@ -161,7 +161,7 @@ public class ExportLiveMeasuresStepTest {
         "test",
         7.0d));
     assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
-    assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(metric.getUuid());
+    assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
   }
 
   @Test
@@ -191,7 +191,7 @@ public class ExportLiveMeasuresStepTest {
         "",
         false));
     assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
-    assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(metric.getUuid());
+    assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
   }
 
   @Test
index 698d1a5be02e0d9f207b1d49797157f52757dac8..251bbc97183f6cc93c7a8bf8712f4b201a63e31c 100644 (file)
@@ -142,7 +142,7 @@ public class ExportMeasuresStepTest {
     assertThat(exportedMeasures).extracting(ProjectDump.Measure::getAnalysisUuid).containsOnly(firstAnalysis.getUuid(), secondAnalysis.getUuid());
     assertThat(exportedMeasures).extracting(ProjectDump.Measure::getMetricRef).containsOnly(0);
     assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 measures exported");
-    assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(NCLOC.getUuid());
+    assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(NCLOC.getUuid());
   }
 
   @Test