diff options
Diffstat (limited to 'server/sonar-webserver-core')
5 files changed, 92 insertions, 56 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGenerator.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGenerator.java index 08652f93ee4..9c49029690f 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGenerator.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGenerator.java @@ -21,6 +21,8 @@ package org.sonar.server.rule; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import org.elasticsearch.common.util.set.Sets; import org.jetbrains.annotations.Nullable; import org.sonar.api.server.rule.Context; import org.sonar.api.server.rule.RuleDescriptionSection; @@ -29,25 +31,42 @@ import org.sonar.core.util.UuidFactory; import org.sonar.db.rule.RuleDescriptionSectionContextDto; import org.sonar.db.rule.RuleDescriptionSectionDto; -import static java.util.stream.Collectors.toSet; +import static org.sonar.api.rules.RuleType.*; public class AdvancedRuleDescriptionSectionsGenerator implements RuleDescriptionSectionsGenerator { private final UuidFactory uuidFactory; + private final LegacyIssueRuleDescriptionSectionsGenerator legacyIssueRuleDescriptionSectionsGenerator; - public AdvancedRuleDescriptionSectionsGenerator(UuidFactory uuidFactory) { + public AdvancedRuleDescriptionSectionsGenerator(UuidFactory uuidFactory, LegacyIssueRuleDescriptionSectionsGenerator legacyIssueRuleDescriptionSectionsGenerator) { this.uuidFactory = uuidFactory; + this.legacyIssueRuleDescriptionSectionsGenerator = legacyIssueRuleDescriptionSectionsGenerator; } @Override public boolean isGeneratorForRule(RulesDefinition.Rule rule) { - return !rule.ruleDescriptionSections().isEmpty(); + return !rule.ruleDescriptionSections().isEmpty() && skipHotspotRulesForSonar16635(rule); + } + + private static boolean skipHotspotRulesForSonar16635(RulesDefinition.Rule rule) { + return !SECURITY_HOTSPOT.equals(rule.type()); } @Override public Set<RuleDescriptionSectionDto> generateSections(RulesDefinition.Rule rule) { - return rule.ruleDescriptionSections().stream() + Set<RuleDescriptionSectionDto> advancedSections = rule.ruleDescriptionSections().stream() .map(this::toRuleDescriptionSectionDto) - .collect(toSet()); + .collect(Collectors.toSet()); + return addLegacySectionToAdvancedSections(advancedSections, rule); + } + + /** + * This was done to preserve backward compatibility with SonarLint until they stop using htmlDesc field in api/rules/[show|search] endpoints, see SONAR-16635 + * @deprecated the method should be removed once SonarLint supports rules.descriptionSections fields, I.E in 10.x + */ + @Deprecated(since = "9.6", forRemoval = true) + private Set<RuleDescriptionSectionDto> addLegacySectionToAdvancedSections(Set<RuleDescriptionSectionDto> advancedSections, RulesDefinition.Rule rule) { + Set<RuleDescriptionSectionDto> legacySection = legacyIssueRuleDescriptionSectionsGenerator.generateSections(rule); + return Sets.union(advancedSections, legacySection); } private RuleDescriptionSectionDto toRuleDescriptionSectionDto(RuleDescriptionSection section) { diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGenerator.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGenerator.java index d0c93c7fdbc..e2d5675d236 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGenerator.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGenerator.java @@ -35,6 +35,7 @@ import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; import static org.sonar.api.server.rule.RuleDescriptionSection.RuleDescriptionSectionKeys.ASSESS_THE_PROBLEM_SECTION_KEY; import static org.sonar.api.server.rule.RuleDescriptionSection.RuleDescriptionSectionKeys.HOW_TO_FIX_SECTION_KEY; import static org.sonar.api.server.rule.RuleDescriptionSection.RuleDescriptionSectionKeys.ROOT_CAUSE_SECTION_KEY; +import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection; public class LegacyHotspotRuleDescriptionSectionsGenerator implements RuleDescriptionSectionsGenerator { private final UuidFactory uuidFactory; @@ -45,7 +46,9 @@ public class LegacyHotspotRuleDescriptionSectionsGenerator implements RuleDescri @Override public boolean isGeneratorForRule(RulesDefinition.Rule rule) { - return SECURITY_HOTSPOT.equals(rule.type()) && rule.ruleDescriptionSections().isEmpty(); + // To prevent compatibility issues with SonarLint, this Generator is used for all hotspots rules, regardless of if they expose advanced sections or not. See SONAR-16635. + // In the future, the generator should not be used for advanced rules (add condition && rule.ruleDescriptionSections().isEmpty()) + return SECURITY_HOTSPOT.equals(rule.type()); } @Override @@ -65,6 +68,9 @@ public class LegacyHotspotRuleDescriptionSectionsGenerator implements RuleDescri } private Set<RuleDescriptionSectionDto> generateSections(String descriptionInHtml) { + if (descriptionInHtml.isEmpty()) { + return emptySet(); + } String[] split = extractSection("", descriptionInHtml); String remainingText = split[0]; String ruleDescriptionSection = split[1]; @@ -101,7 +107,10 @@ public class LegacyHotspotRuleDescriptionSectionsGenerator implements RuleDescri RuleDescriptionSectionDto assessSection = createSection(ASSESS_THE_PROBLEM_SECTION_KEY, askSection, sensitiveSection, noncompliantSection); RuleDescriptionSectionDto fixSection = createSection(HOW_TO_FIX_SECTION_KEY, recommendedSection, compliantSection, seeSection); - return Stream.of(rootSection, assessSection, fixSection) + // For backward compatibility with SonarLint, see SONAR-16635. Should be removed in 10.x + RuleDescriptionSectionDto defaultSection = createDefaultRuleDescriptionSection(uuidFactory.create(), descriptionInHtml); + + return Stream.of(rootSection, assessSection, fixSection, defaultSection) .filter(Objects::nonNull) .collect(Collectors.toSet()); } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGeneratorTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGeneratorTest.java index 08c4a4f4df8..b2c4425606a 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGeneratorTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/AdvancedRuleDescriptionSectionsGeneratorTest.java @@ -91,65 +91,72 @@ public class AdvancedRuleDescriptionSectionsGeneratorTest { @Mock private RulesDefinition.Rule rule; + @Mock + private RuleDescriptionSectionDto LEGACY_SECTION; + + @Mock + private LegacyIssueRuleDescriptionSectionsGenerator legacyIssueRuleDescriptionSectionsGenerator; + @InjectMocks private AdvancedRuleDescriptionSectionsGenerator generator; @Before public void before() { when(uuidFactory.create()).thenReturn(UUID_1).thenReturn(UUID_2); + when(legacyIssueRuleDescriptionSectionsGenerator.generateSections(rule)).thenReturn(Set.of(LEGACY_SECTION)); } @Test - public void generateSections_whenOneSection_createsOneSections() { + public void generateSections_whenOneSection_createsOneSectionAndDefault() { when(rule.ruleDescriptionSections()).thenReturn(List.of(SECTION_1)); Set<RuleDescriptionSectionDto> ruleDescriptionSectionDtos = generator.generateSections(rule); assertThat(ruleDescriptionSectionDtos) .usingRecursiveFieldByFieldElementComparator() - .containsOnly(EXPECTED_SECTION_1); + .containsExactlyInAnyOrder(EXPECTED_SECTION_1, LEGACY_SECTION); } @Test - public void generateSections_whenTwoSections_createsTwoSections() { + public void generateSections_whenTwoSections_createsTwoSectionsAndDefault() { when(rule.ruleDescriptionSections()).thenReturn(List.of(SECTION_1, SECTION_2)); Set<RuleDescriptionSectionDto> ruleDescriptionSectionDtos = generator.generateSections(rule); assertThat(ruleDescriptionSectionDtos) .usingRecursiveFieldByFieldElementComparator() - .containsExactlyInAnyOrder(EXPECTED_SECTION_1, EXPECTED_SECTION_2); + .containsExactlyInAnyOrder(EXPECTED_SECTION_1, EXPECTED_SECTION_2, LEGACY_SECTION); } @Test - public void generateSections_whenTwoContextSpecificSections_createsTwoSections() { + public void generateSections_whenTwoContextSpecificSections_createsTwoSectionsAndDefault() { when(rule.ruleDescriptionSections()).thenReturn(List.of(SECTION_3_WITH_CTX_1, SECTION_3_WITH_CTX_2)); Set<RuleDescriptionSectionDto> ruleDescriptionSectionDtos = generator.generateSections(rule); assertThat(ruleDescriptionSectionDtos) .usingRecursiveFieldByFieldElementComparator() - .containsExactlyInAnyOrder(EXPECTED_SECTION_3_WITH_CTX_1, EXPECTED_SECTION_3_WITH_CTX_2); + .containsExactlyInAnyOrder(EXPECTED_SECTION_3_WITH_CTX_1, EXPECTED_SECTION_3_WITH_CTX_2, LEGACY_SECTION); } @Test - public void generateSections_whenContextSpecificSectionsAndNonContextSpecificSection_createsTwoSections() { + public void generateSections_whenContextSpecificSectionsAndNonContextSpecificSection_createsTwoSectionsAndDefault() { when(rule.ruleDescriptionSections()).thenReturn(List.of(SECTION_1, SECTION_3_WITH_CTX_2)); Set<RuleDescriptionSectionDto> ruleDescriptionSectionDtos = generator.generateSections(rule); assertThat(ruleDescriptionSectionDtos) .usingRecursiveFieldByFieldElementComparator() - .containsExactlyInAnyOrder(EXPECTED_SECTION_1, EXPECTED_SECTION_3_WITH_CTX_2); + .containsExactlyInAnyOrder(EXPECTED_SECTION_1, EXPECTED_SECTION_3_WITH_CTX_2, LEGACY_SECTION); } @Test - public void generateSections_whenNoSections_returnsEmptySet() { + public void generateSections_whenNoSections_returnsDefault() { when(rule.ruleDescriptionSections()).thenReturn(emptyList()); Set<RuleDescriptionSectionDto> ruleDescriptionSectionDtos = generator.generateSections(rule); - assertThat(ruleDescriptionSectionDtos).isEmpty(); + assertThat(ruleDescriptionSectionDtos).containsOnly(LEGACY_SECTION); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java index 6308f481229..dd4914f6d50 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/LegacyHotspotRuleDescriptionSectionsGeneratorTest.java @@ -19,20 +19,16 @@ */ package org.sonar.server.rule; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.Map; import java.util.Set; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.core.util.UuidFactory; import org.sonar.db.rule.RuleDescriptionSectionDto; +import org.sonar.markdown.Markdown; import static java.util.stream.Collectors.toMap; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,7 +36,6 @@ import static org.sonar.api.server.rule.RuleDescriptionSection.RuleDescriptionSe import static org.sonar.api.server.rule.RuleDescriptionSection.RuleDescriptionSectionKeys.HOW_TO_FIX_SECTION_KEY; import static org.sonar.api.server.rule.RuleDescriptionSection.RuleDescriptionSectionKeys.ROOT_CAUSE_SECTION_KEY; -@RunWith(DataProviderRunner.class) public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { /* @@ -84,6 +79,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { + " @CrossOrigin(origins = \"http://domain2.com\") // Questionable\n" + " @RequestMapping(value = \"/test1\")\n" + " public ResponseEntity<String> test1() {\n" + " return ResponseEntity.ok().body(\"ok\");\n" + " }\n" + "}\n" + "</pre>\n"; + private static final String DEFAULT_SECTION_KEY = "default"; + private final UuidFactory uuidFactory = mock(UuidFactory.class); private final RulesDefinition.Rule rule = mock(RulesDefinition.Rule.class); @@ -114,21 +111,17 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { } @Test - @UseDataProvider("descriptionsWithoutTitles") - public void parse_to_risk_description_fields_when_desc_contains_no_section(String description) { - when(rule.htmlDescription()).thenReturn(description); + public void parse_to_risk_description_fields_when_desc_contains_no_section() { + String descriptionWithoutTitles = "description without titles"; + when(rule.htmlDescription()).thenReturn(descriptionWithoutTitles); Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); - assertThat(results).hasSize(1); - RuleDescriptionSectionDto uniqueSection = results.iterator().next(); - assertThat(uniqueSection.getKey()).isEqualTo(ROOT_CAUSE_SECTION_KEY); - assertThat(uniqueSection.getContent()).isEqualTo(description); - } + Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); + assertThat(sectionKeyToContent).hasSize(2) + .containsEntry(ROOT_CAUSE_SECTION_KEY, descriptionWithoutTitles) + .containsEntry(DEFAULT_SECTION_KEY, rule.htmlDescription()); - @DataProvider - public static Object[][] descriptionsWithoutTitles() { - return new Object[][] {{randomAlphabetic(123)}, {"bar\n" + "acme\n" + "foo"}}; } @Test @@ -138,7 +131,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); - assertThat(sectionKeyToContent).hasSize(2) + assertThat(sectionKeyToContent).hasSize(3) + .containsEntry(DEFAULT_SECTION_KEY, rule.htmlDescription()) .containsEntry(ASSESS_THE_PROBLEM_SECTION_KEY, ASKATRISK) .containsEntry(HOW_TO_FIX_SECTION_KEY, RECOMMENTEDCODINGPRACTICE); } @@ -151,7 +145,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); - assertThat(sectionKeyToContent).hasSize(2) + assertThat(sectionKeyToContent).hasSize(3) + .containsEntry(DEFAULT_SECTION_KEY, rule.htmlDescription()) .containsEntry(ROOT_CAUSE_SECTION_KEY, DESCRIPTION) .containsEntry(HOW_TO_FIX_SECTION_KEY, RECOMMENTEDCODINGPRACTICE); } @@ -163,7 +158,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); - assertThat(sectionKeyToContent).hasSize(2) + assertThat(sectionKeyToContent).hasSize(3) + .containsEntry(DEFAULT_SECTION_KEY, rule.htmlDescription()) .containsEntry(ROOT_CAUSE_SECTION_KEY, DESCRIPTION) .containsEntry(ASSESS_THE_PROBLEM_SECTION_KEY, ASKATRISK); } @@ -175,7 +171,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); - assertThat(sectionKeyToContent).hasSize(3) + assertThat(sectionKeyToContent).hasSize(4) + .containsEntry(DEFAULT_SECTION_KEY, rule.htmlDescription()) .containsEntry(ROOT_CAUSE_SECTION_KEY, DESCRIPTION) .containsEntry(ASSESS_THE_PROBLEM_SECTION_KEY, NONCOMPLIANTCODE) .containsEntry(HOW_TO_FIX_SECTION_KEY, COMPLIANTCODE); @@ -188,7 +185,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); - assertThat(sectionKeyToContent).hasSize(3) + assertThat(sectionKeyToContent).hasSize(4) + .containsEntry(DEFAULT_SECTION_KEY, rule.htmlDescription()) .containsEntry(ROOT_CAUSE_SECTION_KEY, DESCRIPTION) .containsEntry(ASSESS_THE_PROBLEM_SECTION_KEY, NONCOMPLIANTCODE) .containsEntry(HOW_TO_FIX_SECTION_KEY, RECOMMENTEDCODINGPRACTICE + SEE); @@ -201,7 +199,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); - assertThat(sectionKeyToContent).hasSize(3) + assertThat(sectionKeyToContent).hasSize(4) + .containsEntry(DEFAULT_SECTION_KEY, rule.htmlDescription()) .containsEntry(ROOT_CAUSE_SECTION_KEY, DESCRIPTION) .containsEntry(ASSESS_THE_PROBLEM_SECTION_KEY, ASKATRISK + SENSITIVECODE) .containsEntry(HOW_TO_FIX_SECTION_KEY, RECOMMENTEDCODINGPRACTICE + SEE); @@ -225,7 +224,8 @@ public class LegacyHotspotRuleDescriptionSectionsGeneratorTest { Set<RuleDescriptionSectionDto> results = generator.generateSections(rule); Map<String, String> sectionKeyToContent = results.stream().collect(toMap(RuleDescriptionSectionDto::getKey, RuleDescriptionSectionDto::getContent)); - assertThat(sectionKeyToContent).hasSize(3) + assertThat(sectionKeyToContent).hasSize(4) + .containsEntry(DEFAULT_SECTION_KEY, Markdown.convertToHtml(rule.markdownDescription())) .containsEntry(ROOT_CAUSE_SECTION_KEY, ruleDescription + "<br/>" + "<h2>Exceptions</h2>" + exceptionsContent + "<br/>") diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RuleDescriptionSectionsGeneratorsTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RuleDescriptionSectionsGeneratorsTest.java index 9687ab4f7a1..03ad1283b71 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RuleDescriptionSectionsGeneratorsTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RuleDescriptionSectionsGeneratorsTest.java @@ -67,6 +67,8 @@ public class RuleDescriptionSectionsGeneratorsTest { private static final RuleDescriptionSectionDto DEFAULT_MD_SECTION_1 = RuleDescriptionSectionDto.builder().uuid(UUID_1).key("default").content(MD_CONTENT).build(); private static final RuleDescriptionSectionDto HTML_SECTION_1 = RuleDescriptionSectionDto.builder().uuid(UUID_1).key(KEY_1).content(HTML_CONTENT).build(); private static final RuleDescriptionSectionDto HTML_SECTION_2 = RuleDescriptionSectionDto.builder().uuid(UUID_2).key(KEY_2).content(HTML_CONTENT).build(); + private static final RuleDescriptionSectionDto LEGACY_HTML_SECTION = RuleDescriptionSectionDto.builder().uuid(UUID_2).key("default").content(HTML_CONTENT).build(); + private static final RuleDescriptionSectionDto LEGACY_MD_SECTION = RuleDescriptionSectionDto.builder().uuid(UUID_2).key("default").content(MD_CONTENT).build(); @Parameterized.Parameters(name = "{index} = {0}") public static List<RuleDescriptionGeneratorTestData> testData() { @@ -80,21 +82,20 @@ public class RuleDescriptionSectionsGeneratorsTest { aRuleOfType(VULNERABILITY).html(HTML_CONTENT).md(MD_CONTENT).expectedGenerator(LEGACY_ISSUE).addExpectedSection(DEFAULT_HTML_SECTION_1).build(), // HOTSPOT aRuleOfType(SECURITY_HOTSPOT).html(null).md(null).expectedGenerator(LEGACY_HOTSPOT).build(), - aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(null).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_HTML_HOTSPOT_SECTION_1).build(), - aRuleOfType(SECURITY_HOTSPOT).html(null).md(MD_CONTENT).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_MD_HOTSPOT_SECTION_1).build(), - aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(MD_CONTENT).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_HTML_HOTSPOT_SECTION_1).build(), + aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(null).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_HTML_HOTSPOT_SECTION_1).addExpectedSection(LEGACY_HTML_SECTION).build(), + aRuleOfType(SECURITY_HOTSPOT).html(null).md(MD_CONTENT).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_MD_HOTSPOT_SECTION_1).addExpectedSection(LEGACY_MD_SECTION).build(), + aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(MD_CONTENT).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_HTML_HOTSPOT_SECTION_1).addExpectedSection(LEGACY_HTML_SECTION).build(), // ADVANCED RULES aRuleOfType(BUG).html(null).md(null).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build(), - aRuleOfType(BUG).html(HTML_CONTENT).md(null).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build(), - aRuleOfType(BUG).html(null).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build(), - aRuleOfType(BUG).html(HTML_CONTENT).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build(), - aRuleOfType(BUG).html(HTML_CONTENT).md(MD_CONTENT).addSection(SECTION_1).addSection(SECTION_2).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1) - .addExpectedSection( - HTML_SECTION_2).build(), - aRuleOfType(SECURITY_HOTSPOT).html(null).md(null).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build(), - aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(null).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build(), - aRuleOfType(SECURITY_HOTSPOT).html(null).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build(), - aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).build() + aRuleOfType(BUG).html(HTML_CONTENT).md(null).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).addExpectedSection(LEGACY_HTML_SECTION).build(), + aRuleOfType(BUG).html(null).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).addExpectedSection(LEGACY_MD_SECTION).build(), + aRuleOfType(BUG).html(HTML_CONTENT).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(ADVANCED_RULE).addExpectedSection(HTML_SECTION_1).addExpectedSection(LEGACY_HTML_SECTION).build(), + aRuleOfType(BUG).html(HTML_CONTENT).md(MD_CONTENT).addSection(SECTION_1).addSection(SECTION_2).expectedGenerator(ADVANCED_RULE) + .addExpectedSection(HTML_SECTION_1).addExpectedSection(HTML_SECTION_2).addExpectedSection(LEGACY_HTML_SECTION).build(), + aRuleOfType(SECURITY_HOTSPOT).html(null).md(null).addSection(SECTION_1).expectedGenerator(LEGACY_HOTSPOT).build(), + aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(null).addSection(SECTION_1).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_HTML_HOTSPOT_SECTION_1).addExpectedSection(LEGACY_HTML_SECTION).build(), + aRuleOfType(SECURITY_HOTSPOT).html(null).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_MD_HOTSPOT_SECTION_1).addExpectedSection(LEGACY_MD_SECTION).build(), + aRuleOfType(SECURITY_HOTSPOT).html(HTML_CONTENT).md(MD_CONTENT).addSection(SECTION_1).expectedGenerator(LEGACY_HOTSPOT).addExpectedSection(DEFAULT_HTML_HOTSPOT_SECTION_1).addExpectedSection(LEGACY_HTML_SECTION).build() ); } @@ -103,9 +104,9 @@ public class RuleDescriptionSectionsGeneratorsTest { private final RuleDescriptionGeneratorTestData testData; - private final RuleDescriptionSectionsGenerator advancedRuleDescriptionSectionsGenerator = new AdvancedRuleDescriptionSectionsGenerator(uuidFactory); private final RuleDescriptionSectionsGenerator legacyHotspotRuleDescriptionSectionsGenerator = new LegacyHotspotRuleDescriptionSectionsGenerator(uuidFactory); - private final RuleDescriptionSectionsGenerator legacyIssueRuleDescriptionSectionsGenerator = new LegacyIssueRuleDescriptionSectionsGenerator(uuidFactory); + private final LegacyIssueRuleDescriptionSectionsGenerator legacyIssueRuleDescriptionSectionsGenerator = new LegacyIssueRuleDescriptionSectionsGenerator(uuidFactory); + private final RuleDescriptionSectionsGenerator advancedRuleDescriptionSectionsGenerator = new AdvancedRuleDescriptionSectionsGenerator(uuidFactory, legacyIssueRuleDescriptionSectionsGenerator); Map<RuleDescriptionSectionGeneratorIdentifier, RuleDescriptionSectionsGenerator> idToGenerator = ImmutableMap.<RuleDescriptionSectionGeneratorIdentifier, RuleDescriptionSectionsGenerator>builder() .put(ADVANCED_RULE, advancedRuleDescriptionSectionsGenerator) |