Search in sources :

Example 61 with TestInputFileBuilder

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

the class DefaultFileSystemTest method inputFile_supports_non_indexed_predicates.

@Test
public void inputFile_supports_non_indexed_predicates() {
    fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
    // it would fail if more than one java file
    assertThat(fs.inputFile(fs.predicates().hasLanguage("java"))).isNotNull();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Test(org.junit.Test)

Example 62 with TestInputFileBuilder

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

the class DefaultCpdTokensTest method dont_save_for_test_files.

@Test
public void dont_save_for_test_files() {
    DefaultInputFile testInputFile = new TestInputFileBuilder("foo", "src/Foo.java").setLines(2).setOriginalLineStartOffsets(new int[] { 0, 50 }).setOriginalLineEndOffsets(new int[] { 49, 100 }).setLastValidOffset(101).setType(InputFile.Type.TEST).build();
    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage).onFile(testInputFile).addToken(testInputFile.newRange(1, 2, 1, 5), "foo");
    tokens.save();
    verifyZeroInteractions(sensorStorage);
    assertThat(tokens.getTokenLines()).isEmpty();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultCpdTokens(org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens) Test(org.junit.Test)

Example 63 with TestInputFileBuilder

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

the class SensorContextTesterTest method duplicateCpdTokens.

@Test(expected = UnsupportedOperationException.class)
public void duplicateCpdTokens() {
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("public class Foo {\n\n}").build();
    tester.newCpdTokens().onFile(inputFile).addToken(inputFile.newRange(0, 6), "public").save();
    tester.newCpdTokens().onFile(inputFile).addToken(inputFile.newRange(0, 6), "public").save();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Example 64 with TestInputFileBuilder

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

the class SensorContextTesterTest method duplicateHighlighting.

@Test(expected = UnsupportedOperationException.class)
public void duplicateHighlighting() {
    tester.newHighlighting().onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()).highlight(1, 0, 1, 5, TypeOfText.ANNOTATION).save();
    tester.newHighlighting().onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()).highlight(1, 0, 1, 5, TypeOfText.ANNOTATION).save();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Test(org.junit.Test)

Example 65 with TestInputFileBuilder

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

the class SensorContextTesterTest method testConditions.

@Test
public void testConditions() {
    assertThat(tester.conditions("foo:src/Foo.java", 1)).isNull();
    assertThat(tester.coveredConditions("foo:src/Foo.java", 1)).isNull();
    tester.newCoverage().onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar\nasd\nasdas\nasdfas").build()).conditions(1, 4, 2).save();
    assertThat(tester.conditions("foo:src/Foo.java", 1)).isEqualTo(4);
    assertThat(tester.coveredConditions("foo:src/Foo.java", 1)).isEqualTo(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) 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