Package org.sonar.api.measures

Examples of org.sonar.api.measures.Measure


  @Override
  public void decorate(Resource resource, DecoratorContext context) {
    CountDistributionBuilder nclocDistribution = new CountDistributionBuilder(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION);
    if (ResourceUtils.isFile(resource)) {
      Language language = resource.getLanguage();
      Measure ncloc = context.getMeasure(CoreMetrics.NCLOC);
      if (language != null && ncloc != null) {
        nclocDistribution.add(language.getKey(), ncloc.getIntValue());
      }
    } else {
      for (Measure measure : context.getChildrenMeasures(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION)) {
        nclocDistribution.add(measure);
      }
    }
    Measure measure = nclocDistribution.build(false);
    if (measure != null) {
      context.saveMeasure(measure);
    }
  }
View Full Code Here


    }
    for (Metric metric : generatesMetrics()) {
      if (context.getMeasure(metric) == null) {
        Double sum = MeasureUtils.sum(shouldSaveZeroIfNoChildMeasures(), context.getChildrenMeasures(metric));
        if (sum != null) {
          context.saveMeasure(new Measure(metric, sum));
        }
      }
    }
  }
View Full Code Here

public class DuplicationDensityDecoratorTest {

  @Test
  public void densityIsBalancedByNclocAndCommentLines() {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 40.0));
    when(context.getMeasure(CoreMetrics.COMMENT_LINES)).thenReturn(new Measure(CoreMetrics.COMMENT_LINES, 10.0));
    when(context.getMeasure(CoreMetrics.DUPLICATED_LINES)).thenReturn(new Measure(CoreMetrics.DUPLICATED_LINES, 10.0));

    DuplicationDensityDecorator decorator = new DuplicationDensityDecorator();
    decorator.decorate(null, context);

    verify(context).saveMeasure(CoreMetrics.DUPLICATED_LINES_DENSITY, 20.0);
View Full Code Here


  @Test
  public void densityEvenIfNoComments() {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 40.0));
    when(context.getMeasure(CoreMetrics.DUPLICATED_LINES)).thenReturn(new Measure(CoreMetrics.DUPLICATED_LINES, 10.0));

    DuplicationDensityDecorator decorator = new DuplicationDensityDecorator();
    decorator.decorate(null, context);

    verify(context).saveMeasure(CoreMetrics.DUPLICATED_LINES_DENSITY, 25.0);
View Full Code Here

  }

  @Test
  public void noDensityIfNoDuplicationMeasure() {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 45.0));

    DuplicationDensityDecorator decorator = new DuplicationDensityDecorator();
    decorator.decorate(null, context);

    verify(context, never()).saveMeasure(eq(CoreMetrics.DUPLICATED_LINES_DENSITY), anyDouble());
View Full Code Here

  }

  @Test
  public void noDensityWhenZeroNclocAndComments() {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 0.0));
    when(context.getMeasure(CoreMetrics.DUPLICATED_LINES)).thenReturn(new Measure(CoreMetrics.COMMENT_LINES, 0.0));
    when(context.getMeasure(CoreMetrics.DUPLICATED_LINES)).thenReturn(new Measure(CoreMetrics.DUPLICATED_LINES, 10.0));

    DuplicationDensityDecorator decorator = new DuplicationDensityDecorator();
    decorator.decorate(null, context);

    verify(context, never()).saveMeasure(eq(CoreMetrics.DUPLICATED_LINES_DENSITY), anyDouble());
View Full Code Here

  }

  @Test
  public void zeroDensityWhenZeroComments() {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 40.0));
    when(context.getMeasure(CoreMetrics.COMMENT_LINES)).thenReturn(new Measure(CoreMetrics.COMMENT_LINES, 0.0));
    CommentDensityDecorator decorator = new CommentDensityDecorator();
    decorator.decorate(null, context);
    verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.COMMENT_LINES_DENSITY, 0.0)));
  }
View Full Code Here

    assertThat(decorator.shouldExecuteOnProject(mock(Project.class))).isEqualTo(true);
  }

  @Test
  public void shouldNotSaveIfMeasureAlreadyExists() {
    when(context.getMeasure(CoreMetrics.FILES)).thenReturn(new Measure(CoreMetrics.FILES, 1.0));

    decorator.decorate(resource, context);

    verify(context, never()).saveMeasure(eq(CoreMetrics.FILES), anyDouble());
  }
View Full Code Here

    verify(context, times(1)).saveMeasure(eq(CoreMetrics.FILES), eq(1d));
  }

  @Test
  public void shouldSumChildren() {
    when(context.getChildrenMeasures(CoreMetrics.FILES)).thenReturn(Arrays.asList(new Measure(CoreMetrics.FILES, 2.0), new Measure(CoreMetrics.FILES, 3.0)));

    decorator.decorate(resource, context);

    verify(context).saveMeasure(eq(CoreMetrics.FILES), eq(5.0));
  }
View Full Code Here

    when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot3)).thenReturn(Arrays.<Object[]>asList(
      new Object[] {NCLOC_ID, null, null, null, 240.0}));

    // current analysis
    DecoratorContext context = mock(DecoratorContext.class);
    Measure currentNcloc = newMeasure(NCLOC, 200.0);
    Measure currentCoverage = newMeasure(COVERAGE, 80.0);
    when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(currentNcloc, currentCoverage));

    VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3), mock(RuleFinder.class));
    decorator.decorate(dir, context);

    // context updated for each variation : 2 times for ncloc and 1 time for coverage
    verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());

    assertThat(currentNcloc.getVariation1()).isEqualTo(20.0);
    assertThat(currentNcloc.getVariation2()).isNull();
    assertThat(currentNcloc.getVariation3()).isEqualTo(-40.0);

    assertThat(currentCoverage.getVariation1()).isEqualTo(5.0);
    assertThat(currentCoverage.getVariation2()).isNull();
    assertThat(currentCoverage.getVariation3()).isNull();
  }
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.