HealthTrendChart implements TrendChart { @Override public LinesChartModel create(final Iterable<? extends BuildResult<AnalysisBuildResult>> results, final ChartModelConfiguration configuration) { HealthSeriesBuilder builder = new HealthSeriesBuilder(healthDescriptor); LinesDataSet dataSet = builder.createDataSet(configuration, results); LinesChartModel model = new LinesChartModel(); model.setDomainAxisLabels(dataSet.getDomainAxisLabels()); if (healthDescriptor.isEnabled()) { LineSeries healthy = createSeries(Messages.Healthy_Name(), Palette.GREEN); healthy.addAll(dataSet.getSeries(HealthSeriesBuilder.HEALTHY)); LineSeries intermediate = createSeries(Messages.Satisfactory_Name(), Palette.YELLOW); intermediate.addAll(dataSet.getSeries(HealthSeriesBuilder.BETWEEN)); LineSeries unhealthy = createSeries(Messages.Unhealthy_Name(), Palette.RED); unhealthy.addAll(dataSet.getSeries(HealthSeriesBuilder.UNHEALTHY)); model.addSeries(healthy, intermediate, unhealthy); } else { LineSeries total = new LineSeries(Messages.Total_Name(), Palette.YELLOW.getNormal(), StackedMode.SEPARATE_LINES, FilledMode.LINES); total.addAll(dataSet.getSeries(HealthSeriesBuilder.TOTAL)); model.addSeries(total); } return model; } HealthTrendChart(final HealthDescriptor healthDescriptor); @Override LinesChartModel create(final Iterable<? extends BuildResult<AnalysisBuildResult>> results,
            final ChartModelConfiguration configuration);  }
@Test void shouldCreateHealthChart() { HealthDescriptor healthDescriptor = new HealthDescriptor(5, 10, Severity.WARNING_NORMAL); HealthTrendChart chart = new HealthTrendChart(healthDescriptor); List<BuildResult<AnalysisBuildResult>> resultsCheckStyle = createBuildResults(); LinesChartModel model = chart.create(resultsCheckStyle, new ChartModelConfiguration()); assertThatJson(model).node("domainAxisLabels") .isArray().containsExactly("#1", "#2", "#3", "#4"); assertThatJson(model).node("series") .isArray().hasSize(3); assertThat(healthDescriptor.isEnabled()).isTrue(); assertThat(model.getSeries().get(0).getName()).isEqualTo("Excellent"); verifySeries(model, 0, 0, 5, 5, 5); assertThat(model.getSeries().get(1).getName()).isEqualTo("Satisfactory"); verifySeries(model, 1, 0, 0, 5, 5); assertThat(model.getSeries().get(2).getName()).isEqualTo("Failing"); verifySeries(model, 2, 0, 0, 0, 5); }
@Test void shouldCreateFallbackChartIfHealthIsDisabled() { HealthDescriptor healthDescriptor = new HealthDescriptor(-1, -1, Severity.WARNING_NORMAL); HealthTrendChart chart = new HealthTrendChart(healthDescriptor); List<BuildResult<AnalysisBuildResult>> resultsCheckStyle = createBuildResults(); LinesChartModel model = chart.create(resultsCheckStyle, new ChartModelConfiguration()); assertThatJson(model).node("domainAxisLabels") .isArray().containsExactly("#1", "#2", "#3", "#4"); assertThatJson(model).node("series") .isArray().hasSize(1); assertThat(healthDescriptor.isEnabled()).isFalse(); assertThat(model.getSeries().get(0).getName()).isEqualTo("Total (health report disabled)"); verifySeries(model, 0, 0, 5, 10, 15); }