use of org.sonar.api.batch.fs.internal.DefaultInputFile 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.setSettings(new MapSettings().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);
}
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class XooBlameCommandTest method testBlameWithRelativeDate.
@Test
public void testBlameWithRelativeDate() throws IOException {
File source = new File(baseDir, "src/foo.xoo");
FileUtils.write(source, "sample content");
File scm = new File(baseDir, "src/foo.xoo.scm");
FileUtils.write(scm, "123,julien,-10\n234,julien,-10");
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
BlameOutput result = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
new XooBlameCommand().blame(input, result);
Predicate<Date> datePredicate = argument -> {
Date approximate = DateUtils.addDays(new Date(), -10);
return argument.getTime() > approximate.getTime() - 5000 && argument.getTime() < approximate.getTime() + 5000;
};
ArgumentCaptor<List<BlameLine>> blameLinesCaptor = ArgumentCaptor.forClass(List.class);
verify(result).blameResult(eq(inputFile), blameLinesCaptor.capture());
assertThat(blameLinesCaptor.getValue()).extracting(BlameLine::date).allMatch(datePredicate);
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class XooBlameCommandTest method blame_containing_author_with_comma.
@Test
public void blame_containing_author_with_comma() throws IOException {
File source = new File(baseDir, "src/foo.xoo");
FileUtils.write(source, "sample content");
File scm = new File(baseDir, "src/foo.xoo.scm");
FileUtils.write(scm, "\"123\",\"john,doe\",\"2019-01-22\"");
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
BlameOutput result = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
new XooBlameCommand().blame(input, result);
verify(result).blameResult(inputFile, singletonList(new BlameLine().revision("123").author("john,doe").date(DateUtils.parseDate("2019-01-22"))));
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class OneQuickFixPerLineSensorTest method testRule.
@Test
public void testRule() 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);
sensor.execute(context);
// One issue per line
assertThat(context.allIssues()).hasSize(10);
for (Issue issue : context.allIssues()) {
assertThat(issue.isQuickFixAvailable()).isTrue();
}
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileSystemMediumTest method scan_project_without_name.
@Test
public void scan_project_without_name() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample.xoo", "Sample xoo\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
int ref = result.getReportReader().readMetadata().getRootComponentRef();
assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty();
assertThat(result.inputFiles()).hasSize(1);
DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
assertThat(file.type()).isEqualTo(InputFile.Type.MAIN);
assertThat(file.relativePath()).isEqualTo("src/sample.xoo");
assertThat(file.language()).isEqualTo("xoo");
// file was published, since language matched xoo
assertThat(file.isPublished()).isTrue();
assertThat(result.getReportComponent(file.scannerId())).isNotNull();
}
Aggregations