Package org.sonar.api.resources

Examples of org.sonar.api.resources.File


  }

  @Test
  public void test_measure_coder() throws Exception {
    MeasureCache cache = new MeasureCache(caches, metricFinder, techDebtModel);
    Resource file1 = new File("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt");

    Measure measure = new Measure(CoreMetrics.NCLOC, 1.786, 5);
    cache.put(file1, measure);

    Measure savedMeasure = cache.byResource(file1).iterator().next();
View Full Code Here


    String source = lastSnapshots.getSource(new Project("my-project"));
    assertThat(source).isEqualTo("");
  }

  private File newFile() {
    File file = new File("org/foo", "Bar.c");
    file.setEffectiveKey("myproject:org/foo/Bar.c");
    return file;
  }
View Full Code Here

    file.setEffectiveKey("myproject:org/foo/Bar.c");
    return file;
  }

  private File newFileWithSpace() {
    File file = new File("org/foo", "Foo Bar.c");
    file.setEffectiveKey("myproject:org/foo/Foo Bar.c");
    return file;
  }
View Full Code Here

        Resource sonarFile;
        String parentOldKey;
        if ("java".equals(resourceModel.getLanguageKey())) {
          parentOldKey = String.format("%s:%s", module.getEffectiveKey(), DeprecatedKeyUtils.getJavaFileParentDeprecatedKey(oldKey));
        } else {
          sonarFile = new File(oldKey);
          parentOldKey = String.format("%s:%s", module.getEffectiveKey(), sonarFile.getParent().getDeprecatedKey());
        }
        String parentNewKey = String.format("%s:%s", module.getEffectiveKey(), getParentKey(matchedFile));
        if (!deprecatedDirectoryKeyMapper.containsKey(parentOldKey)) {
          deprecatedDirectoryKeyMapper.put(parentOldKey, parentNewKey);
View Full Code Here

public class ResourceCacheTest {
  @Test
  public void should_cache_resource() throws Exception {
    ResourceCache cache = new ResourceCache();
    String componentKey = "struts:src/org/struts/Action.java";
    Resource resource = new File("org/struts/Action.java").setEffectiveKey(componentKey);
    cache.add(resource);

    assertThat(cache.get(componentKey)).isSameAs(resource);
    assertThat(cache.get("other")).isNull();
  }
View Full Code Here

  }

  @Test
  public void should_fail_if_missing_component_key() throws Exception {
    ResourceCache cache = new ResourceCache();
    Resource resource = new File("org/struts/Action.java").setEffectiveKey(null);
    try {
      cache.add(resource);
      fail();
    } catch (IllegalStateException e) {
      // success
View Full Code Here

  @Test
  public void test_calculation_for_file() {
    when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
    when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
    when(context.getResource()).thenReturn(new File("foo"));

    Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY, CoreMetrics.FUNCTIONS).calculate(data, context);
    assertThat(measure.getValue()).isEqualTo(3.0);
  }
View Full Code Here

  @Test
  public void should_use_fallback_metric_when_no_data_on_main_metric_for_file() {
    when(data.getMeasure(CoreMetrics.COMPLEXITY_IN_FUNCTIONS)).thenReturn(null);
    when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
    when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
    when(context.getResource()).thenReturn(new File("foo"));

    Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, CoreMetrics.FUNCTIONS)
      .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
      .calculate(data, context);
    assertThat(measure.getValue()).isEqualTo(3.0);
View Full Code Here

  @Test
  public void should_use_main_metric_even_if_fallback_metric_provided() {
    when(data.getMeasure(CoreMetrics.COMPLEXITY_IN_FUNCTIONS)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
    when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 42.0));
    when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
    when(context.getResource()).thenReturn(new File("foo"));

    Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, CoreMetrics.FUNCTIONS)
      .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
      .calculate(data, context);
    assertThat(measure.getValue()).isEqualTo(3.0);
View Full Code Here

    decorator.saveCharacteristicMeasure(context, (Characteristic) null, 12.0, false);
    verify(context, times(1)).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT));

    // or for a file
    context = mock(DecoratorContext.class);
    when(context.getResource()).thenReturn(new File("foo"));
    decorator.saveCharacteristicMeasure(context, (Characteristic) null, 12.0, false);
    verify(context, times(1)).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT));
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.resources.File

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.