aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch-protocol/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch-protocol/src/test/java')
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/ProtobufUtilTest.java71
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java28
2 files changed, 12 insertions, 87 deletions
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/ProtobufUtilTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/ProtobufUtilTest.java
deleted file mode 100644
index 04ebcf7f989..00000000000
--- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/ProtobufUtilTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.protocol;
-
-import java.io.File;
-import org.apache.commons.io.FileUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.test.TestUtils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ProtobufUtilTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void only_utils() {
- assertThat(TestUtils.hasOnlyPrivateConstructors(ProtobufUtil.class));
- }
-
- @Test
- public void readFile_fails_if_file_does_not_exist() throws Exception {
- thrown.expect(IllegalStateException.class);
-
- File file = temp.newFile();
- FileUtils.forceDelete(file);
- ProtobufUtil.readFile(file, BatchReport.Metadata.PARSER);
- }
-
- @Test
- public void readFile_returns_empty_message_if_file_is_empty() throws Exception {
- File file = temp.newFile();
- BatchReport.Metadata msg = ProtobufUtil.readFile(file, BatchReport.Metadata.PARSER);
- assertThat(msg).isNotNull();
- assertThat(msg.isInitialized()).isTrue();
- }
-
- @Test
- public void readFile_returns_message() throws Exception {
- File file = temp.newFile();
- ProtobufUtil.writeToFile(BatchReport.Metadata.getDefaultInstance(), file);
- BatchReport.Metadata message = ProtobufUtil.readFile(file, BatchReport.Metadata.PARSER);
- assertThat(message).isNotNull();
- assertThat(message.isInitialized()).isTrue();
- }
-}
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java
index e19e044d2c5..ae1a6cd143e 100644
--- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java
@@ -28,9 +28,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.batch.protocol.Constants;
-import org.sonar.batch.protocol.ProtobufUtil;
import org.sonar.batch.protocol.output.BatchReport.Range;
import org.sonar.core.util.CloseableIterator;
+import org.sonar.core.util.Protobuf;
import static org.assertj.core.api.Assertions.assertThat;
@@ -63,7 +63,7 @@ public class BatchReportWriterTest {
.setRootComponentRef(1);
underTest.writeMetadata(metadata.build());
- BatchReport.Metadata read = ProtobufUtil.readFile(underTest.getFileStructure().metadataFile(), BatchReport.Metadata.PARSER);
+ BatchReport.Metadata read = Protobuf.read(underTest.getFileStructure().metadataFile(), BatchReport.Metadata.PARSER);
assertThat(read.getAnalysisDate()).isEqualTo(15000000L);
assertThat(read.getProjectKey()).isEqualTo("PROJECT_A");
assertThat(read.getRootComponentRef()).isEqualTo(1);
@@ -88,7 +88,7 @@ public class BatchReportWriterTest {
assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
File file = underTest.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1);
assertThat(file).exists().isFile();
- BatchReport.Component read = ProtobufUtil.readFile(file, BatchReport.Component.PARSER);
+ BatchReport.Component read = Protobuf.read(file, BatchReport.Component.PARSER);
assertThat(read.getRef()).isEqualTo(1);
assertThat(read.getChildRefList()).containsOnly(5, 42);
assertThat(read.hasName()).isFalse();
@@ -111,7 +111,7 @@ public class BatchReportWriterTest {
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 = ProtobufUtil.readStreamFromFile(file, BatchReport.Issue.PARSER)) {
+ try (CloseableIterator<BatchReport.Issue> read = Protobuf.readStream(file, BatchReport.Issue.PARSER)) {
assertThat(Iterators.size(read)).isEqualTo(1);
}
}
@@ -131,7 +131,7 @@ public class BatchReportWriterTest {
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 = ProtobufUtil.readStreamFromFile(file, BatchReport.Measure.PARSER)) {
+ try (CloseableIterator<BatchReport.Measure> read = Protobuf.readStream(file, BatchReport.Measure.PARSER)) {
assertThat(Iterators.size(read)).isEqualTo(1);
}
}
@@ -154,7 +154,7 @@ public class BatchReportWriterTest {
assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isTrue();
File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CHANGESETS, 1);
assertThat(file).exists().isFile();
- BatchReport.Changesets read = ProtobufUtil.readFile(file, BatchReport.Changesets.PARSER);
+ BatchReport.Changesets read = Protobuf.read(file, BatchReport.Changesets.PARSER);
assertThat(read.getComponentRef()).isEqualTo(1);
assertThat(read.getChangesetCount()).isEqualTo(1);
assertThat(read.getChangesetList()).hasSize(1);
@@ -184,7 +184,7 @@ public class BatchReportWriterTest {
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 = ProtobufUtil.readStreamFromFile(file, BatchReport.Duplication.PARSER)) {
+ 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);
@@ -218,7 +218,7 @@ public class BatchReportWriterTest {
File file = underTest.getFileStructure().fileFor(FileStructure.Domain.SYMBOLS, 1);
assertThat(file).exists().isFile();
- try (CloseableIterator<BatchReport.Symbol> read = ProtobufUtil.readStreamFromFile(file, BatchReport.Symbol.PARSER)) {
+ try (CloseableIterator<BatchReport.Symbol> read = Protobuf.readStream(file, BatchReport.Symbol.PARSER)) {
assertThat(read).hasSize(1);
}
}
@@ -235,8 +235,7 @@ public class BatchReportWriterTest {
.setEndLine(1)
.build())
.setType(Constants.HighlightingType.ANNOTATION)
- .build()
- ));
+ .build()));
assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isTrue();
}
@@ -255,8 +254,7 @@ public class BatchReportWriterTest {
.setUtCoveredConditions(1)
.setItCoveredConditions(1)
.setOverallCoveredConditions(1)
- .build()
- ));
+ .build()));
assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isTrue();
}
@@ -266,8 +264,7 @@ public class BatchReportWriterTest {
assertThat(underTest.hasComponentData(FileStructure.Domain.TESTS, 1)).isFalse();
underTest.writeTests(1, Arrays.asList(
- BatchReport.Test.getDefaultInstance()
- ));
+ BatchReport.Test.getDefaultInstance()));
assertThat(underTest.hasComponentData(FileStructure.Domain.TESTS, 1)).isTrue();
@@ -278,8 +275,7 @@ public class BatchReportWriterTest {
assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGE_DETAILS, 1)).isFalse();
underTest.writeCoverageDetails(1, Arrays.asList(
- BatchReport.CoverageDetail.getDefaultInstance()
- ));
+ BatchReport.CoverageDetail.getDefaultInstance()));
assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGE_DETAILS, 1)).isTrue();
}