Search in sources :

Example 26 with TestInputFileBuilder

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

the class DefaultHighlightableTest method should_store_highlighting_rules.

@Test
public void should_store_highlighting_rules() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata("azerty\nbla bla").build();
    DefaultHighlightable highlightablePerspective = new DefaultHighlightable(inputFile, sensorStorage, mock(AnalysisMode.class));
    highlightablePerspective.newHighlighting().highlight(0, 6, "k").highlight(7, 10, "cppd").done();
    ArgumentCaptor<DefaultHighlighting> argCaptor = ArgumentCaptor.forClass(DefaultHighlighting.class);
    verify(sensorStorage).store(argCaptor.capture());
    assertThat(argCaptor.getValue().getSyntaxHighlightingRuleSet()).hasSize(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultHighlighting(org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting) AnalysisMode(org.sonar.api.batch.AnalysisMode) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) DefaultHighlightable(org.sonar.scanner.source.DefaultHighlightable) Test(org.junit.Test)

Example 27 with TestInputFileBuilder

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

the class AdditionalFilePredicatesTest method key.

@Test
public void key() {
    FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java");
    InputFile inputFile = new TestInputFileBuilder("struts", "Action.java").build();
    assertThat(predicate.apply(inputFile)).isTrue();
    inputFile = new TestInputFileBuilder("struts", "Filter.java").build();
    assertThat(predicate.apply(inputFile)).isFalse();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) FilePredicate(org.sonar.api.batch.fs.FilePredicate) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 28 with TestInputFileBuilder

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

the class ItCoverageSensorTest method testNoExecutionIfNoCoverageFile.

@Test
public void testNoExecutionIfNoCoverageFile() {
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").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 29 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 30 with TestInputFileBuilder

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

the class OneIssuePerLineSensorTest method testProvideGap.

@Test
public void testProvideGap() throws IOException {
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.xoo").setLanguage(Xoo.KEY).initMetadata("a\nb\nc\nd\ne\nf\ng\nh\ni\n").build();
    SensorContextTester context = SensorContextTester.create(temp.newFolder());
    context.fileSystem().add(inputFile);
    context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2");
    sensor.execute(context);
    // One issue per line
    assertThat(context.allIssues()).hasSize(10);
    for (Issue issue : context.allIssues()) {
        assertThat(issue.gap()).isEqualTo(1.2d);
    }
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Issue(org.sonar.api.batch.sensor.issue.Issue) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Aggregations

TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)87 Test (org.junit.Test)77 InputFile (org.sonar.api.batch.fs.InputFile)41 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)23 File (java.io.File)19 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)9 Before (org.junit.Before)7 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)6 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)5 BlameLine (org.sonar.api.batch.scm.BlameLine)5 AnalysisMode (org.sonar.api.batch.AnalysisMode)4 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)4 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)4 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)4 Issue (org.sonar.api.batch.sensor.issue.Issue)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)4 DefaultBlameOutput (org.sonar.scanner.scm.DefaultBlameOutput)4 DefaultTextPointer (org.sonar.api.batch.fs.internal.DefaultTextPointer)3 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)3