Package org.sonar.api.batch

Examples of org.sonar.api.batch.DecoratorContext


  @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);

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


  }

  @Test
  public void always_save_technical_debt_for_positive_values() throws Exception {
    // for a project
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getResource()).thenReturn(new Project("foo"));
    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

    verify(context, times(1)).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT));
  }

  @Test
  public void always_save_technical_debt_for_project_if_top_characteristic() throws Exception {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getResource()).thenReturn(new Project("foo"));

    // this is a top characteristic
    DefaultCharacteristic rootCharacteristic = new DefaultCharacteristic().setKey("root");

    decorator.saveCharacteristicMeasure(context, rootCharacteristic, 0.0, true);
View Full Code Here

  /**
   * SQALE-147
   */
  @Test
  public void never_save_technical_debt_for_project_if_not_top_characteristic() throws Exception {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getResource()).thenReturn(new Project("foo"));

    DefaultCharacteristic rootCharacteristic = new DefaultCharacteristic().setKey("EFFICIENCY");
    DefaultCharacteristic characteristic = new DefaultCharacteristic().setKey("MEMORY_EFFICIENCY").setParent(rootCharacteristic);

    decorator.saveCharacteristicMeasure(context, characteristic, 0.0, true);
View Full Code Here

    verify(context, never()).saveMeasure(any(Measure.class));
  }

  @Test
  public void not_save_technical_debt_for_file_if_zero() throws Exception {
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getResource()).thenReturn(new File("foo"));

    decorator.saveCharacteristicMeasure(context, null, 0.0, true);
    verify(context, never()).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT));
  }
View Full Code Here

    when(index.getResource(module1)).thenReturn(module1);
    module2 = new Project("module2").setName("Module2").setParent(root);
    module2.setId(2);
    when(index.getResource(module2)).thenReturn(module2);

    DecoratorContext module1Context = mock(DecoratorContext.class);
    when(module1Context.getResource()).thenReturn(module1);
    DecoratorContext module2Context = mock(DecoratorContext.class);
    when(module2Context.getResource()).thenReturn(module2);

    when(rootContext.getChildren()).thenReturn(Arrays.asList(module1Context, module2Context));

  }
View Full Code Here

  @Test
  public void not_execute_on_unit_test() throws Exception {
    File resource = mock(File.class);
    when(resource.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);
    DecoratorContext context = mock(DecoratorContext.class);

    SqaleRatingDecorator decorator = new SqaleRatingDecorator();
    decorator.decorate(resource, context);

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

    List<DecoratorContext> contexts = new ArrayList<DecoratorContext>(201);
    contexts.add(file1Context);
    contexts.add(file2Context);
    for (int i = 0; i < 199; i++) {
      DecoratorContext fileContext = mock(DecoratorContext.class);
      when(fileContext.getResource()).thenReturn(File.create("file" + i));
      contexts.add(fileContext);
    }

    when(dirContext.getChildren()).thenReturn(contexts);
View Full Code Here

    dir1 = Directory.create("src/foo1", "foo1");
    dir1.setId(1);
    dir2 = Directory.create("src/foo2", "foo2");
    dir2.setId(2);

    DecoratorContext dir1Context = mock(DecoratorContext.class);
    when(dir1Context.getResource()).thenReturn(dir1);
    DecoratorContext dir2Context = mock(DecoratorContext.class);
    when(dir2Context.getResource()).thenReturn(dir2);

    when(moduleContext.getChildren()).thenReturn(Arrays.asList(dir1Context, dir2Context));

  }
View Full Code Here

TOP

Related Classes of org.sonar.api.batch.DecoratorContext

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.