Ejemplo n.º 1
0
  @Test
  public void write_duplications() {
    assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isFalse();

    BatchReport.Duplication duplication =
        BatchReport.Duplication.newBuilder()
            .setOriginPosition(Range.newBuilder().setStartLine(1).setEndLine(5).build())
            .addDuplicate(
                BatchReport.Duplicate.newBuilder()
                    .setOtherFileKey("COMPONENT_A")
                    .setOtherFileRef(2)
                    .setRange(Range.newBuilder().setStartLine(6).setEndLine(10).build())
                    .build())
            .build();
    underTest.writeComponentDuplications(1, Arrays.asList(duplication));

    assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.DUPLICATIONS, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Duplication> duplications =
        Protobuf.readStream(file, BatchReport.Duplication.PARSER)) {
      BatchReport.Duplication dup = duplications.next();
      assertThat(dup.getOriginPosition()).isNotNull();
      assertThat(dup.getDuplicateList()).hasSize(1);
    }
  }
Ejemplo n.º 2
0
  @Test
  public void write_symbols() {
    // no data yet
    assertThat(underTest.hasComponentData(FileStructure.Domain.SYMBOLS, 1)).isFalse();

    // write data
    BatchReport.Symbol symbol =
        BatchReport.Symbol.newBuilder()
            .setDeclaration(
                BatchReport.Range.newBuilder()
                    .setStartLine(1)
                    .setStartOffset(3)
                    .setEndLine(1)
                    .setEndOffset(5)
                    .build())
            .addReference(
                BatchReport.Range.newBuilder()
                    .setStartLine(10)
                    .setStartOffset(15)
                    .setEndLine(11)
                    .setEndOffset(2)
                    .build())
            .build();

    underTest.writeComponentSymbols(1, Arrays.asList(symbol));

    assertThat(underTest.hasComponentData(FileStructure.Domain.SYMBOLS, 1)).isTrue();

    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.SYMBOLS, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Symbol> read =
        Protobuf.readStream(file, BatchReport.Symbol.PARSER)) {
      assertThat(read).hasSize(1);
    }
  }
Ejemplo n.º 3
0
  @Test
  public void write_issues() {
    // no data yet
    assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse();

    // write data
    BatchReport.Issue issue =
        BatchReport.Issue.newBuilder().setLine(50).setMsg("the message").build();

    underTest.writeComponentIssues(1, Arrays.asList(issue));

    assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Issue> read =
        Protobuf.readStream(file, BatchReport.Issue.PARSER)) {
      assertThat(Iterators.size(read)).isEqualTo(1);
    }
  }
Ejemplo n.º 4
0
  @Test
  public void write_measures() {
    assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse();

    BatchReport.Measure measure =
        BatchReport.Measure.newBuilder()
            .setStringValue("text-value")
            .setDoubleValue(2.5d)
            .setValueType(Constants.MeasureValueType.DOUBLE)
            .build();

    underTest.writeComponentMeasures(1, Arrays.asList(measure));

    assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.MEASURES, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Measure> read =
        Protobuf.readStream(file, BatchReport.Measure.PARSER)) {
      assertThat(Iterators.size(read)).isEqualTo(1);
    }
  }