Search in sources :

Example 96 with TestInputFileBuilder

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

the class DefaultBlameOutputTest method shouldFailIfNullRevision.

@Test
public void shouldFailIfNullRevision() {
    InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
    var blameOUtput = new DefaultBlameOutput(null, analysisWarnings, singletonList(file));
    var lines = singletonList(new BlameLine().date(new Date()).author("guy"));
    assertThatThrownBy(() -> blameOUtput.blameResult(file, lines)).isInstanceOf(IllegalArgumentException.class).hasMessage("Blame revision is blank for file " + file + " at line 1");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) Date(java.util.Date) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 97 with TestInputFileBuilder

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

the class DefaultBlameOutputTest method shouldNotFailIfNotSameNumberOfLines.

@Test
public void shouldNotFailIfNotSameNumberOfLines() {
    InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build();
    new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).blameResult(file, singletonList(new BlameLine().revision("1").author("guy")));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 98 with TestInputFileBuilder

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

the class XooTokenizerTest method testExecution.

@Test
public void testExecution() throws IOException {
    File source = new File(baseDir, "src/foo.xoo");
    FileUtils.write(source, "token1 token2 token3\ntoken4");
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
    fileSystem.add(inputFile);
    XooTokenizer tokenizer = new XooTokenizer(fileSystem);
    SourceCode sourceCode = mock(SourceCode.class);
    when(sourceCode.getFileName()).thenReturn(inputFile.absolutePath());
    Tokens cpdTokens = new Tokens();
    tokenizer.tokenize(sourceCode, cpdTokens);
    // 4 tokens + EOF
    assertThat(cpdTokens.getTokens()).hasSize(5);
    assertThat(cpdTokens.getTokens().get(3)).isEqualTo(new TokenEntry("token4", "src/foo.xoo", 2));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SourceCode(net.sourceforge.pmd.cpd.SourceCode) TokenEntry(net.sourceforge.pmd.cpd.TokenEntry) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Tokens(net.sourceforge.pmd.cpd.Tokens) Test(org.junit.Test)

Example 99 with TestInputFileBuilder

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

the class JavaCpdBlockIndexerTest method setUp.

@Before
public void setUp() throws IOException {
    MockitoAnnotations.initMocks(this);
    File baseDir = temp.newFolder();
    DefaultFileSystem fs = new DefaultFileSystem(baseDir);
    file = new TestInputFileBuilder("foo", "src/ManyStatements.java").setModuleBaseDir(baseDir.toPath()).setLanguage(JAVA).build();
    fs.add(file);
    File ioFile = file.file();
    FileUtils.copyURLToFile(this.getClass().getResource("ManyStatements.java"), ioFile);
    settings = new MapSettings();
    engine = new JavaCpdBlockIndexer(fs, settings, index);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) MapSettings(org.sonar.api.config.MapSettings) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 100 with TestInputFileBuilder

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

the class DefaultIndexTest method shouldGetHierarchy.

@Test
public void shouldGetHierarchy() {
    InputComponent component = new DefaultInputModule("module1");
    InputFile file1 = new TestInputFileBuilder("module1", "src/org/foo/Bar.java").build();
    when(componentStore.getByKey("module1")).thenReturn(component);
    when(componentStore.getByKey("module1:src/org/foo/Bar.java")).thenReturn(file1);
    when(componentTree.getParent(file1)).thenReturn(component);
    when(componentTree.getChildren(component)).thenReturn(Collections.singleton(file1));
    assertThat(index.getParent("module1:src/org/foo/Bar.java").getKey()).isEqualTo("module1");
    assertThat(index.getParent("module1")).isNull();
    assertThat(index.getChildren("module1")).containsOnly(File.create("src/org/foo/Bar.java"));
    assertThat(index.getChildren("module1:src/org/foo/Bar.java")).isEmpty();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputComponent(org.sonar.api.batch.fs.InputComponent) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) 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