Package org.sonar.api.measures

Examples of org.sonar.api.measures.Measure


      new Object[] {VIOLATIONS_ID, null, null, rule1.getId(), 100.0},// rule 1
      new Object[] {VIOLATIONS_ID, null, null, rule2.getId(), 80.0})); // rule 2

    // current analysis
    DecoratorContext context = mock(DecoratorContext.class);
    Measure violations = newMeasure(VIOLATIONS, 200.0);
    Measure violationsRule1 = RuleMeasure.createForRule(VIOLATIONS, rule1, 130.0);
    Measure violationsRule2 = RuleMeasure.createForRule(VIOLATIONS, rule2, 70.0);
    when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(violations, violationsRule1, violationsRule2));

    VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1), ruleFinder);
    decorator.decorate(dir, context);
View Full Code Here


    assertThat(violations.getVariation1()).isEqualTo(20.0);
  }

  private Measure newMeasure(Metric metric, double value) {
    return new Measure(metric, value);
  }
View Full Code Here

    filter = new CoverageMeasurementFilter(settings, new CoverageDecorator(), new LineCoverageDecorator(), new BranchCoverageDecorator());
  }

  @Test
  public void shouldNotFilterNonCoverageMetrics() {
    Measure otherMeasure = mock(Measure.class);
    when(otherMeasure.getMetric()).thenReturn(CoreMetrics.LINES);
    assertThat(filter.accept(mock(Resource.class), otherMeasure)).isTrue();
  }
View Full Code Here

  }

  @Test
  public void shouldFilterFileBasedOnPattern() {
    Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false);
    Measure coverageMeasure = mock(Measure.class);
    when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.LINES_TO_COVER);

    settings.setProperty("sonar.coverage.exclusions", "src/org/polop/*");
    filter.initPatterns();
    assertThat(filter.accept(resource, coverageMeasure)).isFalse();
  }
View Full Code Here

  }

  @Test
  public void shouldNotFilterFileBasedOnPattern() {
    Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false);
    Measure coverageMeasure = mock(Measure.class);
    when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.COVERAGE);

    settings.setProperty("sonar.coverage.exclusions", "src/org/other/*");
    filter.initPatterns();
    assertThat(filter.accept(resource, coverageMeasure)).isTrue();
  }
View Full Code Here

    verify(context, never()).saveMeasure(eq(CoreMetrics.IT_COVERAGE), anyDouble());
  }

  @Test
  public void should_count_elements_for_new_code() {
    Measure newLines = measureWithVariation(1, 100.0);
    Measure newConditions = measureWithVariation(1, 1.0);
    DecoratorContext context = mockNewContext(newLines, null, null, newConditions);

    long count = decorator.countElementsForNewCode(context, 1);

    assertThat(count).isEqualTo(101).isEqualTo(100 + 1);
View Full Code Here

    assertThat(count).isEqualTo(101).isEqualTo(100 + 1);
  }

  @Test
  public void should_count_covered_elements_for_new_code() {
    Measure newLines = measureWithVariation(1, 100.0);
    Measure newUncoveredConditions = measureWithVariation(1, 10.0);
    Measure newUncoveredLines = measureWithVariation(1, 5.0);
    Measure newConditions = measureWithVariation(1, 1.0);
    DecoratorContext context = mockNewContext(newLines, newUncoveredConditions, newUncoveredLines, newConditions);

    long count = decorator.countCoveredElementsForNewCode(context, 1);

    assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
View Full Code Here

    assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
  }

  private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_LINES_TO_COVER, (double) lines));
    when(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_LINES, (double) uncoveredLines));
    when(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_CONDITIONS_TO_COVER, (double) conditions));
    when(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
    return context;
  }
View Full Code Here

  @Test
  public void shouldDoNothingIfNoScmData() throws ParseException {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA))
      .thenReturn(new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "1=10"));

    NewCoverageFileAnalyzer decorator = newDecorator();
    decorator.doDecorate(context);
    verify(context, never()).saveMeasure(any(Measure.class));
  }
View Full Code Here

    when(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER)).thenReturn(newConditions);
    return context;
  }

  private static Measure measureWithVariation(int period, double variation) {
    Measure measure = mock(Measure.class);
    when(measure.getVariation(period)).thenReturn(variation);
    return measure;
  }
View Full Code Here

TOP

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

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.