Esempio n. 1
0
  @Test
  public void testExecution() throws IOException {
    File measures = new File(baseDir, "src/foo.xoo.measures");
    FileUtils.write(
        measures, "ncloc:12\nbranch_coverage:5.3\nsqale_index:300\nbool:true\n\n#comment");
    DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
    context.fileSystem().add(inputFile);

    Metric<Boolean> booleanMetric =
        new Metric.Builder("bool", "Bool", Metric.ValueType.BOOL).create();

    when(metricFinder.findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.findByKey("branch_coverage")).thenReturn(CoreMetrics.BRANCH_COVERAGE);
    when(metricFinder.findByKey("sqale_index")).thenReturn(CoreMetrics.TECHNICAL_DEBT);
    when(metricFinder.findByKey("bool")).thenReturn(booleanMetric);

    sensor.execute(context);

    assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.NCLOC).value()).isEqualTo(12);
    assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.BRANCH_COVERAGE).value())
        .isEqualTo(5.3);
    assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.TECHNICAL_DEBT).value())
        .isEqualTo(300L);
    assertThat(context.measure("foo:src/foo.xoo", booleanMetric).value()).isTrue();
  }
Esempio n. 2
0
 @Before
 public void start() {
   super.start();
   metricFinder = mock(MetricFinder.class);
   when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
   measureCache = new MeasureCache(caches, metricFinder);
 }
Esempio n. 3
0
 @Override
 public Measure addMeasure(Resource resource, Measure measure) {
   Bucket bucket = getBucket(resource);
   if (bucket != null) {
     org.sonar.api.batch.measure.Metric metric = metricFinder.findByKey(measure.getMetricKey());
     if (metric == null) {
       throw new SonarException("Unknown metric: " + measure.getMetricKey());
     }
     if (!isTechnicalProjectCopy(resource)
         && !measure.isFromCore()
         && INTERNAL_METRICS.contains(metric)) {
       LOG.debug(
           "Metric "
               + metric.key()
               + " is an internal metric computed by SonarQube. Provided value is ignored.");
       return measure;
     }
     if (measureCache.contains(resource, measure)) {
       throw new SonarException(
           "Can not add the same measure twice on " + resource + ": " + measure);
     }
     measureCache.put(resource, measure);
   }
   return measure;
 }