org.sonar.api.batch.fs.internal.DefaultInputFile Java Examples
The following examples show how to use
org.sonar.api.batch.fs.internal.DefaultInputFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScssMetricsVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void setUp(String fileName) { File moduleBaseDir = new File("src/test/resources/metrics/"); context = SensorContextTester.create(moduleBaseDir); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("scss") .setType(InputFile.Type.MAIN); context.fileSystem().add(inputFile); context.fileSystem().setEncoding(Charsets.UTF_8); ScssMetricsVisitor metricsVisitor = new ScssMetricsVisitor(context, mock(NoSonarFilter.class)); TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class); when(treeVisitorContext.getFile()).thenReturn(inputFile.file()); when(treeVisitorContext.getTopTree()).thenReturn(ScssParser.createParser(Charsets.UTF_8).parse(inputFile.file())); metricsVisitor.scanTree(treeVisitorContext); }
Example #2
Source File: CoverageSensorTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 6 votes |
@Test public void test() throws Throwable { TemporaryFolder folder = new TemporaryFolder(); folder.create(); SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); String tempName = "GetStatusMessage.sql"; String covReport = "test.xml"; File f = folder.newFile(tempName); File coverage = folder.newFile(covReport); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/coverage/Coverage.opencoverxml"), coverage); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/coverage/TestCode.sql"), f); DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName) .initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build(); ctxTester.fileSystem().add(file1); ctxTester.settings().setProperty(Constants.COVERAGE_FILE, coverage.getAbsolutePath()); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_COVERAGE, false); CoverageSensor sut = new CoverageSensor(new SqlCoverCoverageProvider(ctxTester.settings(), ctxTester.fileSystem())); sut.execute(ctxTester); Assert.assertEquals((int) 2, (int) ctxTester.lineHits(file1.key(), 7)); }
Example #3
Source File: AntlrContextTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 6 votes |
@Test public void compareWithSonarInputFile() throws IOException { String s = "select " + "*" + "from dbo.test\r\nselect 1"; File ff = folder.newFile("test.sql"); FileUtils.write(ff, s); DefaultInputFile f = new TestInputFileBuilder("", "test.sql").setLanguage(TSQLLanguage.KEY).initMetadata(s) .build(); AntlrContext result = AntlrUtils.getRequest(s); for (Token t : result.getStream().getTokens()) { if (t.getType() == Token.EOF) { continue; } int[] start = result.getLineAndColumn(t.getStartIndex()); int[] end = result.getLineAndColumn(t.getStopIndex()); TextPointer p1 = f.newPointer(t.getStartIndex()); TextPointer p2 = f.newPointer(t.getStopIndex()); Assert.assertNotNull(start); Assert.assertNotNull(end); Assert.assertEquals(p1.line(), start[0]); Assert.assertEquals(p1.lineOffset(), start[1]); Assert.assertEquals(p2.line(), end[0]); Assert.assertEquals(p2.lineOffset(), end[1]); } }
Example #4
Source File: SyntaxHighlighterVisitorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("gherkin") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new SyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #5
Source File: CheckstyleExecutorTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 6 votes |
private static CheckstyleConfiguration mockConf() throws CheckstyleException { final CheckstyleConfiguration conf = mock(CheckstyleConfiguration.class); when(conf.getCharset()).thenReturn(Charset.defaultCharset()); when(conf.getCheckstyleConfiguration()).thenReturn( CheckstyleConfiguration.toCheckstyleConfiguration( new File("test-resources/checkstyle-conf.xml"))); final File file = new File("test-resources/Hello.java"); final File file2 = new File("test-resources/World.java"); when(conf.getSourceFiles()).thenReturn(Arrays.asList( new DefaultInputFile( new DefaultIndexedFile("", file.getParentFile().toPath(), file.getName(), "java"), DefaultInputFile::checkMetadata), new DefaultInputFile( new DefaultIndexedFile("", file2.getParentFile().toPath(), file2.getName(), "java"), DefaultInputFile::checkMetadata) )); return conf; }
Example #6
Source File: RubocopSensorTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Before public void setUp() throws URISyntaxException { MockitoAnnotations.initMocks(this); URL filePath = RubocopSensorTest.class.getClassLoader().getResource("./test_controller.rb"); rubyFile = new File(filePath.toURI()); context = SensorContextTester.create(rubyFile.getParentFile()); context.fileSystem().add(new DefaultInputFile("myProjectKey", "test_controller.rb") .setLanguage("rb") .setOriginalLineOffsets(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}) .setLines(15)); context.fileSystem().add(new DefaultInputFile("myProjectKey", "unknown_file.rb") .setLanguage("rb") .setOriginalLineOffsets(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) .setLines(10)); }
Example #7
Source File: PathResolverTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Before public void setUp() throws Exception { URL filePath = PathResolverTest.class.getClassLoader().getResource("./test_controller.rb"); existingFile = new File(filePath.toURI()); String parentPath = existingFile.getParent(); this.sensorContext = SensorContextTester.create(new File(parentPath)); this.sensorContext.settings().setProperty("path key", "test_controller.rb"); DefaultInputFile file = new DefaultInputFile("", "test_controller.rb") .setLanguage(Ruby.LANGUAGE_KEY); this.sensorContext.fileSystem().add(file); this.resolver = new PathResolver(); }
Example #8
Source File: SimpleCovSensorTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Before public void setUp() throws URISyntaxException { URL filePath = SimpleCovSensorTest.class.getClassLoader().getResource("./test_controller.rb"); rubyFile = new File(filePath.toURI()); context = SensorContextTester.create(rubyFile.getParentFile()); context.settings().setProperty(RubyPlugin.TEST_FRAMEWORK, "RSpec"); context.fileSystem().add(new DefaultInputFile("myProjectKey", "test_controller.rb") .setLanguage("rb") .setLines(15)); context.fileSystem().add(new DefaultInputFile("myProjectKey", "unknown_file.rb") .setLanguage("rb") .setLines(10)); TestUtils.buildResultSetFile(rubyFile); }
Example #9
Source File: CpdVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("css") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); cpdVisitor = new CpdVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #10
Source File: LessMetricsVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void setUp(String fileName) { File moduleBaseDir = new File("src/test/resources/metrics/"); context = SensorContextTester.create(moduleBaseDir); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("less") .setType(InputFile.Type.MAIN); context.fileSystem().add(inputFile); context.fileSystem().setEncoding(Charsets.UTF_8); LessMetricsVisitor metricsVisitor = new LessMetricsVisitor(context, mock(NoSonarFilter.class)); TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class); when(treeVisitorContext.getFile()).thenReturn(inputFile.file()); when(treeVisitorContext.getTopTree()).thenReturn(LessParser.createParser(Charsets.UTF_8).parse(inputFile.file())); metricsVisitor.scanTree(treeVisitorContext); }
Example #11
Source File: CssMetricsVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void setUp(String fileName) { File moduleBaseDir = new File("src/test/resources/metrics/"); context = SensorContextTester.create(moduleBaseDir); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("css") .setType(InputFile.Type.MAIN); context.fileSystem().add(inputFile); context.fileSystem().setEncoding(Charsets.UTF_8); CssMetricsVisitor metricsVisitor = new CssMetricsVisitor(context, mock(NoSonarFilter.class)); TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class); when(treeVisitorContext.getFile()).thenReturn(inputFile.file()); when(treeVisitorContext.getTopTree()).thenReturn(CssParser.createParser(Charsets.UTF_8).parse(inputFile.file())); metricsVisitor.scanTree(treeVisitorContext); }
Example #12
Source File: CssSyntaxHighlighterVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("css") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new CssSyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #13
Source File: ScssSyntaxHighlighterVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("scss") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new ScssSyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #14
Source File: PathResolverImplTest.java From SonarTsPlugin with MIT License | 6 votes |
@Before public void setUp() throws Exception { URL filePath = PathResolverImplTest.class.getClassLoader().getResource("./existing.ts"); existingFile = new File(filePath.toURI()); String parentPath = existingFile.getParent(); this.sensorContext = SensorContextTester.create(new File(parentPath)); this.sensorContext.settings().setProperty("path key", "existing.ts"); DefaultInputFile file = new DefaultInputFile("", "existing.ts") .setLanguage(TypeScriptLanguage.LANGUAGE_KEY); this.sensorContext.fileSystem().add(file); this.resolver = new PathResolverImpl(); }
Example #15
Source File: LuaSquidSensorTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void analyse2() throws FileNotFoundException { DefaultFileSystem fs = new DefaultFileSystem(TEST_DIR); tester.setFileSystem(fs); DefaultInputFile inputFile = new DefaultInputFile("key", "timeFormatter.lua") .setType(InputFile.Type.MAIN) .setLanguage(Lua.KEY) .initMetadata(new FileMetadata().readMetadata(new FileReader(new File(TEST_DIR, "timeFormatter.lua")))); fs.add(inputFile); sensor.execute(tester); String componentKey = inputFile.key(); assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY_IN_CLASSES).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.COMMENT_LINES).value()).isEqualTo(59); assertThat(tester.measure(componentKey, CoreMetrics.STATEMENTS).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.FUNCTIONS).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("0=1;5=0;10=0;20=0;30=0;60=0;90=0"); assertThat(tester.measure(componentKey, CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("1=0;2=0;4=0;6=0;8=0;10=0;12=0"); assertThat(tester.allIssues()).hasSize(0); }
Example #16
Source File: PmdViolationRecorderTest.java From sonar-p3c-pmd with MIT License | 6 votes |
@Test public void should_convert_pmd_violation_to_sonar_violation() { org.sonar.api.rules.Rule sonarRule = createRuleInRuleFinder("RULE"); File file1 = new File("src/source.java"); DefaultInputFile inputFile1 = addToFileSystem(file1); Issuable issuable = createIssuable(inputFile1); RuleViolation pmdViolation = createPmdViolation(file1, 42, "Description", "RULE"); Issue issue = mock(Issue.class); IssueBuilder issueBuilder = mock(IssueBuilder.class); when(issuable.newIssueBuilder()).thenReturn(issueBuilder); when(issueBuilder.ruleKey(sonarRule.ruleKey())).thenReturn(issueBuilder); when(issueBuilder.message("Description")).thenReturn(issueBuilder); when(issueBuilder.line(42)).thenReturn(issueBuilder); when(issueBuilder.build()).thenReturn(issue); pmdViolationRecorder.saveViolation(pmdViolation); verify(issuable).addIssue(issue); verify(issueBuilder).ruleKey(sonarRule.ruleKey()); verify(issueBuilder).message("Description"); verify(issueBuilder).line(42); verify(sonarRule, atLeastOnce()).ruleKey(); }
Example #17
Source File: LessSyntaxHighlighterVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("less") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new LessSyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #18
Source File: TsCoverageSensorImplTest.java From SonarTsPlugin with MIT License | 6 votes |
@Before public void setUp() throws Exception { this.file = new DefaultInputFile("", "src/test/existing.ts").setLanguage(TypeScriptLanguage.LANGUAGE_KEY); this.file.setLines(5); this.settings = mock(Settings.class); when(this.settings.getString(TypeScriptPlugin.SETTING_LCOV_REPORT_PATH)).thenReturn("lcovpath"); this.parser = mock(LCOVParser.class); this.sensor = spy(new TsCoverageSensorImpl()); this.context = SensorContextTester.create(new File("")); this.context.fileSystem().add(this.file); this.context.setSettings(this.settings); this.lcovFile = mock(File.class); when(this.lcovFile.isFile()).thenReturn(true); doReturn(this.lcovFile).when(this.sensor).getIOFile(any(File.class), eq("lcovpath")); doReturn(this.parser).when(this.sensor).getParser(eq(this.context), any(File[].class)); }
Example #19
Source File: LeinNvdSensorTest.java From sonar-clojure with MIT License | 6 votes |
private SensorContextTester prepareContext() throws IOException { SensorContextTester context = SensorContextTester.create(new File("/")); context.settings().appendProperty(NvdProperties.REPORT_LOCATION_PROPERTY, "src/test/resources/nvd-report.json"); File baseDir = new File("src/test/resources/"); File project = new File(baseDir, "project.clj"); DefaultInputFile projectFile = TestInputFileBuilder.create("", "project.clj") .setLanguage(Clojure.KEY) .initMetadata(new String(Files.readAllBytes(project.toPath()), StandardCharsets.UTF_8)) .setContents(new String(Files.readAllBytes(project.toPath()), StandardCharsets.UTF_8)) .build(); context.fileSystem().add(projectFile); return context; }
Example #20
Source File: ClojureSensorTest.java From sonar-clojure with MIT License | 6 votes |
private SensorContextTester prepareContext() { DefaultFileSystem fileSystem = new DefaultFileSystem(temporaryFolder.getRoot()); SensorContextTester context = SensorContextTester.create(temporaryFolder.getRoot()); context.setFileSystem(fileSystem); DefaultInputFile inputFile1 = TestInputFileBuilder.create("module", "foo.clj") .setLanguage(Clojure.KEY) .initMetadata("firstLine\nsecondLine") .build(); DefaultInputFile inputFile2 = TestInputFileBuilder.create("module", "bar.clj") .setLanguage(Clojure.KEY) .initMetadata("firstLine\nsecondLine\nthirdLine") .build(); context.fileSystem().add(inputFile1).add(inputFile2); return context; }
Example #21
Source File: LCOVParserImplTest.java From SonarTsPlugin with MIT License | 5 votes |
@Before public void setUp() throws Exception { this.sensorContext = SensorContextTester.create(new File("")); this.inputFile = new DefaultInputFile("", "path/to/file.ts") .setLanguage(TypeScriptLanguage.LANGUAGE_KEY) .setLines(3); this.sensorContext.fileSystem().add(this.inputFile); }
Example #22
Source File: TestUtils.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
public static DefaultInputFile createTestInputFile(File file, String contents, Charset encoding) { final DefaultInputFile inputFile = new TestInputFileBuilder("module1", file.getName()).setCharset(encoding).build(); try { Files.write(file.toPath(), contents.getBytes(encoding)); inputFile.setMetadata(new FileMetadata().readMetadata(new FileInputStream(file), encoding, file.getAbsolutePath())); } catch (IOException e) { throw Throwables.propagate(e); } return inputFile; }
Example #23
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private DefaultInputFile createInputFile(File dir, String fileName) throws IOException { return new TestInputFileBuilder("key", fileName) .setModuleBaseDir(dir.toPath()) .setLanguage(HtmlConstants.LANGUAGE_KEY) .setType(InputFile.Type.MAIN) .initMetadata(Files.readString(new File(dir, fileName).toPath(), StandardCharsets.UTF_8)) .setCharset(StandardCharsets.UTF_8) .build(); }
Example #24
Source File: CoberturaSensorTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void shouldParseReport() throws Exception { DefaultInputFile inputFile = new DefaultInputFile("key", "src/example/file.lua") .setLanguage(Lua.KEY) .setType(InputFile.Type.MAIN) .initMetadata(new FileMetadata().readMetadata(new FileReader(TEST_DIR + "src/example/file.lua"))); tester.fileSystem().add(inputFile); tester.settings().setProperty(LuaPlugin.COBERTURA_REPORT_PATH, "coverage.xml"); sensor.execute(tester); String componentKey = "key:src/example/file.lua"; Integer[] expectedConditions = {2, null, null, null, null, null, null, null, null, null}; Integer[] expectedCoveredConditions = {1, null, null, null, null, null, null, null, null, null}; Integer[] expectedHits = {0, null, null, null, null, null, 0, null, null, null}; for (int line = 1; line <= expectedConditions.length; line++) { assertThat(tester.coveredConditions(componentKey, CoverageType.UNIT, line)).as("line " + line).isEqualTo(expectedCoveredConditions[line - 1]); assertThat(tester.conditions(componentKey, CoverageType.UNIT, line)).as("line " + line).isEqualTo(expectedConditions[line - 1]); assertThat(tester.lineHits(componentKey, CoverageType.UNIT, line)).as("line " + line).isEqualTo(expectedHits[line - 1]); assertThat(tester.coveredConditions(componentKey, CoverageType.IT, line)).isNull(); assertThat(tester.lineHits(componentKey, CoverageType.IT, line)).isNull(); assertThat(tester.coveredConditions(componentKey, CoverageType.OVERALL, line)).isNull(); assertThat(tester.lineHits(componentKey, CoverageType.OVERALL, line)).isNull(); } }
Example #25
Source File: LOCSensorImplTest.java From SonarTsPlugin with MIT License | 5 votes |
private void assertLineCount(String testName, Integer expected) throws FileNotFoundException { DefaultInputFile resource = resource("src/test/resources/loc/" + testName + ".txt"); this.sensorContext.fileSystem().add(resource); this.sensor.execute(this.sensorContext); assertEquals(expected, this.sensorContext.measure(resource.key(), CoreMetrics.NCLOC).value()); }
Example #26
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Test public void checkNestedTags_noErrorsFound() throws IOException { DefaultInputFile inputFile = createInputFile(TEST_DIR, "nestedTags.html"); tester.fileSystem().add(inputFile); sensor.execute(tester); assertThat(tester.allAnalysisErrors()).isEmpty(); }
Example #27
Source File: CloverXmlReportParser.java From sonar-clover with Apache License 2.0 | 5 votes |
private void saveHitsData(InputFile resource, SMInputCursor lineCursor) throws ParseException, XMLStreamException { final NewCoverage coverage = context.newCoverage().onFile(resource); // cursor should be on the metrics element if (!canBeIncludedInFileMetrics(lineCursor)) { // cursor should now be on the line cursor; exclude this file if there are no elements to cover ((DefaultInputFile) resource).setExcludedForCoverage(true); } while (lineCursor.getNext() != null) { // skip class elements on format 2_3_2 if (isClass(lineCursor)) { continue; } final int lineId = Integer.parseInt(lineCursor.getAttrValue("num")); String count = lineCursor.getAttrValue("count"); if (StringUtils.isNotBlank(count)) { final int hits = Integer.parseInt(count); coverage.lineHits(lineId, hits); } else { int trueCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("truecount")); int falseCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("falsecount")); int coveredConditions = 0; if (trueCount > 0) { coveredConditions++; } if (falseCount > 0) { coveredConditions++; } coverage.conditions(lineId, 2, coveredConditions); } } coverage.save(); }
Example #28
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Test public void checkExpressionWithinHtmlComment_noErrorsFound() throws Exception { DefaultInputFile inputFile = createInputFile(TEST_DIR, "comment.html"); tester.fileSystem().add(inputFile); sensor.execute(tester); assertThat(tester.allAnalysisErrors()).isNotEmpty(); }
Example #29
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Test public void checkFileWithError_analysisErrorFound() throws Exception { DefaultInputFile inputFile = createInputFile(TEST_DIR, "error.html"); tester.fileSystem().add(inputFile); sensor.execute(tester); assertThat(tester.allAnalysisErrors()).isNotEmpty(); }
Example #30
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Test public void sonarlintCheck() throws Exception { DefaultInputFile inputFile = createInputFile(TEST_DIR, "test.html"); tester.fileSystem().add(inputFile); sensor.execute(tester); String componentKey = inputFile.key(); assertThat(tester.allIssues()).isNotEmpty(); assertThat(tester.cpdTokens(componentKey)).isNull(); assertThat(tester.highlightingTypeAt(componentKey, 1, 0)).isEmpty(); }