Search in sources :

Example 1 with TestInputFileBuilder

use of testutils.TestInputFileBuilder in project sonarlint-core by SonarSource.

the class SensorOptimizerTests method should_optimize_on_language.

@Test
void should_optimize_on_language() {
    var descriptor = new DefaultSensorDescriptor().onlyOnLanguages("java", "php");
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    inputFileCache.doAdd(new TestInputFileBuilder("src/Foo.java").setLanguage(Language.JAVA).build());
    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
Also used : TestInputFileBuilder(testutils.TestInputFileBuilder) DefaultSensorDescriptor(org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with TestInputFileBuilder

use of testutils.TestInputFileBuilder in project sonarlint-core by SonarSource.

the class DefaultAnalysisErrorTests method setUp.

@BeforeEach
void setUp() {
    inputFile = new TestInputFileBuilder("src/File.java").build();
    textPointer = new DefaultTextPointer(5, 2);
    storage = mock(SensorStorage.class);
}
Also used : TestInputFileBuilder(testutils.TestInputFileBuilder) DefaultTextPointer(org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.DefaultTextPointer) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with TestInputFileBuilder

use of testutils.TestInputFileBuilder in project sonarlint-core by SonarSource.

the class SonarLintFileSystemTests method files.

@Test
void files() {
    assertThat(fs.inputFiles(fs.predicates().all())).isEmpty();
    var inputFile = new TestInputFileBuilder("src/Foo.php").setBaseDir(basedir).setLanguage(Language.PHP).build();
    inputFileCache.doAdd(inputFile);
    inputFileCache.doAdd(new TestInputFileBuilder("src/Bar.java").setBaseDir(basedir).setLanguage(Language.JAVA).build());
    inputFileCache.doAdd(new TestInputFileBuilder("src/Baz.java").setBaseDir(basedir).setLanguage(Language.JAVA).build());
    // no language
    inputFileCache.doAdd(new TestInputFileBuilder("src/readme.txt").setBaseDir(basedir).build());
    // needed for CFamily
    assertThat(fs.inputFile(fs.predicates().is(inputFile.file()))).isNotNull();
    assertThat(fs.inputFile(fs.predicates().hasURI(new File(basedir.toFile(), "src/Bar.java").toURI()))).isNotNull();
    assertThat(fs.inputFile(fs.predicates().hasURI(new File(basedir.toFile(), "does/not/exist").toURI()))).isNull();
    assertThat(fs.inputFile(fs.predicates().hasURI(new File(basedir.toFile(), "../src/Bar.java").toURI()))).isNull();
    assertThat(fs.files(fs.predicates().all())).hasSize(4);
    assertThat(fs.files(fs.predicates().hasLanguage("java"))).hasSize(2);
    assertThat(fs.files(fs.predicates().hasLanguage("cobol"))).isEmpty();
    assertThat(fs.hasFiles(fs.predicates().all())).isTrue();
    assertThat(fs.hasFiles(fs.predicates().hasLanguage("java"))).isTrue();
    assertThat(fs.hasFiles(fs.predicates().hasLanguage("cobol"))).isFalse();
    assertThat(fs.inputFiles(fs.predicates().all())).hasSize(4);
    assertThat(fs.inputFiles(fs.predicates().hasLanguage("php"))).hasSize(1);
    assertThat(fs.inputFiles(fs.predicates().hasLanguage("java"))).hasSize(2);
    assertThat(fs.inputFiles(fs.predicates().hasLanguage("cobol"))).isEmpty();
    assertThat(fs.languages()).containsOnly("java", "php");
}
Also used : TestInputFileBuilder(testutils.TestInputFileBuilder) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with TestInputFileBuilder

use of testutils.TestInputFileBuilder in project sonarlint-core by SonarSource.

the class SonarLintFileSystemTests method add_languages.

@Test
void add_languages() {
    assertThat(fs.languages()).isEmpty();
    inputFileCache.doAdd(new TestInputFileBuilder("src/Foo.php").setLanguage(Language.PHP).build());
    inputFileCache.doAdd(new TestInputFileBuilder("src/Bar.java").setLanguage(Language.JAVA).build());
    assertThat(fs.languages()).containsOnly("java", "php");
}
Also used : TestInputFileBuilder(testutils.TestInputFileBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with TestInputFileBuilder

use of testutils.TestInputFileBuilder in project sonarlint-core by SonarSource.

the class SonarLintFileSystemTests method input_file_supports_non_indexed_predicates.

@Test
void input_file_supports_non_indexed_predicates() {
    inputFileCache.doAdd(new TestInputFileBuilder("src/Bar.java").setLanguage(Language.JAVA).build());
    // it would fail if more than one java file
    assertThat(fs.inputFile(fs.predicates().hasLanguage("java"))).isNotNull();
}
Also used : TestInputFileBuilder(testutils.TestInputFileBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

TestInputFileBuilder (testutils.TestInputFileBuilder)7 Test (org.junit.jupiter.api.Test)6 DefaultSensorDescriptor (org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor)2 File (java.io.File)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)1 DefaultTextPointer (org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.DefaultTextPointer)1