Summary { public String create() { return div(labelProvider.getTitle(analysisResult, !analysisResult.getErrorMessages().isEmpty()), createDescription()) .withId(labelProvider.getId() + "-summary") .renderFormatted(); } Summary(final StaticAnalysisLabelProvider labelProvider, final AnalysisResult result); @VisibleForTesting  Summary(final StaticAnalysisLabelProvider labelProvider, final AnalysisResult result,
            final LabelProviderFactoryFacade facade); String create();  }
@Test @Issue("SECURITY-1373") void shouldSanitizeName() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, Lists.immutable.of("Error 1", "Error 2"), 0); Locale.setDefault(Locale.ENGLISH); LabelProviderFactoryFacade facade = mock(LabelProviderFactoryFacade.class); StaticAnalysisLabelProvider checkStyleLabelProvider = createLabelProvider("checkstyle", "<b>CheckStyle</b> <script>execute</script>"); when(facade.get("checkstyle")).thenReturn(checkStyleLabelProvider); Summary summary = new Summary(checkStyleLabelProvider, analysisResult, facade); setResetReferenceAction(summary, false); String createdHtml = summary.create(); assertThat(createdHtml).contains("<b>CheckStyle</b>"); assertThat(createdHtml).doesNotContain("<script>execute</script>"); }
@Test void shouldShowAggregatedWarnings() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, Lists.immutable.of("Error 1", "Error 2"), 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).contains("<svg class=\"info-page-decorator svg-icon\"><use href=\"/path/to/error\"></use></svg>"); }
@Test void shouldHaveDivWithInfoIcon() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).contains("<svg class=\"info-page-decorator svg-icon\"><use href=\"/path/to/info\"></use></svg>"); }
@Test void shouldHaveCorrectIDsForDivs() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).contains("<div id=\"test-summary\">"); assertThat(createdHtml).contains("id=\"test-title\""); }
@Test void shouldContainNoMessageForToolNames() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).doesNotContain(Messages.Tool_ParticipatingTools("")); }
@Test void shouldContainMessageWithToolNames() { AnalysisResult analysisResult = createAnalysisResult( Maps.fixedSize.of("checkstyle", 15, "pmd", 20), 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).contains(Messages.Tool_ParticipatingTools("CheckStyle, PMD")); }
@Test void shouldContainMessageWithToolNamesIfThereAreNoWarningsFound() { AnalysisResult analysisResult = createAnalysisResult( Maps.fixedSize.of("checkstyle", 0, "pmd", 0), 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).contains("No warnings for"); assertThat(createdHtml).contains(Messages.Tool_ParticipatingTools("CheckStyle, PMD")); }
@Test void shouldContainNoIssuesSinceLabel() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); when(analysisResult.getTotalSize()).thenReturn(0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).containsPattern("No warnings for .* builds"); }
@Test void shouldNotContainNoIssuesSinceLabelWhenTotalIsNotZero() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); when(analysisResult.getTotalSize()).thenReturn(1); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).doesNotContain("No warnings for"); assertThat(createdHtml).contains("<a href=\"test\">One warning</a>"); }
@Test void shouldNotContainNoIssuesSinceLabelWhenBuildIsYounger() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); when(analysisResult.getTotalSize()).thenReturn(0); when(analysisResult.getBuild()).thenReturn(new Build(1)); when(analysisResult.getNoIssuesSinceBuild()).thenReturn(3); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).doesNotContain("No warnings for"); assertThat(createdHtml).contains("No warnings"); }
@Test void shouldContainNewIssues() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 3, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).containsPattern( createWarningsLink("<a href=\"test/new\">.*3 new warnings.*</a>")); }
@Test void shouldNotContainNewIssues() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).doesNotContainPattern( createWarningsLink("<a href=\"test/new\">.* new warnings.*</a>")); }
@Test void shouldContainFixedIssuesLabel() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 5, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).containsPattern( createWarningsLink("<a href=\"test/fixed\">.*5 fixed warnings.*</a>")); }
@Test void shouldNotContainFixedIssuesLabel() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).doesNotContainPattern( createWarningsLink("<a href=\"test/fixed\">.* fixed warnings.*</a>")); }
@Test void shouldContainQualityGateResult() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); when(analysisResult.getQualityGateStatus()).thenReturn(QualityGateStatus.PASSED); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).containsPattern( createWarningsLink( "Quality gate: <img src=\"color\" class=\"icon-blue\" alt=\"Success\" title=\"Success\"> Success")); }
@Test void shouldNotContainQualityGateResult() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); when(analysisResult.getQualityGateStatus()).thenReturn(QualityGateStatus.INACTIVE); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).doesNotContain("Quality gate"); }
@Test void shouldContainReferenceBuild() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).contains("Reference build: <a href=\"absoluteUrl\">Job #15</a>"); }
@Test void shouldNotContainReferenceBuild() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, EMPTY_ERRORS, 0); when(analysisResult.getReferenceBuild()).thenReturn(Optional.empty()); String createdHtml = createSummary(analysisResult).create(); assertThat(createdHtml).doesNotContain("Reference build:"); }
@Test void shouldProvideSummary() { AnalysisResult analysisResult = createAnalysisResult( Maps.fixedSize.of("checkstyle", 15, "pmd", 20), 2, 2, EMPTY_ERRORS, 1); Summary summary = createSummary(analysisResult); String actualSummary = summary.create(); assertThat(actualSummary).contains("CheckStyle, PMD"); assertThat(actualSummary).contains("No warnings for 2 builds"); assertThat(actualSummary).contains("since build <a href=\"../1\" class=\"model-link inside\">1</a>"); assertThat(actualSummary).containsPattern( createWarningsLink("<a href=\"test/new\">.*2 new warnings.*</a>")); assertThat(actualSummary).containsPattern( createWarningsLink("<a href=\"test/fixed\">.*2 fixed warnings.*</a>")); assertThat(actualSummary).contains( "Quality gate: <img src=\"color\" class=\"icon-blue\" alt=\"Success\" title=\"Success\"> Success\n"); assertThat(actualSummary).contains("Reference build: <a href=\"absoluteUrl\">Job #15</a>"); }
@Test void shouldProvideResetAction() { AnalysisResult analysisResult = createAnalysisResult( Maps.fixedSize.of("checkstyle", 15, "pmd", 20), 2, 2, EMPTY_ERRORS, 1); Summary summary = createSummary(analysisResult, true); assertThat(summary.create()).contains( "Quality gate: <img src=\"color\" class=\"icon-blue\" alt=\"Success\" title=\"Success\"> Success " + "<button id=\"test-resetReference\" type=\"button\" class=\"btn btn-outline-primary btn-sm\">Reset quality gate</button>"); }