use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlFileSensorTest method test_issues_creation.
@Test
public void test_issues_creation() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
final File file = new File("src/test/files/maven/pom.xml");
DefaultInputFile inputFile = new TestInputFileBuilder("", "pom.xml").setModuleBaseDir(fs.baseDirPath()).setPublish(false).build();
fs.add(inputFile);
SonarComponents sonarComponents = createSonarComponentsMock(fs, file);
XmlFileSensor sensor = new XmlFileSensor(sonarComponents, fs);
assertThat(inputFile.isPublished()).isFalse();
sensor.execute(context);
assertThat(inputFile.isPublished()).isTrue();
verify(sonarComponents, times(1)).reportIssue(Mockito.argThat(argument -> file.getAbsolutePath().equals(argument.getFile().getAbsolutePath())));
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlFileSensorTest method not_executed_without_xml_files_in_file_system.
@Test
public void not_executed_without_xml_files_in_file_system() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven/"));
DefaultFileSystem fs = context.fileSystem();
SonarComponents sonarComponents = createSonarComponentsMock(fs);
XmlFileSensor sensor = new XmlFileSensor(sonarComponents, fs);
sensor.execute(context);
verify(sonarComponents, Mockito.never()).reportIssue(any());
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlFileSensorTest method createSonarComponentsMock.
private static SonarComponents createSonarComponentsMock(DefaultFileSystem fs, @Nullable File file) throws IOException {
SonarComponents sonarComponents = mock(SonarComponents.class);
when(sonarComponents.checkClasses()).thenReturn(new JavaCheck[] { new PomElementOrderCheck() });
when(sonarComponents.getFileSystem()).thenReturn(fs);
if (file != null) {
when(sonarComponents.fileLines(any(File.class))).thenReturn(Files.readLines(file, StandardCharsets.UTF_8));
}
Checks<JavaCheck> checks = mock(Checks.class);
when(checks.ruleKey(any(JavaCheck.class))).thenReturn(RuleKey.of("squid", RuleAnnotationUtils.getRuleKey(PomElementOrderCheck.class)));
when(sonarComponents.checks()).thenReturn(Lists.<Checks<JavaCheck>>newArrayList(checks));
return sonarComponents;
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class SonarSymbolTableVisitorTest method setUp.
@Before
public void setUp() {
context = SensorContextTester.create(temp.getRoot());
fs = context.fileSystem();
sonarComponents = new SonarComponents(mock(FileLinesContextFactory.class), fs, mock(JavaClasspath.class), mock(JavaTestClasspath.class), mock(CheckFactory.class));
sonarComponents.setSensorContext(context);
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class VisitorsBridgeForTestsTest method test_semantic_disabled.
@Test
public void test_semantic_disabled() {
SensorContextTester context = SensorContextTester.create(new File("")).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
SonarComponents sonarComponents = new SonarComponents(null, context.fileSystem(), null, null, null, null);
sonarComponents.setSensorContext(context);
Tree parse = JavaParser.createParser().parse("class A{}");
VisitorsBridgeForTests visitorsBridgeForTests = new VisitorsBridgeForTests(Collections.singletonList(new DummyVisitor()), sonarComponents);
visitorsBridgeForTests.setCurrentFile(new File("dummy.java"));
visitorsBridgeForTests.visitFile(parse);
assertThat(visitorsBridgeForTests.lastCreatedTestContext().getSemanticModel()).isNull();
parse = JavaParser.createParser().parse("class A{}");
visitorsBridgeForTests = new VisitorsBridgeForTests(new DummyVisitor(), sonarComponents);
visitorsBridgeForTests.setCurrentFile(new File("dummy.java"));
visitorsBridgeForTests.visitFile(parse);
assertThat(visitorsBridgeForTests.lastCreatedTestContext().getSemanticModel()).isNotNull();
}
Aggregations