SeverityPieChart { public PieChartModel create(final Report report) { PieChartModel model = new PieChartModel(Messages.Severities_Name()); ImmutableSet<Severity> predefinedSeverities = Severity.getPredefinedValues(); for (Severity severity : predefinedSeverities) { int total = report.getSizeOf(severity); if (total > 0 || !severity.equals(Severity.ERROR)) { model.add(new PieData(LocalizedSeverity.getLocalizedString(severity), total), SeverityPalette.getColor(severity)); } } return model; }  PieChartModel create(final Report report);  }
@Test void shouldCreateChartFromEmptyReport() { SeverityPieChart severityPieChart = new SeverityPieChart(); PieChartModel pieChartModel = severityPieChart.create(createReport(0, 0, 0, 0)); List<PieData> data = pieChartModel.getData(); assertThat(data.get(0)).isEqualTo(new PieData("High", 0)); assertThat(data.get(1)).isEqualTo(new PieData("Normal", 0)); assertThat(data.get(2)).isEqualTo(new PieData("Low", 0)); }
@Test void shouldCreateChartFromReportWithOneError() { SeverityPieChart severityPieChart = new SeverityPieChart(); PieChartModel pieChartModel = severityPieChart.create(createReport(1, 0, 0, 0)); List<PieData> data = pieChartModel.getData(); assertThat(data.get(0)).isEqualTo(new PieData("Error", 1)); assertThat(data.get(1)).isEqualTo(new PieData("High", 0)); assertThat(data.get(2)).isEqualTo(new PieData("Normal", 0)); assertThat(data.get(3)).isEqualTo(new PieData("Low", 0)); }
@Test void shouldCreateChartFromSimpleReport() { SeverityPieChart severityPieChart = new SeverityPieChart(); PieChartModel pieChartModel = severityPieChart.create(createReport(1, 1, 1, 1)); List<PieData> data = pieChartModel.getData(); assertThat(data.get(0)).isEqualTo(new PieData("Error", 1)); assertThat(data.get(1)).isEqualTo(new PieData("High", 1)); assertThat(data.get(2)).isEqualTo(new PieData("Normal", 1)); assertThat(data.get(3)).isEqualTo(new PieData("Low", 1)); }