Search in sources :

Example 46 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class ItCoverageSensorTest method testLineHitAndConditions.

@Test
public void testLineHitAndConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.itcoverage");
    FileUtils.write(coverage, "1:3:4:2");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setModuleBaseDir(baseDir.toPath()).setLanguage("xoo").setLines(10).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.lineHits("foo:src/foo.xoo", 1)).isEqualTo(3);
    assertThat(context.conditions("foo:src/foo.xoo", 1)).isEqualTo(4);
    assertThat(context.coveredConditions("foo:src/foo.xoo", 1)).isEqualTo(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 47 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class UtCoverageSensorTest method testNoExecutionIfNoCoverageFile.

@Test
public void testNoExecutionIfNoCoverageFile() {
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 48 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class UtCoverageSensorTest method testLineHitNoConditions.

@Test
public void testLineHitNoConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.coverage");
    FileUtils.write(coverage, "1:3\n\n#comment");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).setLines(10).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.lineHits("foo:src/foo.xoo", 1)).isEqualTo(3);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 49 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class UtCoverageSensorTest method testLineHitAndConditions.

@Test
public void testLineHitAndConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.coverage");
    FileUtils.write(coverage, "1:3:4:2");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).setLines(10).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.lineHits("foo:src/foo.xoo", 1)).isEqualTo(3);
    assertThat(context.conditions("foo:src/foo.xoo", 1)).isEqualTo(4);
    assertThat(context.coveredConditions("foo:src/foo.xoo", 1)).isEqualTo(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 50 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class OverallCoverageSensorTest method testLineHitAndConditions.

@Test
public void testLineHitAndConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.overallcoverage");
    FileUtils.write(coverage, "1:3:4:2");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).setLines(10).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.lineHits("foo:src/foo.xoo", 1)).isEqualTo(3);
    assertThat(context.conditions("foo:src/foo.xoo", 1)).isEqualTo(4);
    assertThat(context.coveredConditions("foo:src/foo.xoo", 1)).isEqualTo(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)199 Test (org.junit.Test)163 File (java.io.File)89 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)88 InputFile (org.sonar.api.batch.fs.InputFile)87 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)41 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)23 Before (org.junit.Before)22 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)16 SonarComponents (org.sonar.java.SonarComponents)13 JavaCheck (org.sonar.plugins.java.api.JavaCheck)13 BlameLine (org.sonar.api.batch.scm.BlameLine)12 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)9 Path (java.nio.file.Path)8 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 AnalyzerMessage (org.sonar.java.AnalyzerMessage)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 IOException (java.io.IOException)6 ZipFile (java.util.zip.ZipFile)6 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)6