Package org.sonar.api.measures

Examples of org.sonar.api.measures.Metric


    Snapshot snapshot = new Snapshot(project1, true, "", new Date(1));
    getSession().save(snapshot);
    getSession().save(CoreMetrics.CLASSES);
    getSession().commit();

    Metric metric = new MeasuresDao(getSession()).getMetric(CoreMetrics.CLASSES_KEY);
    for (int i = 0; i < NB_INSERTS; i++) {
      MeasureModel pm = new MeasureModel(metric.getId(), 1.0).setSnapshotId(snapshot.getId());
      getSession().save(pm);
    }

    getSession().commit();
    assertEquals(NB_INSERTS, getHQLCount(MeasureModel.class));
View Full Code Here


  @Override
  public Object get(Value value, Class clazz, CoderContext context) {
    Measure<?> m = new Measure();
    String metricKey = value.getString();
    Metric metric = metricFinder.findByKey(metricKey);
    if (metric == null) {
      throw new IllegalStateException("Unknow metric with key " + metricKey);
    }
    m.setMetric(metric);
    m.setRawValue(value.isNull(true) ? null : value.getDouble());
View Full Code Here

  private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap();
  private Map<Integer, Metric> metricsById = Maps.newLinkedHashMap();

  public DeprecatedMetricFinder(GlobalReferentials globalReferentials) {
    for (org.sonar.batch.protocol.input.Metric metric : globalReferentials.metrics()) {
      Metric hibernateMetric = new org.sonar.api.measures.Metric.Builder(metric.key(), metric.name(), ValueType.valueOf(metric.valueType()))
        .create()
        .setDirection(metric.direction())
        .setQualitative(metric.isQualitative())
        .setUserManaged(metric.isUserManaged())
        .setDescription(metric.description())
View Full Code Here

  @Override
  public Collection<Metric> findAll(List<String> metricKeys) {
    List<Metric> result = Lists.newLinkedList();
    for (String metricKey : metricKeys) {
      Metric metric = findByKey(metricKey);
      if (metric != null) {
        result.add(metric);
      }
    }
    return result;
View Full Code Here

      public Measure calculate(FormulaData data, FormulaContext context) {
        return null;
      }
    };
    Metric metric = new Metric("ncloc").setFormula(formula);
    List<Metric> dependencies = new FormulaDecorator(metric).dependsUponMetrics();
    assertThat(dependencies).containsOnly(CoreMetrics.COMPLEXITY, CoreMetrics.COVERAGE);
  }
View Full Code Here

    assertThat(dependencies).containsOnly(CoreMetrics.COMPLEXITY, CoreMetrics.COVERAGE);
  }

  @Test
  public void saveMeasure() {
    FormulaDecorator decorator = new FormulaDecorator(new Metric("fake").setFormula(new FakeFormula()));

    DecoratorContext context = mock(DecoratorContext.class);
    decorator.decorate(null, context);

    verify(context).saveMeasure(argThat(new IsMeasure(new Metric("fake"), 50.0)));
  }
View Full Code Here

    verify(context).saveMeasure(argThat(new IsMeasure(new Metric("fake"), 50.0)));
  }

  @Test
  public void doNotExecuteIfExistingResult() {
    Metric fake = new Metric("fake");
    FormulaDecorator decorator = new FormulaDecorator(fake.setFormula(new FakeFormula()));

    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(fake)).thenReturn(new Measure(fake, 10.0));
    decorator.decorate(null, context);
View Full Code Here

    public List<Metric> dependsUponMetrics() {
      return Collections.emptyList();
    }

    public Measure calculate(FormulaData data, FormulaContext context) {
      return new Measure(new Metric("fake")).setValue(50.0);
    }
View Full Code Here

    when(snapshot.getId()).thenReturn(id);
    return snapshot;
  }

  private static Metric ncloc() {
    Metric ncloc = mock(Metric.class);
    when(ncloc.getId()).thenReturn(1);
    when(ncloc.getKey()).thenReturn("ncloc");
    return ncloc;
  }
View Full Code Here

    when(ncloc.getKey()).thenReturn("ncloc");
    return ncloc;
  }

  private static Metric coverage() {
    Metric coverage = mock(Metric.class);
    when(coverage.getId()).thenReturn(COVERAGE_METRIC_ID);
    when(coverage.getKey()).thenReturn("coverage");
    when(coverage.isOptimizedBestValue()).thenReturn(true);
    when(coverage.getBestValue()).thenReturn(100.0);
    return coverage;
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.measures.Metric

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.