--- /dev/null
+/*
+ * 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.server.computation.source;
+
+import com.google.common.base.Throwables;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.Parser;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.sonar.server.util.CloseableIterator;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ReportIterator<E> extends CloseableIterator<E> {
+
+ private final Parser<E> parser;
+ private InputStream stream;
+
+ public ReportIterator(File file, Parser<E> parser) {
+ try {
+ this.parser = parser;
+ this.stream = FileUtils.openInputStream(file);
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ protected E doNext() {
+ try {
+ return parser.parseDelimitedFrom(stream);
+ } catch (InvalidProtocolBufferException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ protected void doClose() {
+ IOUtils.closeQuietly(stream);
+ }
+}
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.source.ReportIterator;
import org.sonar.server.source.db.FileSourceDb;
+import java.io.File;
+
/**
* Nothing is persist for the moment. Only Coverage are read and not persist for the moment
*/
BatchReportReader reportReader = context.getReportReader();
BatchReport.Component component = reportReader.readComponent(componentRef);
if (component.getType().equals(Constants.ComponentType.FILE)) {
- Iterable<BatchReport.Coverage> coverageList = reportReader.readFileCoverage(componentRef);
- if (coverageList != null) {
- processCoverage(component, coverageList);
+ File coverageFile = reportReader.readFileCoverage(componentRef);
+ if (coverageFile != null) {
+ ReportIterator<BatchReport.Coverage> coverageReport = new ReportIterator<>(coverageFile, BatchReport.Coverage.PARSER);
+ processCoverage(component, coverageReport);
}
}
}
}
- private void processCoverage(BatchReport.Component component, Iterable<BatchReport.Coverage> coverageList) {
+ private void processCoverage(BatchReport.Component component, ReportIterator<BatchReport.Coverage> coverageReport) {
fileSourceData = null;
FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
- for (BatchReport.Coverage coverage : coverageList) {
+ while (coverageReport.hasNext()) {
+ BatchReport.Coverage coverage = coverageReport.next();
FileSourceDb.Line.Builder lineBuilder = dataBuilder.addLinesBuilder().setLine(coverage.getLine());
processLineCoverage(coverage.getLine(), lineBuilder, coverage);
}
--- /dev/null
+/*
+ * 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.server.computation.source;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.batch.protocol.output.BatchReport;
+import org.sonar.batch.protocol.output.BatchReportWriter;
+import org.sonar.batch.protocol.output.FileStructure;
+
+import java.io.File;
+import java.util.NoSuchElementException;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ReportIteratorTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ File file;
+
+ ReportIterator<BatchReport.Coverage> sut;
+
+ @Before
+ public void setUp() throws Exception {
+ File dir = temp.newFolder();
+ BatchReportWriter writer = new BatchReportWriter(dir);
+
+ writer.writeFileCoverage(1, newArrayList(
+ BatchReport.Coverage.newBuilder()
+ .setLine(1)
+ .build()
+ ));
+
+ file = new FileStructure(dir).fileFor(FileStructure.Domain.COVERAGE, 1);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (sut != null) {
+ sut.close();
+ }
+ }
+
+ @Test
+ public void read_report() throws Exception {
+ sut = new ReportIterator<>(file, BatchReport.Coverage.PARSER);
+ assertThat(sut.next().getLine()).isEqualTo(1);
+ }
+
+ @Test(expected = NoSuchElementException.class)
+ public void test_error() throws Exception {
+ sut = new ReportIterator<>(file, BatchReport.Coverage.PARSER);
+ sut.next();
+
+ // fail !
+ sut.next();
+ }
+
+}
+++ /dev/null
-/*
- * 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 org.apache.commons.io.Charsets;
-import org.apache.commons.io.IOUtils;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-
-/**
- * An object to iterate over lines in a file.
- * A LineStream is opened upon creation and is closed by invoking the close method.
- *
- * Inspired by {@link java.nio.file.DirectoryStream}
- */
-public class FileStream implements Closeable, Iterable<String> {
-
- private final File file;
- private InputStream inputStream;
-
- public FileStream(File file) {
- this.file = file;
- }
-
- @Override
- public Iterator<String> iterator() {
- if (this.inputStream != null) {
- throw new IllegalStateException("Iterator already obtained");
- } else {
- try {
- this.inputStream = ProtobufUtil.createInputStream(file);
- return IOUtils.lineIterator(inputStream, Charsets.UTF_8);
- } catch (IOException e) {
- throw new IllegalStateException("Failed to read lines from file " + file, e);
- }
- }
- }
-
- @Override
- public void close() {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- throw new IllegalStateException("Failed to close input stream of file " + file, e);
- }
- }
- }
-}
*/
package org.sonar.batch.protocol;
-import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import com.google.protobuf.Parser;
}
}
- static <T extends Message> T readInputStream(InputStream inputStream, Parser<T> parser) {
- try {
- return parser.parseDelimitedFrom(inputStream);
- } catch (InvalidProtocolBufferException e) {
- throw new IllegalStateException("Failed to read input stream", e);
- }
- }
-
- static InputStream createInputStream(File file) {
- try {
- return new BufferedInputStream(new FileInputStream(file));
- } catch (FileNotFoundException e) {
- throw new IllegalStateException("Unable to find file " + file, e);
- }
- }
-
public static void writeToFile(Message message, File toFile) {
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(toFile, false))) {
message.writeTo(out);
+++ /dev/null
-/*
- * 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 com.google.protobuf.Message;
-import com.google.protobuf.Parser;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * An object to iterate over protobuf messages in a file.
- * A ReportStream is opened upon creation and is closed by invoking the close method.
- *
- * Warning, while it extends Iterable, it is not a general-purpose Iterable as it supports only a single Iterator;
- * invoking the iterator method to obtain a second or subsequent iterator throws IllegalStateException.
- *
- * Inspired by {@link java.nio.file.DirectoryStream}
- */
-public class ReportStream<R extends Message> implements Closeable, Iterable<R> {
-
- private final File file;
- private final Parser<R> parser;
- private InputStream inputStream;
-
- public ReportStream(File file, Parser<R> parser) {
- this.file = file;
- this.parser = parser;
- }
-
- @Override
- public Iterator<R> iterator() {
- if (this.inputStream != null) {
- throw new IllegalStateException("Iterator already obtained");
- } else {
- this.inputStream = ProtobufUtil.createInputStream(file);
- return new ReportIterator<>(inputStream, parser);
- }
- }
-
- @Override
- public void close() {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- throw new IllegalStateException("Failed to close input stream of file " + file, e);
- }
- }
- }
-
- private static class ReportIterator<R extends Message> implements Iterator<R> {
-
- private final Parser<R> parser;
- private InputStream inputStream;
- private R currentMessage;
-
- public ReportIterator(InputStream inputStream, Parser<R> parser) {
- this.inputStream = inputStream;
- this.parser = parser;
- }
-
- @Override
- public boolean hasNext() {
- if (currentMessage == null) {
- currentMessage = ProtobufUtil.readInputStream(inputStream, parser);
- }
- return currentMessage != null;
- }
-
- @Override
- public R next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
- R messageToReturn = currentMessage;
- currentMessage = null;
- return messageToReturn;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-}
*/
package org.sonar.batch.protocol.output;
-import org.sonar.batch.protocol.FileStream;
import org.sonar.batch.protocol.ProtobufUtil;
-import org.sonar.batch.protocol.ReportStream;
import org.sonar.batch.protocol.output.BatchReport.Issues;
import javax.annotation.CheckForNull;
}
@CheckForNull
- public ReportStream<BatchReport.Coverage> readFileCoverage(int fileRef) {
+ public File readFileCoverage(int fileRef) {
File file = fileStructure.fileFor(FileStructure.Domain.COVERAGE, fileRef);
if (doesFileExists(file)) {
- return new ReportStream<>(file, BatchReport.Coverage.PARSER);
+ return file;
}
return null;
}
- public FileStream readSourceLines(int fileRef) {
+ public File readFileSource(int fileRef) {
File file = fileStructure.fileFor(FileStructure.Domain.SOURCE, fileRef);
if (!doesFileExists(file)) {
throw new IllegalStateException("Unable to find source for file #" + fileRef + ". File does not exist: " + file);
}
- return new FileStream(file);
+ return file;
}
private boolean doesFileExists(File file) {
this.fileStructure = new FileStructure(dir);
}
- FileStructure getFileStructure() {
+ public FileStructure getFileStructure() {
return fileStructure;
}
+++ /dev/null
-/*
- * 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 com.google.common.io.Resources;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.Iterator;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class FileStreamTest {
-
- File file;
-
- FileStream sut;
-
- @Before
- public void setUp() throws Exception {
- file = new File(Resources.getResource(getClass(), "FileStreamTest/file.txt").getFile());
- }
-
- @After
- public void tearDown() throws Exception {
- if (sut != null) {
- sut.close();
- }
- }
-
- @Test
- public void read_lines() throws Exception {
- sut = new FileStream(file);
-
- Iterator<String> lines = sut.iterator();
- assertThat(lines.next()).isEqualTo("line1");
- assertThat(lines.next()).isEqualTo("line2");
- assertThat(lines.next()).isEqualTo("line3");
- }
-
- @Test(expected = IllegalStateException.class)
- public void fail_to_get_iterator_twice() throws Exception {
- sut = new FileStream(file);
- sut.iterator();
-
- // Fail !
- sut.iterator();
- }
-
- @Test
- public void not_fail_when_close_without_calling_iterator() throws Exception {
- sut = new FileStream(file);
- sut.close();
- }
-}
+++ /dev/null
-/*
- * 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 org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.batch.protocol.output.FileStructure;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ReportStreamTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- File file;
-
- ReportStream<BatchReport.Coverage> sut;
-
- @Before
- public void setUp() throws Exception {
- File dir = temp.newFolder();
- BatchReportWriter writer = new BatchReportWriter(dir);
-
- writer.writeFileCoverage(1, Arrays.asList(
- BatchReport.Coverage.newBuilder()
- .setLine(1)
- .build()
- ));
-
- file = new FileStructure(dir).fileFor(FileStructure.Domain.COVERAGE, 1);
- }
-
- @After
- public void tearDown() throws Exception {
- if (sut != null) {
- sut.close();
- }
- }
-
- @Test
- public void read_report() throws Exception {
- sut = new ReportStream<>(file, BatchReport.Coverage.PARSER);
- assertThat(sut).hasSize(1);
- }
-
- @Test(expected = IllegalStateException.class)
- public void fail_to_get_iterator_twice() throws Exception {
- sut = new ReportStream<>(file, BatchReport.Coverage.PARSER);
- sut.iterator();
-
- // Fail !
- sut.iterator();
- }
-
- @Test(expected = NoSuchElementException.class)
- public void fail_to_get_next_when_no_next() throws Exception {
- sut = new ReportStream<>(file, BatchReport.Coverage.PARSER);
- Iterator<BatchReport.Coverage> iterator = sut.iterator();
- // Get first element
- iterator.next();
-
- // Fail !
- iterator.next();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void fail_to_remove() throws Exception {
- sut = new ReportStream<>(file, BatchReport.Coverage.PARSER);
- Iterator<BatchReport.Coverage> iterator = sut.iterator();
-
- // Fail !
- iterator.remove();
- }
-
-}
*/
package org.sonar.batch.protocol.output;
+import com.google.common.collect.Lists;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.batch.protocol.Constants;
import java.io.File;
+import java.io.InputStream;
import java.util.Arrays;
-import java.util.List;
-import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
public class BatchReportReaderTest {
.build()));
sut = new BatchReportReader(dir);
- List<BatchReport.Coverage> coverageList = newArrayList(sut.readFileCoverage(1));
- assertThat(coverageList).hasSize(2);
-
- BatchReport.Coverage coverage = coverageList.get(0);
- assertThat(coverage.getLine()).isEqualTo(1);
- assertThat(coverage.getConditions()).isEqualTo(1);
- assertThat(coverage.getUtHits()).isTrue();
- assertThat(coverage.getItHits()).isFalse();
- assertThat(coverage.getUtCoveredConditions()).isEqualTo(1);
- assertThat(coverage.getItCoveredConditions()).isEqualTo(1);
- assertThat(coverage.getOverallCoveredConditions()).isEqualTo(1);
-
- coverage = coverageList.get(1);
- assertThat(coverage.getLine()).isEqualTo(2);
- assertThat(coverage.getConditions()).isEqualTo(5);
- assertThat(coverage.getUtHits()).isFalse();
- assertThat(coverage.getItHits()).isFalse();
- assertThat(coverage.getUtCoveredConditions()).isEqualTo(4);
- assertThat(coverage.getItCoveredConditions()).isEqualTo(5);
- assertThat(coverage.getOverallCoveredConditions()).isEqualTo(5);
+
+ InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(dir).readFileCoverage(1));
+ try {
+ BatchReport.Coverage coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
+ assertThat(coverage.getLine()).isEqualTo(1);
+ assertThat(coverage.getConditions()).isEqualTo(1);
+ assertThat(coverage.getUtHits()).isTrue();
+ assertThat(coverage.getItHits()).isFalse();
+ assertThat(coverage.getUtCoveredConditions()).isEqualTo(1);
+ assertThat(coverage.getItCoveredConditions()).isEqualTo(1);
+ assertThat(coverage.getOverallCoveredConditions()).isEqualTo(1);
+
+ coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
+ assertThat(coverage.getLine()).isEqualTo(2);
+ assertThat(coverage.getConditions()).isEqualTo(5);
+ assertThat(coverage.getUtHits()).isFalse();
+ assertThat(coverage.getItHits()).isFalse();
+ assertThat(coverage.getUtCoveredConditions()).isEqualTo(4);
+ assertThat(coverage.getItCoveredConditions()).isEqualTo(5);
+ assertThat(coverage.getOverallCoveredConditions()).isEqualTo(5);
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ @Test
+ public void read_source_lines() throws Exception {
+ File dir = temp.newFolder();
+ BatchReportWriter writer = new BatchReportWriter(dir);
+ File file = writer.getFileStructure().fileFor(FileStructure.Domain.SOURCE, 1);
+ FileUtils.writeLines(file, Lists.newArrayList("line1", "line2"));
+
+ File sourceFile = new BatchReportReader(dir).readFileSource(1);
+ assertThat(sourceFile).isEqualTo(file);
}
@Test(expected = IllegalStateException.class)
assertThat(sut.readFileCoverage(123)).isNull();
}
- @Test(expected = IllegalStateException.class)
- public void fail_if_no_source_found() throws Exception {
- assertThat(sut.readSourceLines(123)).isNull();
+ @Test
+ public void return_null_if_no_source_found() throws Exception {
+ assertThat(sut.readFileCoverage(123)).isNull();
}
/**
*/
package org.sonar.batch.protocol.output;
-import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.batch.protocol.Constants;
-import org.sonar.batch.protocol.FileStream;
import org.sonar.batch.protocol.ProtobufUtil;
-import org.sonar.batch.protocol.ReportStream;
import org.sonar.batch.protocol.output.BatchReport.Range;
import java.io.File;
import java.util.Arrays;
-import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.util.Lists.newArrayList;
public class BatchReportWriterTest {
.setUtCoveredConditions(1)
.setItCoveredConditions(1)
.setOverallCoveredConditions(1)
- .build(),
- BatchReport.Coverage.newBuilder()
- .setLine(2)
- .setConditions(5)
- .setUtHits(false)
- .setItHits(false)
- .setUtCoveredConditions(4)
- .setItCoveredConditions(5)
- .setOverallCoveredConditions(5)
.build()
- ));
+ ));
assertThat(writer.hasComponentData(FileStructure.Domain.COVERAGE, 1)).isTrue();
-
- ReportStream coverageReportStream = null;
- try {
- coverageReportStream = new BatchReportReader(dir).readFileCoverage(1);
- List<BatchReport.Coverage> coverageList = newArrayList(coverageReportStream);
- assertThat(coverageList).hasSize(2);
-
- BatchReport.Coverage coverage = coverageList.get(0);
- assertThat(coverage.getLine()).isEqualTo(1);
- assertThat(coverage.getConditions()).isEqualTo(1);
- assertThat(coverage.getUtHits()).isTrue();
- assertThat(coverage.getItHits()).isFalse();
- assertThat(coverage.getUtCoveredConditions()).isEqualTo(1);
- assertThat(coverage.getItCoveredConditions()).isEqualTo(1);
- assertThat(coverage.getOverallCoveredConditions()).isEqualTo(1);
-
- coverage = coverageList.get(1);
- assertThat(coverage.getLine()).isEqualTo(2);
- assertThat(coverage.getConditions()).isEqualTo(5);
- assertThat(coverage.getUtHits()).isFalse();
- assertThat(coverage.getItHits()).isFalse();
- assertThat(coverage.getUtCoveredConditions()).isEqualTo(4);
- assertThat(coverage.getItCoveredConditions()).isEqualTo(5);
- assertThat(coverage.getOverallCoveredConditions()).isEqualTo(5);
- } finally {
- IOUtils.closeQuietly(coverageReportStream);
- }
- }
-
- @Test
- public void read_source_lines() throws Exception {
- File dir = temp.newFolder();
- BatchReportWriter writer = new BatchReportWriter(dir);
- File file = writer.getFileStructure().fileFor(FileStructure.Domain.SOURCE, 1);
- assertThat(file.exists());
- FileUtils.writeLines(file, Lists.newArrayList("line1", "line2"));
-
- FileStream fileStream = null;
- try {
- fileStream = new BatchReportReader(dir).readSourceLines(1);
- assertThat(fileStream).hasSize(2);
- } finally {
- fileStream.close();
- }
}
}