]> source.dussan.org Git - sonarqube.git/commitdiff
Fix tests
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 29 Jul 2019 14:59:16 +0000 (09:59 -0500)
committerSonarTech <sonartech@sonarsource.com>
Wed, 4 Sep 2019 18:21:04 +0000 (20:21 +0200)
15 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/DbScmInfo.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/GeneratedScmInfo.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ReportScmInfo.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfo.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesDiff.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/DbScmInfoTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ReportScmInfoTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryRule.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/ScmLineReaderTest.java

index eef809a7d4d0fe5c59094f54a38e40d87ac4c6db..26bb80346d00184c91b15e99d4e73632b1ea47d0 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.ce.task.projectanalysis.scm;
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.function.Function;
 import javax.annotation.Nonnull;
@@ -42,9 +43,9 @@ class DbScmInfo implements ScmInfo {
     this.fileHash = fileHash;
   }
 
-  public static Optional<DbScmInfo> create(List<DbFileSources.Line> lines, String fileHash) {
+  public static Optional<DbScmInfo> create(List<DbFileSources.Line> lines, int lineCount, String fileHash) {
     LineToChangeset lineToChangeset = new LineToChangeset();
-    Changeset[] lineChanges = new Changeset[lines.size()];
+    Changeset[] lineChanges = new Changeset[lineCount];
 
     boolean lineAdded = false;
 
@@ -91,7 +92,7 @@ class DbScmInfo implements ScmInfo {
    */
   private static class LineToChangeset implements Function<DbFileSources.Line, Changeset> {
     private final Changeset.Builder builder = Changeset.newChangesetBuilder();
-    private final HashMap<Changeset, Changeset> cache = new HashMap<>();
+    private final Map<Changeset, Changeset> cache = new HashMap<>();
 
     @Override
     @Nullable
index 71ed37e721a94e996b2d7b6b852696882ab9d4ba..7d9b4501e26c579c2ee7084431e0ab0fc8ec9a47 100644 (file)
  */
 package org.sonar.ce.task.projectanalysis.scm;
 
-import static com.google.common.base.Preconditions.checkState;
+import javax.annotation.concurrent.Immutable;
 
-public class GeneratedScmInfo implements ScmInfo {
-  private final ScmInfoImpl delegate;
+import static com.google.common.base.Preconditions.checkState;
 
-  public GeneratedScmInfo(Changeset[] lineChangeset) {
-    delegate = new ScmInfoImpl(lineChangeset);
+@Immutable
+public class GeneratedScmInfo {
+  private GeneratedScmInfo() {
+    // static only
   }
 
   public static ScmInfo create(long analysisDate, int lines) {
@@ -38,7 +39,7 @@ public class GeneratedScmInfo implements ScmInfo {
     for (int i = 0; i < lines; i++) {
       lineChangeset[i] = changeset;
     }
-    return new GeneratedScmInfo(lineChangeset);
+    return new ScmInfoImpl(lineChangeset);
   }
 
   public static ScmInfo create(long analysisDate, int[] matches, ScmInfo dbScmInfo) {
@@ -51,32 +52,12 @@ public class GeneratedScmInfo implements ScmInfo {
 
     for (int i = 0; i < matches.length; i++) {
       if (matches[i] > 0) {
-        changesets[i] = dbChangesets[matches[i]];
+        changesets[i] = dbChangesets[matches[i] - 1];
       } else {
         changesets[i] = changeset;
       }
     }
-    return new GeneratedScmInfo(changesets);
-  }
-
-  @Override
-  public Changeset getLatestChangeset() {
-    return delegate.getLatestChangeset();
-  }
-
-  @Override
-  public Changeset getChangesetForLine(int lineNumber) {
-    return delegate.getChangesetForLine(lineNumber);
-  }
-
-  @Override
-  public boolean hasChangesetForLine(int lineNumber) {
-    return delegate.hasChangesetForLine(lineNumber);
-  }
-
-  @Override
-  public Changeset[] getAllChangesets() {
-    return delegate.getAllChangesets();
+    return new ScmInfoImpl(changesets);
   }
 
 }
index 8de0b9c45eb6dbbda7d7f5602f39aa3170373f32..3f3e52b292f12df55b0307e3214e9b535d36c39a 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.ce.task.projectanalysis.scm;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.function.Function;
+import java.util.function.IntFunction;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.scanner.protocol.output.ScannerReport;
 
@@ -33,15 +33,14 @@ import static org.apache.commons.lang.StringUtils.isNotEmpty;
  * ScmInfo implementation based on the changeset information from the Report
  */
 @Immutable
-class ReportScmInfo implements ScmInfo {
-  private final ScmInfo delegate;
+class ReportScmInfo {
 
-  ReportScmInfo(ScannerReport.Changesets changesets) {
-    requireNonNull(changesets);
-    this.delegate = convertToScmInfo(changesets);
+  ReportScmInfo() {
+    // static only
   }
 
-  private static ScmInfo convertToScmInfo(ScannerReport.Changesets changesets) {
+  public static ScmInfo create(ScannerReport.Changesets changesets) {
+    requireNonNull(changesets);
     Changeset[] lineChangesets = new Changeset[changesets.getChangesetIndexByLineCount()];
     LineIndexToChangeset lineIndexToChangeset = new LineIndexToChangeset(changesets);
 
@@ -52,45 +51,25 @@ class ReportScmInfo implements ScmInfo {
     return new ScmInfoImpl(lineChangesets);
   }
 
-  @Override
-  public Changeset getLatestChangeset() {
-    return this.delegate.getLatestChangeset();
-  }
-
-  @Override
-  public Changeset getChangesetForLine(int lineNumber) {
-    return this.delegate.getChangesetForLine(lineNumber);
-  }
-
-  @Override
-  public boolean hasChangesetForLine(int lineNumber) {
-    return delegate.hasChangesetForLine(lineNumber);
-  }
-
-  @Override
-  public Changeset[] getAllChangesets() {
-    return this.delegate.getAllChangesets();
-  }
-
-  private static class LineIndexToChangeset implements Function<Integer, Changeset> {
+  private static class LineIndexToChangeset implements IntFunction<Changeset> {
     private final ScannerReport.Changesets changesets;
     private final Map<Integer, Changeset> changesetCache;
     private final Changeset.Builder builder = Changeset.newChangesetBuilder();
 
-    public LineIndexToChangeset(ScannerReport.Changesets changesets) {
+    private LineIndexToChangeset(ScannerReport.Changesets changesets) {
       this.changesets = changesets;
       this.changesetCache = new HashMap<>(changesets.getChangesetCount());
     }
 
     @Override
-    public Changeset apply(Integer lineNumber) {
+    public Changeset apply(int lineNumber) {
       int changesetIndex = changesets.getChangesetIndexByLine(lineNumber);
       return changesetCache.computeIfAbsent(changesetIndex, idx -> convert(changesets.getChangeset(changesetIndex), lineNumber));
     }
 
     private Changeset convert(ScannerReport.Changesets.Changeset changeset, int line) {
-      checkState(isNotEmpty(changeset.getRevision()), "Changeset on line %s must have a revision", line);
-      checkState(changeset.getDate() != 0, "Changeset on line %s must have a date", line);
+      checkState(isNotEmpty(changeset.getRevision()), "Changeset on line %s must have a revision", line + 1);
+      checkState(changeset.getDate() != 0, "Changeset on line %s must have a date", line + 1);
       return builder
         .setRevision(changeset.getRevision().intern())
         .setAuthor(isNotEmpty(changeset.getAuthor()) ? changeset.getAuthor().intern() : null)
index 6c52c0509e38d0a4e5158b51b18234575d5d7451..720b225481864d1be4ec4b4a98cf41c631c15974 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.ce.task.projectanalysis.scm;
 
-import java.util.Map;
-
 /**
  * Represents changeset information for a file. If SCM information is present, it will be the author, revision and date fetched from SCM
  * for every line. Otherwise, it's a date that corresponds the the analysis date in which the line was modified. 
index 9c8aefa912c38ac52da253dbc62a331487b55b99..fe70bf61a09ccf948a7a5751c086ca4b7583ba0b 100644 (file)
@@ -55,7 +55,7 @@ public class ScmInfoDbLoader {
       if (dto == null) {
         return Optional.empty();
       }
-      return DbScmInfo.create(dto.getSourceData().getLinesList(), dto.getSrcHash());
+      return DbScmInfo.create(dto.getSourceData().getLinesList(), dto.getLineCount(), dto.getSrcHash());
     }
   }
 
index 46416371552645952a01d686a4938dd2d0c10d2a..cb1514699f1c55cb6b9c43d85f162d939c9f01d1 100644 (file)
@@ -21,6 +21,9 @@ package org.sonar.ce.task.projectanalysis.scm;
 
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.api.utils.Preconditions;
 
@@ -37,7 +40,7 @@ public class ScmInfoImpl implements ScmInfo {
   }
 
   private static Changeset computeLatestChangeset(Changeset[] lineChangesets) {
-    return Arrays.stream(lineChangesets).max(Comparator.comparingLong(Changeset::getDate))
+    return Arrays.stream(lineChangesets).filter(Objects::nonNull).max(Comparator.comparingLong(Changeset::getDate))
       .orElseThrow(() -> new IllegalStateException("Expecting at least one Changeset to be present"));
   }
 
@@ -48,6 +51,10 @@ public class ScmInfoImpl implements ScmInfo {
 
   @Override
   public Changeset getChangesetForLine(int lineNumber) {
+    if (lineNumber < 1 || lineNumber > lineChangesets.length) {
+      throw new IllegalArgumentException("There's no changeset on line " + lineNumber);
+
+    }
     Changeset changeset = lineChangesets[lineNumber - 1];
     if (changeset != null) {
       return changeset;
@@ -69,7 +76,7 @@ public class ScmInfoImpl implements ScmInfo {
   public String toString() {
     return "ScmInfoImpl{" +
       "latestChangeset=" + latestChangeset +
-      ", lineChangesets=" + lineChangesets +
-      '}';
+      ", lineChangesets={" + IntStream.range(0, lineChangesets.length).mapToObj(i -> i + 1 + "=" + lineChangesets[i]).collect(Collectors.joining(", "))
+      + "}}";
   }
 }
index 6788e59dd18dba93b95a94a8cff5d57de24056ba..858a0e2f4b8769c4b7e27eb8ce1399f81c599ea7 100644 (file)
@@ -84,7 +84,7 @@ public class ScmInfoRepositoryImpl implements ScmInfoRepository {
 
   private static Optional<ScmInfo> getScmInfoFromReport(Component file, ScannerReport.Changesets changesets) {
     LOGGER.trace("Reading SCM info from report for file '{}'", file.getDbKey());
-    return Optional.of(new ReportScmInfo(changesets));
+    return Optional.of(ReportScmInfo.create(changesets));
   }
 
   private Optional<ScmInfo> generateScmInfoForAllFile(Component file) {
index 6778539414978d4eca76fba66cd4329e9ad0df61..548a81ae0c63426fac0c25c13f0cb75dc1603ae6 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.ce.task.projectanalysis.source;
 
-import org.sonar.ce.task.projectanalysis.component.Component;
 import org.sonar.ce.task.projectanalysis.component.Component;
 
 public interface SourceLinesDiff {
index ba59a2d15a1dac1da72dd8e717347b4e9e599e2f..14dfca2c25576efc98a28b7452d6168d7d2fe8f5 100644 (file)
@@ -33,8 +33,8 @@ public class DbScmInfoTest {
   public ExpectedException thrown = ExpectedException.none();
 
   @Test
-  public void create_scm_info_with_some_changesets() throws Exception {
-    ScmInfo scmInfo = DbScmInfo.create(newFakeData(10).build().getLinesList(), "hash").get();
+  public void create_scm_info_with_some_changesets() {
+    ScmInfo scmInfo = DbScmInfo.create(newFakeData(10).build().getLinesList(), 10, "hash").get();
 
     assertThat(scmInfo.getAllChangesets()).hasSize(10);
   }
@@ -48,7 +48,7 @@ public class DbScmInfoTest {
     addLine(fileDataBuilder, 4, "john", 123456789L, "rev-1");
     fileDataBuilder.build();
 
-    ScmInfo scmInfo = DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get();
+    ScmInfo scmInfo = DbScmInfo.create(fileDataBuilder.getLinesList(), 4, "hash").get();
 
     assertThat(scmInfo.getAllChangesets()).hasSize(4);
 
@@ -59,14 +59,14 @@ public class DbScmInfoTest {
   }
 
   @Test
-  public void return_same_changeset_objects_for_lines_with_same_fields() throws Exception {
+  public void return_same_changeset_objects_for_lines_with_same_fields() {
     DbFileSources.Data.Builder fileDataBuilder = DbFileSources.Data.newBuilder();
     fileDataBuilder.addLinesBuilder().setScmRevision("rev").setScmDate(65L).setLine(1);
     fileDataBuilder.addLinesBuilder().setScmRevision("rev2").setScmDate(6541L).setLine(2);
     fileDataBuilder.addLinesBuilder().setScmRevision("rev1").setScmDate(6541L).setLine(3);
     fileDataBuilder.addLinesBuilder().setScmRevision("rev").setScmDate(65L).setLine(4);
 
-    ScmInfo scmInfo = DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get();
+    ScmInfo scmInfo = DbScmInfo.create(fileDataBuilder.getLinesList(), 4, "hash").get();
 
     assertThat(scmInfo.getAllChangesets()).hasSize(4);
 
@@ -82,7 +82,7 @@ public class DbScmInfoTest {
     addLine(fileDataBuilder, 3, "john", 123456789L, "rev-1");
     fileDataBuilder.build();
 
-    ScmInfo scmInfo = DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get();
+    ScmInfo scmInfo = DbScmInfo.create(fileDataBuilder.getLinesList(), 3, "hash").get();
 
     Changeset latestChangeset = scmInfo.getLatestChangeset();
     assertThat(latestChangeset.getAuthor()).isEqualTo("henry");
@@ -95,40 +95,44 @@ public class DbScmInfoTest {
     DbFileSources.Data.Builder fileDataBuilder = DbFileSources.Data.newBuilder();
     fileDataBuilder.addLinesBuilder().setLine(1);
 
-    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), "hash")).isNotPresent();
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 1, "hash")).isNotPresent();
   }
 
   @Test
-  public void should_support_some_lines_not_having_scm_info() throws Exception {
+  public void should_support_some_lines_not_having_scm_info() {
     DbFileSources.Data.Builder fileDataBuilder = DbFileSources.Data.newBuilder();
     fileDataBuilder.addLinesBuilder().setScmRevision("rev").setScmDate(543L).setLine(1);
     fileDataBuilder.addLinesBuilder().setLine(2);
     fileDataBuilder.build();
 
-    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get().getAllChangesets()).hasSize(1);
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().getAllChangesets()).hasSize(2);
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().hasChangesetForLine(1)).isTrue();
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().hasChangesetForLine(2)).isFalse();
   }
 
   @Test
-  public void filter_out_entries_without_date() throws Exception {
+  public void filter_out_entries_without_date() {
     DbFileSources.Data.Builder fileDataBuilder = DbFileSources.Data.newBuilder();
     fileDataBuilder.addLinesBuilder().setScmRevision("rev").setScmDate(555L).setLine(1);
     fileDataBuilder.addLinesBuilder().setScmRevision("rev-1").setLine(2);
     fileDataBuilder.build();
 
-    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get().getAllChangesets()).hasSize(1);
-    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get().getChangesetForLine(1).getRevision()).isEqualTo("rev");
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().getAllChangesets()).hasSize(2);
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().getChangesetForLine(1).getRevision()).isEqualTo("rev");
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().hasChangesetForLine(2)).isFalse();
+
   }
 
   @Test
-  public void should_support_having_no_author() throws Exception {
+  public void should_support_having_no_author() {
     DbFileSources.Data.Builder fileDataBuilder = DbFileSources.Data.newBuilder();
     // gets filtered out
     fileDataBuilder.addLinesBuilder().setScmAuthor("John").setLine(1);
     fileDataBuilder.addLinesBuilder().setScmRevision("rev").setScmDate(555L).setLine(2);
     fileDataBuilder.build();
 
-    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get().getAllChangesets()).hasSize(1);
-    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), "hash").get().getChangesetForLine(2).getAuthor()).isNull();
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().getAllChangesets()).hasSize(2);
+    assertThat(DbScmInfo.create(fileDataBuilder.getLinesList(), 2, "hash").get().getChangesetForLine(2).getAuthor()).isNull();
   }
 
   private static void addLine(DbFileSources.Data.Builder dataBuilder, Integer line, String author, Long date, String revision) {
index 97a0fbb4d10fa7509f703b0c5c3ce226dd0245eb..1201c580cb1d9bd081d8044f45781e1d8dfb4e48 100644 (file)
@@ -35,7 +35,7 @@ public class ReportScmInfoTest {
 
   @Test
   public void create_scm_info_with_some_changesets() {
-    ScmInfo scmInfo = new ReportScmInfo(ScannerReport.Changesets.newBuilder()
+    ScmInfo scmInfo = ReportScmInfo.create(ScannerReport.Changesets.newBuilder()
       .setComponentRef(FILE_REF)
       .addChangeset(ScannerReport.Changesets.Changeset.newBuilder()
         .setAuthor("john")
@@ -58,7 +58,7 @@ public class ReportScmInfoTest {
 
   @Test
   public void return_changeset_for_a_given_line() {
-    ScmInfo scmInfo = new ReportScmInfo(ScannerReport.Changesets.newBuilder()
+    ScmInfo scmInfo = ReportScmInfo.create(ScannerReport.Changesets.newBuilder()
       .setComponentRef(FILE_REF)
       .addChangeset(ScannerReport.Changesets.Changeset.newBuilder()
         .setAuthor("john")
@@ -86,7 +86,7 @@ public class ReportScmInfoTest {
 
   @Test
   public void return_latest_changeset() {
-    ScmInfo scmInfo = new ReportScmInfo(ScannerReport.Changesets.newBuilder()
+    ScmInfo scmInfo = ReportScmInfo.create(ScannerReport.Changesets.newBuilder()
       .setComponentRef(FILE_REF)
       .addChangeset(ScannerReport.Changesets.Changeset.newBuilder()
         .setAuthor("john")
@@ -114,14 +114,14 @@ public class ReportScmInfoTest {
   public void fail_with_ISE_when_no_changeset() {
     thrown.expect(IllegalStateException.class);
 
-    new ReportScmInfo(ScannerReport.Changesets.newBuilder().build());
+    ReportScmInfo.create(ScannerReport.Changesets.newBuilder().build());
   }
 
   @Test
   public void fail_with_NPE_when_report_is_null() {
     thrown.expect(NullPointerException.class);
 
-    new ReportScmInfo(null);
+    ReportScmInfo.create(null);
   }
 
   @Test
@@ -129,7 +129,7 @@ public class ReportScmInfoTest {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("Changeset on line 1 must have a revision");
 
-    new ReportScmInfo(ScannerReport.Changesets.newBuilder()
+    ReportScmInfo.create(ScannerReport.Changesets.newBuilder()
       .setComponentRef(FILE_REF)
       .addChangeset(ScannerReport.Changesets.Changeset.newBuilder()
         .setAuthor("john")
@@ -144,7 +144,7 @@ public class ReportScmInfoTest {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("Changeset on line 1 must have a date");
 
-    new ReportScmInfo(ScannerReport.Changesets.newBuilder()
+    ReportScmInfo.create(ScannerReport.Changesets.newBuilder()
       .setComponentRef(FILE_REF)
       .addChangeset(ScannerReport.Changesets.Changeset.newBuilder()
         .setAuthor("john")
index 8a47495bbdbd0d97cb7100a9bf3d01dd17ef7b9f..343af48f19e56bbd9b923fd184eced2376b4932c 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.ce.task.projectanalysis.scm;
 
 import com.google.common.collect.ImmutableList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
@@ -142,7 +143,6 @@ public class ScmInfoDbLoaderTest {
     analysisMetadataHolder.setBaseAnalysis(null);
     analysisMetadataHolder.setBranch(branch);
 
-
     assertThat(underTest.getScmInfo(FILE)).isEmpty();
     assertThat(logTester.logs(TRACE)).isEmpty();
   }
@@ -194,6 +194,7 @@ public class ScmInfoDbLoaderTest {
       builder.setScmRevision(revision);
     }
     dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), new FileSourceDto()
+      .setLineHashes(Collections.singletonList("lineHash"))
       .setFileUuid(fileUuid)
       .setProjectUuid("PROJECT_UUID")
       .setSourceData(fileDataBuilder.build())
index f1f9224f826ef56a0d721229ca076cb2fa53ad60..dda8aa92380334b5edf2ed34bdf1a5de3abcad6c 100644 (file)
  */
 package org.sonar.ce.task.projectanalysis.scm;
 
-import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
 
 public class ScmInfoImplTest {
 
@@ -49,7 +46,7 @@ public class ScmInfoImplTest {
   public void get_all_changesets() {
     ScmInfo scmInfo = createScmInfoWithTwoChangestOnFourLines();
 
-    assertThat(scmInfo.getAllChangesets()).containsOnly(entry(1, CHANGESET_1), entry(2, CHANGESET_2), entry(3, CHANGESET_1), entry(4, CHANGESET_1));
+    assertThat(scmInfo.getAllChangesets()).contains(CHANGESET_1, CHANGESET_2, CHANGESET_1, CHANGESET_1);
   }
 
   @Test
@@ -80,9 +77,9 @@ public class ScmInfoImplTest {
   @Test
   public void fail_with_ISE_on_empty_changeset() {
     thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("A ScmInfo must have at least one Changeset and does not support any null one");
+    thrown.expectMessage("ScmInfo cannot be empty");
 
-    new ScmInfoImpl(Collections.emptyMap());
+    new ScmInfoImpl(new Changeset[0]);
   }
 
   @Test
@@ -130,7 +127,6 @@ public class ScmInfoImplTest {
       .setRevision("rev-2")
       .build();
 
-    ScmInfo scmInfo = new ScmInfoImpl(ImmutableMap.of(1, changeset1, 2, changeset2, 3, changeset1, 4, changeset1));
-    return scmInfo;
+    return new ScmInfoImpl(new Changeset[] {changeset1, changeset2, changeset1, changeset1});
   }
 }
index 982f54df579489acd5fa5f63196f863f88020547..6ef335a52e889584ce13fef22854a71814893eb2 100644 (file)
@@ -287,7 +287,7 @@ public class ScmInfoRepositoryImplTest {
       .setScmAuthor("author1")
       .setScmDate(10L)
       .build();
-    DbScmInfo scmInfo = DbScmInfo.create(Collections.singleton(line1), hash).get();
+    DbScmInfo scmInfo = DbScmInfo.create(Collections.singletonList(line1), 1, hash).get();
     when(dbLoader.getScmInfo(FILE)).thenReturn(Optional.of(scmInfo));
     return scmInfo;
   }
index 983dc67e164ac2968b3b92d0f8ae539cf035947c..756c5c25975213d20b7dd46f4d22bb319066a703 100644 (file)
@@ -22,8 +22,6 @@ package org.sonar.ce.task.projectanalysis.scm;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
 import org.junit.rules.ExternalResource;
 import org.sonar.ce.task.projectanalysis.component.Component;
 
@@ -46,13 +44,12 @@ public class ScmInfoRepositoryRule extends ExternalResource implements ScmInfoRe
   }
 
   public ScmInfoRepositoryRule setScmInfo(int fileRef, Changeset... changesetList) {
-    Map<Integer, Changeset> changeset = IntStream.rangeClosed(1, changesetList.length).boxed().collect(Collectors.toMap(x -> x, x -> changesetList[x - 1]));
-    scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changeset));
+    scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changesetList));
     return this;
   }
 
   public ScmInfoRepositoryRule setScmInfo(int fileRef, Map<Integer, Changeset> changesets) {
-    scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changesets));
+    scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changesets.values().stream().toArray(Changeset[]::new)));
     return this;
   }
 }
index ad19a2bea145549390bdf143b070bd5a017b2f0d..244a477c387850b50ba2a502b0622e3a9dc506bb 100644 (file)
@@ -19,9 +19,6 @@
  */
 package org.sonar.ce.task.projectanalysis.source.linereader;
 
-import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
-import java.util.Map;
 import org.junit.Test;
 import org.sonar.ce.task.projectanalysis.scm.Changeset;
 import org.sonar.ce.task.projectanalysis.scm.ScmInfo;
@@ -34,12 +31,12 @@ public class ScmLineReaderTest {
 
   @Test
   public void set_scm() {
-    ScmInfo scmInfo = new ScmInfoImpl(Collections.singletonMap(1,
+    ScmInfo scmInfo = new ScmInfoImpl(new Changeset[] {
       Changeset.newChangesetBuilder()
         .setAuthor("john")
         .setDate(123_456_789L)
         .setRevision("rev-1")
-        .build()));
+        .build()});
 
     ScmLineReader lineScm = new ScmLineReader(scmInfo);
 
@@ -53,10 +50,10 @@ public class ScmLineReaderTest {
 
   @Test
   public void set_scm_with_minim_fields() {
-    ScmInfo scmInfo = new ScmInfoImpl(Collections.singletonMap(1,
+    ScmInfo scmInfo = new ScmInfoImpl(new Changeset[] {
       Changeset.newChangesetBuilder()
         .setDate(123456789L)
-        .build()));
+        .build()});
 
     ScmLineReader lineScm = new ScmLineReader(scmInfo);
 
@@ -102,16 +99,16 @@ public class ScmLineReaderTest {
     readLineAndAssertLatestChanges(lineScm, 8, changeset2, changeset1);
   }
 
-  private static Map<Integer, Changeset> setup8LinesChangeset(Changeset changeset0, Changeset changeset1, Changeset changeset2) {
-    return ImmutableMap.<Integer, Changeset>builder()
-      .put(1, changeset0)
-      .put(2, changeset1)
-      .put(3, changeset1)
-      .put(4, changeset2)
-      .put(5, changeset0)
-      .put(6, changeset1)
-      .put(7, changeset0)
-      .put(8, changeset0).build();
+  private static Changeset[] setup8LinesChangeset(Changeset changeset0, Changeset changeset1, Changeset changeset2) {
+    return new Changeset[] {
+      changeset0,
+      changeset1,
+      changeset1,
+      changeset2,
+      changeset0,
+      changeset1,
+      changeset0,
+      changeset0};
   }
 
   private void readLineAndAssertLatestChanges(ScmLineReader lineScm, int line, Changeset expectedChangeset, Changeset expectedChangesetWithRevision) {