org.sonar.api.batch.sensor.measure.Measure Java Examples
The following examples show how to use
org.sonar.api.batch.sensor.measure.Measure.
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: RubyMetricsSensorTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Test public void testExecute() { RubyMetricsSensor sensor = new RubyMetricsSensor(); sensor.execute(context); Collection<Measure> measures = context.measures("myProjectKey:test_controller.rb"); assertThat(measures.size()).isEqualTo(3); measures.forEach(measure -> { if (CoreMetrics.NCLOC.equals(measure.metric())) { assertThat(measure.value()).isEqualTo(4); } else if (CoreMetrics.COMMENT_LINES.equals(measure.metric())) { assertThat(measure.value()).isEqualTo(11); } else if (CoreMetrics.CLASSES.equals(measure.metric())) { assertThat(measure.value()).isEqualTo(1); } }); }
Example #2
Source File: ClojureSensorTest.java From sonar-clojure with MIT License | 5 votes |
@Test public void shouldHaveAMeasureOfNonCommentedLinesOfCodePerFile() { clojureSensor.execute(context); String fooKey = "module:foo.clj"; String barKey = "module:bar.clj"; Measure<Integer> fooLineCountMeasure = context.measure(fooKey, CoreMetrics.NCLOC); Measure<Integer> barLineCountMeasure = context.measure(barKey, CoreMetrics.NCLOC); assertThat(fooLineCountMeasure).isNotNull(); assertThat(fooLineCountMeasure.value()).isEqualTo(2); assertThat(barLineCountMeasure).isNotNull(); assertThat(barLineCountMeasure.value()).isEqualTo(3); }
Example #3
Source File: ColdfusionSensorTest.java From sonar-coldfusion with Apache License 2.0 | 5 votes |
@Test public void testBasicCFMAnalysis() { DefaultFileSystem fileSystem = new DefaultFileSystem(tmpFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); fileSystem.setWorkDir(tmpFolder.getRoot().toPath()); context.setFileSystem(fileSystem); context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(7, 6), SonarQubeSide.SCANNER)); context.settings().appendProperty("sonar.projectBaseDir", baseDir.getPath()); addFilesToFs(); CommandExecutor commandExecutor = CommandExecutor.create(); String javaHome = System.getProperty("java.home"); Assert.assertTrue(javaHome!=null && !javaHome.equals("")); if(OSValidator.isWindows()) { context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java.exe"); } else { context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java"); } ColdFusionSensor sensor = new ColdFusionSensor(context.fileSystem(), rulesProfile); sensor.execute(context); Integer nloc = 0; Integer comments = 0; Integer complexity = 0; for (InputFile o : context.fileSystem().inputFiles()) { Measure<Integer> measureNloc = context.measure(o.key(),CoreMetrics.NCLOC.key()); Measure<Integer> measureComment = context.measure(o.key(),CoreMetrics.COMMENT_LINES.key()); Measure<Integer> measureComplexity = context.measure(o.key(),CoreMetrics.COMPLEXITY.key()); nloc+=measureNloc.value(); comments+=measureComment.value(); complexity+=measureComplexity.value(); } assertThat(nloc).isEqualTo(56); assertThat(comments).isEqualTo(9); assertThat(complexity).isEqualTo(10); }