@Test
  public void return_empty_list_when_no_metrics_neither_measure_computers() throws Exception {
    ComputationStep underTest = new FeedMeasureComputers(holder);
    underTest.execute();

    assertThat(holder.getMeasureComputers()).isEmpty();
  }
  @Test
  public void sort_computers() throws Exception {
    MeasureComputer.Implementation implementation1 = mock(MeasureComputer.Implementation.class);
    MeasureComputer.Implementation implementation2 = mock(MeasureComputer.Implementation.class);
    MeasureComputer.Implementation implementation3 = mock(MeasureComputer.Implementation.class);

    MeasureComputerProvider[] providers =
        new MeasureComputerProvider[] {
          // Should be the last to be executed
          new NewMeasureComputerProvider(array(NEW_METRIC_3), array(NEW_METRIC_4), implementation3),
          // Should be the first to be executed
          new NewMeasureComputerProvider(array(NEW_METRIC_1), array(NEW_METRIC_2), implementation1),
          // Should be the second to be executed
          new NewMeasureComputerProvider(array(NEW_METRIC_2), array(NEW_METRIC_3), implementation2)
        };

    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), providers);
    underTest.execute();

    List<MeasureComputer> computers = newArrayList(holder.getMeasureComputers());
    assertThat(computers).hasSize(3);
    assertThat(computers.get(0).getImplementation()).isEqualTo(implementation1);
    assertThat(computers.get(1).getImplementation()).isEqualTo(implementation2);
    assertThat(computers.get(2).getImplementation()).isEqualTo(implementation3);
  }
Пример #3
0
  @Test
  public void support_plugin_metrics_as_input_metrics() throws Exception {
    MeasureComputer[] computers =
        new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2))};
    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), computers);
    underTest.execute();

    assertThat(holder.getMeasureComputers()).hasSize(1);
  }
Пример #4
0
  @Test
  public void fail_with_ISE_when_output_metric_is_a_core_metric() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Metric 'ncloc' cannot be used as an output metric as it's a core metric");

    MeasureComputer[] computers =
        new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array(NCLOC_KEY))};
    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), computers);
    underTest.execute();
  }
Пример #5
0
  @Test
  public void fail_with_ISE_when_output_metric_is_not_define_by_plugin() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage(
        "Metric 'unknown' cannot be used as an output metric as no plugin declare this metric");

    MeasureComputer[] computers =
        new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array("unknown"))};
    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), computers);
    underTest.execute();
  }
  @Test
  public void support_plugin_metrics_as_input_metrics() throws Exception {
    MeasureComputer.Implementation implementation = mock(MeasureComputer.Implementation.class);
    MeasureComputerProvider[] providers =
        new MeasureComputerProvider[] {
          new NewMeasureComputerProvider(array(NEW_METRIC_1), array(NEW_METRIC_2), implementation),
        };
    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), providers);
    underTest.execute();

    assertThat(holder.getMeasureComputers()).hasSize(1);
  }
  @Test
  public void support_no_plugin_metrics() throws Exception {
    MeasureComputer.Implementation implementation = mock(MeasureComputer.Implementation.class);
    MeasureComputerProvider[] providers =
        new MeasureComputerProvider[] {
          new NewMeasureComputerProvider(
              array(CoreMetrics.NCLOC_KEY), array(CoreMetrics.COMMENT_LINES_KEY), implementation),
        };
    ComputationStep underTest = new FeedMeasureComputers(holder, providers);
    underTest.execute();

    assertThat(holder.getMeasureComputers()).hasSize(1);
  }
Пример #8
0
  @Test
  public void
      fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric()
          throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage(
        "Metric 'metric1' cannot be used as an output metric as no plugin declare this metric");

    MeasureComputer[] computers =
        new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1))};
    ComputationStep underTest = new FeedMeasureComputers(holder, computers);
    underTest.execute();
  }
  @Test
  public void fail_with_ISE_when_input_metric_is_unknown() throws Exception {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage(
        "Metric 'unknown' cannot be used as an input metric as it's no a core metric and no plugin declare this metric");

    MeasureComputerProvider[] providers =
        new MeasureComputerProvider[] {
          new NewMeasureComputerProvider(
              array("unknown"), array(NEW_METRIC_4), mock(MeasureComputer.Implementation.class)),
        };

    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), providers);
    underTest.execute();
  }
Пример #10
0
  @Test
  public void sort_computers() throws Exception {
    // Should be the last to be executed
    MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
    // Should be the first to be executed
    MeasureComputer measureComputer2 = newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2));
    // Should be the second to be executed
    MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
    MeasureComputer[] computers =
        new MeasureComputer[] {measureComputer1, measureComputer2, measureComputer3};

    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), computers);
    underTest.execute();

    List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
    assertThat(result).hasSize(3);
    assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
    assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
    assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
  }
Пример #11
0
  @Test
  public void
      fail_with_IAE_when_creating_measure_computer_definition_without_using_the_builder_and_with_invalid_output_metrics()
          throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("At least one output metric must be defined");

    MeasureComputer measureComputer =
        new MeasureComputer() {
          @Override
          public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
            // Create a instance of MeasureComputerDefinition without using the builder
            return new MeasureComputer.MeasureComputerDefinition() {
              @Override
              public Set<String> getInputMetrics() {
                return ImmutableSet.of(NCLOC_KEY);
              }

              @Override
              public Set<String> getOutputMetrics() {
                // Empty output metric is not allowed !
                return Collections.emptySet();
              }
            };
          }

          @Override
          public void compute(MeasureComputerContext context) {
            // Nothing needs to be done as we're only testing metada
          }
        };

    MeasureComputer[] computers = new MeasureComputer[] {measureComputer};
    ComputationStep underTest =
        new FeedMeasureComputers(holder, array(new TestMetrics()), computers);
    underTest.execute();
  }