Package org.sonar.api.measures

Examples of org.sonar.api.measures.Measure


  @Test
  public void shouldDoNothingIfNoCoverageData() throws ParseException {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE))
      .thenReturn(new Measure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE, "10=2008-05-18T00:00:00+0000"));

    NewCoverageFileAnalyzer decorator = newDecorator();
    decorator.doDecorate(context);

    verify(context, never()).saveMeasure(any(Measure.class));
View Full Code Here


  @Test
  public void shouldGetNewLines() throws ParseException {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)).thenReturn(
      new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "10=2;11=3"));
    when(context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE, "10=2007-01-15T00:00:00+0000;11=2011-01-01T00:00:00+0000"));

    NewCoverageFileAnalyzer decorator = newDecorator();
    decorator.doDecorate(context);

    // line 11 has been updated after date1 (2009-12-25). This line is covered.
View Full Code Here

  @Test
  public void shouldGetNewConditions() throws ParseException {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)).thenReturn(
      new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "10=2;11=3"));
    when(context.getMeasure(CoreMetrics.CONDITIONS_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.CONDITIONS_BY_LINE, "11=4"));
    when(context.getMeasure(CoreMetrics.COVERED_CONDITIONS_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE, "11=1"));
    when(context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE, "10=2007-01-15T00:00:00+0000;11=2011-01-01T00:00:00+0000"));

    NewCoverageFileAnalyzer decorator = newDecorator();
    decorator.doDecorate(context);

    // line 11 has been updated after date1 (2009-12-25). This line has 1 covered condition amongst 4
View Full Code Here

  @Test
  public void shouldNotGetNewConditionsWhenNewLineHasNoConditions() throws ParseException {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)).thenReturn(
      new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "10=2;11=3"));
    when(context.getMeasure(CoreMetrics.CONDITIONS_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.CONDITIONS_BY_LINE, "10=1"));
    when(context.getMeasure(CoreMetrics.COVERED_CONDITIONS_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE, "10=1"));
    when(context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE, "10=2007-01-15T00:00:00+0000;11=2011-01-01T00:00:00+0000"));

    NewCoverageFileAnalyzer decorator = newDecorator();
    decorator.doDecorate(context);

    // line 11 has been updated after date1 (2009-12-25) but it has no conditions
View Full Code Here

                                   "3=2008-08-02T13:56:37+0200;" +
                                   "4=2008-08-02T13:56:37+0200";

    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)).thenReturn(
      new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "2=1;3=1"));
    when(context.getMeasure(CoreMetrics.CONDITIONS_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.CONDITIONS_BY_LINE, "2=1"));
    when(context.getMeasure(CoreMetrics.COVERED_CONDITIONS_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE, "2=1"));
    when(context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE)).thenReturn(
      new Measure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE, lastCommitDatesByLine));

    NewCoverageFileAnalyzer decorator = newDecorator();
    decorator.doDecorate(context);

    verify(context).saveMeasure(argThat(new VariationMatcher(CoreMetrics.NEW_LINES_TO_COVER, 1, null)));
View Full Code Here

      this.variation = variation;
    }

    @Override
    public boolean matches(Object o) {
      Measure m = (Measure) o;
      if (m.getMetric().equals(metric)) {
        if ((variation == null && m.getVariation(index) == null) ||
          (variation != null && variation.equals(m.getVariation(index)))) {
          return true;
        }
      }
      return false;
    }
View Full Code Here

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

  private static DecoratorContext mockContext(int conditions, int uncoveredConditions) {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.CONDITIONS_TO_COVER, (double) conditions));
    when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, (double) uncoveredConditions));
    return context;
  }
View Full Code Here

    verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_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.OVERALL_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, (double) lines));
    when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, (double) uncoveredLines));
    when(context.getMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, (double) conditions));
    when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
    return context;
  }
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.