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");
}
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")));
}
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));
}
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);
}
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();
}
Aggregations