]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6993 Add readComponentDuplicationBlocks in ce BatchReportReader
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 4 Nov 2015 16:09:48 +0000 (17:09 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Nov 2015 10:01:28 +0000 (11:01 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReader.java
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java
server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderRule.java

index a7455e6bda11751b5eb92838fa559b0d7c8da644..9fd55110cc3194da63b6387e2189413cef144796 100644 (file)
@@ -42,6 +42,8 @@ public interface BatchReportReader {
 
   CloseableIterator<BatchReport.Duplication> readComponentDuplications(int componentRef);
 
+  CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef);
+
   CloseableIterator<BatchReport.Symbol> readComponentSymbols(int componentRef);
 
   CloseableIterator<BatchReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef);
index 5b1ab44e92fc7a59ab6b7ffc2846dad0e37bf807..392f69d39b2837b70308b9929f443463ed27ca7c 100644 (file)
@@ -99,6 +99,11 @@ public class BatchReportReaderImpl implements BatchReportReader {
     return delegate.readComponentDuplications(componentRef);
   }
 
+  @Override
+  public CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef) {
+    return delegate.readComponentDuplicationBlocks(componentRef);
+  }
+
   @Override
   public CloseableIterator<BatchReport.Symbol> readComponentSymbols(int componentRef) {
     return delegate.readComponentSymbols(componentRef);
index d2fd81b9a4b1d12c7fff5c578905e704ff2d03cd..f561215ed1b5a48dfb8cdb384bb348acdf3f3ca6 100644 (file)
@@ -41,6 +41,7 @@ public class BatchReportReaderImplTest {
   private static final BatchReport.Component COMPONENT = BatchReport.Component.newBuilder().setRef(COMPONENT_REF).build();
   private static final BatchReport.Issue ISSUE = BatchReport.Issue.newBuilder().build();
   private static final BatchReport.Duplication DUPLICATION = BatchReport.Duplication.newBuilder().build();
+  private static final BatchReport.DuplicationBlock DUPLICATION_BLOCK = BatchReport.DuplicationBlock.newBuilder().build();
   private static final BatchReport.Symbol SYMBOL = BatchReport.Symbol.newBuilder().build();
   private static final BatchReport.SyntaxHighlighting SYNTAX_HIGHLIGHTING_1 = BatchReport.SyntaxHighlighting.newBuilder().build();
   private static final BatchReport.SyntaxHighlighting SYNTAX_HIGHLIGHTING_2 = BatchReport.SyntaxHighlighting.newBuilder().build();
@@ -200,6 +201,28 @@ public class BatchReportReaderImplTest {
     assertThat(underTest.readComponentDuplications(COMPONENT_REF)).isNotSameAs(underTest.readComponentDuplications(COMPONENT_REF));
   }
 
+  @Test
+  public void readComponentDuplicationBlocks_returns_empty_list_if_file_does_not_exist() {
+    assertThat(underTest.readComponentDuplicationBlocks(COMPONENT_REF)).isEmpty();
+  }
+
+  @Test
+  public void verify_readComponentDuplicationBlocks_returns_Issues() {
+    writer.writeDuplicationBlocks(COMPONENT_REF, of(DUPLICATION_BLOCK));
+
+    try (CloseableIterator<BatchReport.DuplicationBlock> res = underTest.readComponentDuplicationBlocks(COMPONENT_REF)) {
+      assertThat(res.next()).isEqualTo(DUPLICATION_BLOCK);
+      assertThat(res.hasNext()).isFalse();
+    }
+  }
+
+  @Test
+  public void readComponentDuplicationBlocks_is_not_cached() {
+    writer.writeDuplicationBlocks(COMPONENT_REF, of(DUPLICATION_BLOCK));
+
+    assertThat(underTest.readComponentDuplicationBlocks(COMPONENT_REF)).isNotSameAs(underTest.readComponentDuplicationBlocks(COMPONENT_REF));
+  }
+
   @Test
   public void readComponentSymbols_returns_empty_list_if_file_does_not_exist() {
     assertThat(underTest.readComponentSymbols(COMPONENT_REF)).isEmpty();
index 93ca5ca13ced9f85fb88175c158f56679490e9c3..866e366118ad6929335e19d50d89cd73dd28fa99 100644 (file)
@@ -43,6 +43,7 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
   private Map<Integer, BatchReport.Component> components = new HashMap<>();
   private Map<Integer, List<BatchReport.Issue>> issues = new HashMap<>();
   private Map<Integer, List<BatchReport.Duplication>> duplications = new HashMap<>();
+  private Map<Integer, List<BatchReport.DuplicationBlock>> duplicationBlocks = new HashMap<>();
   private Map<Integer, List<BatchReport.Symbol>> symbols = new HashMap<>();
   private Map<Integer, List<BatchReport.SyntaxHighlighting>> syntaxHighlightings = new HashMap<>();
   private Map<Integer, List<BatchReport.Coverage>> coverages = new HashMap<>();
@@ -72,6 +73,7 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
     this.components.clear();
     this.issues.clear();
     this.duplications.clear();
+    this.duplicationBlocks.clear();
     this.symbols.clear();
     this.syntaxHighlightings.clear();
     this.coverages.clear();
@@ -166,6 +168,15 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
     this.duplications.put(componentRef, Arrays.asList(duplications));
   }
 
+  @Override
+  public CloseableIterator<BatchReport.DuplicationBlock> readComponentDuplicationBlocks(int componentRef) {
+    return closeableIterator(this.duplicationBlocks.get(componentRef));
+  }
+
+  public void putDuplicationBlocks(int componentRef, List<BatchReport.DuplicationBlock> duplicationBlocks) {
+    this.duplicationBlocks.put(componentRef, duplicationBlocks);
+  }
+
   @Override
   public CloseableIterator<BatchReport.Symbol> readComponentSymbols(int componentRef) {
     return closeableIterator(this.symbols.get(componentRef));