Skip to content

Commit

Permalink
NO-JIRA Fix code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-geoffroy-sonarsource committed Jul 28, 2023
1 parent 6785fea commit e756f1b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Sonar Plugin API
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.api.issue.impact;

import javax.annotation.ParametersAreNonnullByDefault;

Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ public void testSimpleSetGet() {
rule.setStatus(RuleStatus.READY);
assertThat(rule.status()).isEqualTo(RuleStatus.READY);

assertSecurityStandards();

rule.setType(RuleType.SECURITY_HOTSPOT);
assertThat(rule.type()).isEqualTo(RuleType.SECURITY_HOTSPOT);

rule.setCleanCodeAttribute(CleanCodeAttribute.FOCUSED);
assertThat(rule.cleanCodeAttribute()).isEqualTo(CleanCodeAttribute.FOCUSED);

DebtRemediationFunction f = mock(DebtRemediationFunction.class);
rule.setDebtRemediationFunction(f);
assertThat(rule.debtRemediationFunction()).isEqualTo(f);

rule.setSeverity("MAJOR");
assertThat(rule.severity()).isEqualTo("MAJOR");

rule.addDefaultImpact(SoftwareQuality.MAINTAINABILITY, Severity.HIGH);
assertThat(rule.defaultImpacts()).hasSize(1).containsEntry(SoftwareQuality.MAINTAINABILITY, Severity.HIGH);

rule.addDescriptionSection(RULE_DESCRIPTION_SECTION);
assertThat(rule.getRuleDescriptionSections()).containsExactly(RULE_DESCRIPTION_SECTION);

rule.addEducationPrincipleKeys("principle1", "principle2", "principle3");
assertThat(rule.educationPrincipleKeys()).containsExactly("principle1", "principle2", "principle3");
}

private void assertSecurityStandards() {
rule.addCwe(12);
rule.addCwe(10);
assertThat(rule.securityStandards()).containsOnly("cwe:10", "cwe:12");
Expand All @@ -129,28 +155,6 @@ public void testSimpleSetGet() {

assertThat(rule.securityStandards())
.contains("owaspAsvs-4.0:1.10.1", "owaspAsvs-4.0:1.11.3", "owaspAsvs-4.0:1.11.4", "owaspAsvs-4.0:1.11.5");

rule.setType(RuleType.SECURITY_HOTSPOT);
assertThat(rule.type()).isEqualTo(RuleType.SECURITY_HOTSPOT);

rule.setCleanCodeAttribute(CleanCodeAttribute.FOCUSED);
assertThat(rule.cleanCodeAttribute()).isEqualTo(CleanCodeAttribute.FOCUSED);

DebtRemediationFunction f = mock(DebtRemediationFunction.class);
rule.setDebtRemediationFunction(f);
assertThat(rule.debtRemediationFunction()).isEqualTo(f);

rule.setSeverity("MAJOR");
assertThat(rule.severity()).isEqualTo("MAJOR");

rule.addDefaultImpact(SoftwareQuality.MAINTAINABILITY, Severity.HIGH);
assertThat(rule.defaultImpacts()).hasSize(1).containsEntry(SoftwareQuality.MAINTAINABILITY, Severity.HIGH);

rule.addDescriptionSection(RULE_DESCRIPTION_SECTION);
assertThat(rule.getRuleDescriptionSections()).containsExactly(RULE_DESCRIPTION_SECTION);

rule.addEducationPrincipleKeys("principle1", "principle2", "principle3");
assertThat(rule.educationPrincipleKeys()).containsExactly("principle1", "principle2", "principle3");
}

@Test
Expand Down

0 comments on commit e756f1b

Please sign in to comment.