Search in sources :

Example 61 with InputFile

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

the class XooBlameCommandTest method testBlame.

@Test
public void testBlame() throws IOException {
    File source = new File(baseDir, "src/foo.xoo");
    FileUtils.write(source, "sample content");
    File scm = new File(baseDir, "src/foo.xoo.scm");
    FileUtils.write(scm, "123,julien,2014-12-12\n234,julien,2014-12-24");
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
    fs.add(inputFile);
    BlameOutput result = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(Arrays.<InputFile>asList(inputFile));
    new XooBlameCommand().blame(input, result);
    verify(result).blameResult(inputFile, Arrays.asList(new BlameLine().revision("123").author("julien").date(DateUtils.parseDate("2014-12-12")), new BlameLine().revision("234").author("julien").date(DateUtils.parseDate("2014-12-24"))));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 62 with InputFile

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

the class OverallCoverageSensorTest method testLineHitNoConditions.

@Test
public void testLineHitNoConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.overallcoverage");
    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 63 with InputFile

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

the class CpdTokenizerSensorTest method createSourceFile.

private void createSourceFile(String content) throws IOException {
    File sourceFile = new File(baseDir, "src/foo.xoo");
    FileUtils.write(sourceFile, content);
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").initMetadata(content).setModuleBaseDir(baseDir.toPath()).build();
    context.fileSystem().add(inputFile);
}
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)

Example 64 with InputFile

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

the class MeasureSensorTest method failIfMetricNotFound.

@Test
public void failIfMetricNotFound() throws IOException {
    File measures = new File(baseDir, "src/foo.xoo.measures");
    FileUtils.write(measures, "unknow:12\n\n#comment");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
    context.fileSystem().add(inputFile);
    thrown.expect(IllegalStateException.class);
    sensor.execute(context);
}
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 65 with InputFile

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

the class MeasureSensorTest method testExecution.

@Test
public void testExecution() throws IOException {
    File measures = new File(baseDir, "src/foo.xoo.measures");
    FileUtils.write(measures, "ncloc:12\nbranch_coverage:5.3\nsqale_index:300\nbool:true\n\n#comment");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
    context.fileSystem().add(inputFile);
    Metric<Boolean> booleanMetric = new Metric.Builder("bool", "Bool", Metric.ValueType.BOOL).create();
    when(metricFinder.<Integer>findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<Double>findByKey("branch_coverage")).thenReturn(CoreMetrics.BRANCH_COVERAGE);
    when(metricFinder.<Long>findByKey("sqale_index")).thenReturn(CoreMetrics.TECHNICAL_DEBT);
    when(metricFinder.<Boolean>findByKey("bool")).thenReturn(booleanMetric);
    sensor.execute(context);
    assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.NCLOC).value()).isEqualTo(12);
    assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.BRANCH_COVERAGE).value()).isEqualTo(5.3);
    assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.TECHNICAL_DEBT).value()).isEqualTo(300L);
    assertThat(context.measure("foo:src/foo.xoo", booleanMetric).value()).isTrue();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Metric(org.sonar.api.measures.Metric) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

InputFile (org.sonar.api.batch.fs.InputFile)102 Test (org.junit.Test)61 File (java.io.File)45 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)39 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)20 TaskResult (org.sonar.scanner.mediumtest.TaskResult)19 IOException (java.io.IOException)10 FilePredicates (org.sonar.api.batch.fs.FilePredicates)8 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)7 List (java.util.List)6 FileSystem (org.sonar.api.batch.fs.FileSystem)6 BlameLine (org.sonar.api.batch.scm.BlameLine)6 ArrayList (java.util.ArrayList)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 DefaultBlameOutput (org.sonar.scanner.scm.DefaultBlameOutput)4 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)3 MutableTestPlan (org.sonar.api.test.MutableTestPlan)3 Block (org.sonar.duplications.block.Block)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2