@@ -39,7 +39,7 @@ public class SonarLintProfileExporterTest {
39
39
40
40
@ Test
41
41
public void test () {
42
- // S1000 has parameters and is enabled -> should not be in exported rule set
42
+ // S1000 has parameters and is enabled
43
43
Rule ruleS1000 = mock (Rule .class );
44
44
when (ruleS1000 .getKey ()).thenReturn ("S1000" );
45
45
RuleParam ruleParam = mock (RuleParam .class );
@@ -50,52 +50,18 @@ public void test() {
50
50
when (activeRuleS1000 .getRule ()).thenReturn (ruleS1000 );
51
51
when (activeRuleS1000 .getSeverity ()).thenReturn (RulePriority .BLOCKER );
52
52
53
- // S1001 is a template rule and is enabled -> should not be in exported rule set
53
+ // S1001 is a SonarLint rule and disabled -> should be disabled in exported rule set
54
54
Rule ruleS1001 = mock (Rule .class );
55
55
when (ruleS1001 .getKey ()).thenReturn ("S1001" );
56
56
when (ruleS1001 .getParams ()).thenReturn (ImmutableList .<RuleParam >of ());
57
- Rule baseTemplateRule = mock (Rule .class );
58
- when (ruleS1001 .getTemplate ()).thenReturn (baseTemplateRule );
57
+ when (ruleS1001 .getTemplate ()).thenReturn (null );
59
58
when (ruleS1001 .getSeverity ()).thenReturn (RulePriority .MAJOR );
60
- org .sonar .api .rules .ActiveRule activeRuleS1001 = mock (ActiveRule .class );
61
- when (activeRuleS1001 .getRule ()).thenReturn (ruleS1001 );
62
- when (activeRuleS1001 .getSeverity ()).thenReturn (RulePriority .BLOCKER );
63
-
64
- // S1002 is a SonarLint rule and disabled -> should be disabled in exported rule set
65
- Rule ruleS1002 = mock (Rule .class );
66
- when (ruleS1002 .getKey ()).thenReturn ("S1002" );
67
- when (ruleS1002 .getParams ()).thenReturn (ImmutableList .<RuleParam >of ());
68
- when (ruleS1002 .getTemplate ()).thenReturn (null );
69
- when (ruleS1002 .getSeverity ()).thenReturn (RulePriority .MAJOR );
70
-
71
- // S1003 is a SonarLint rule and enabled at default severity -> should not be in exported rule set
72
- Rule ruleS1003 = mock (Rule .class );
73
- when (ruleS1003 .getKey ()).thenReturn ("S1003" );
74
- when (ruleS1003 .getParams ()).thenReturn (ImmutableList .<RuleParam >of ());
75
- when (ruleS1003 .getTemplate ()).thenReturn (null );
76
- when (ruleS1003 .getSeverity ()).thenReturn (RulePriority .MAJOR );
77
- org .sonar .api .rules .ActiveRule activeRuleS1003 = mock (ActiveRule .class );
78
- when (activeRuleS1003 .getRule ()).thenReturn (ruleS1003 );
79
- when (activeRuleS1003 .getSeverity ()).thenReturn (RulePriority .MAJOR );
80
-
81
- // S1004 is a SonarLint rule and enabled at different severity -> should be in exported rule set
82
- Rule ruleS1004 = mock (Rule .class );
83
- when (ruleS1004 .getKey ()).thenReturn ("S1004" );
84
- when (ruleS1004 .getParams ()).thenReturn (ImmutableList .<RuleParam >of ());
85
- when (ruleS1004 .getTemplate ()).thenReturn (null );
86
- when (ruleS1004 .getSeverity ()).thenReturn (RulePriority .MAJOR );
87
- org .sonar .api .rules .ActiveRule activeRuleS1004 = mock (ActiveRule .class );
88
- when (activeRuleS1004 .getRule ()).thenReturn (ruleS1004 );
89
- when (activeRuleS1004 .getSeverity ()).thenReturn (RulePriority .BLOCKER );
90
59
91
60
Set <String > allRules = ImmutableSet .of (
92
61
ruleS1000 .getKey (),
93
- ruleS1001 .getKey (),
94
- ruleS1002 .getKey (),
95
- ruleS1003 .getKey (),
96
- ruleS1004 .getKey ());
62
+ ruleS1001 .getKey ());
97
63
CSharpSonarRulesDefinition csharpRulesDefinition = mock (CSharpSonarRulesDefinition .class );
98
- when (csharpRulesDefinition .parameterlessRuleKeys ()).thenReturn (allRules );
64
+ when (csharpRulesDefinition .allRuleKeys ()).thenReturn (allRules );
99
65
100
66
SonarLintProfileExporter exporter = new SonarLintProfileExporter (csharpRulesDefinition );
101
67
assertThat (exporter .getKey ()).isEqualTo ("sonarlint-vs-cs" );
@@ -104,19 +70,14 @@ public void test() {
104
70
105
71
StringWriter writer = new StringWriter ();
106
72
RulesProfile rulesProfile = mock (RulesProfile .class );
107
- when (rulesProfile .getActiveRulesByRepository (CSharpPlugin .REPOSITORY_KEY )).thenReturn (
108
- ImmutableList .of (
109
- activeRuleS1000 ,
110
- activeRuleS1001 ,
111
- activeRuleS1003 ,
112
- activeRuleS1004 ));
73
+ when (rulesProfile .getActiveRulesByRepository (CSharpPlugin .REPOSITORY_KEY )).thenReturn (ImmutableList .of (activeRuleS1000 ));
113
74
exporter .exportProfile (rulesProfile , writer );
114
75
assertThat (writer .toString ()).isEqualTo (
115
76
"<?xml version=\" 1.0\" encoding=\" utf-8\" ?>\r \n " +
116
77
"<RuleSet Name=\" Rules for SonarLint\" Description=\" This rule set was automatically generated from SonarQube.\" ToolsVersion=\" 14.0\" >\r \n " +
117
78
" <Rules AnalyzerId=\" SonarLint.CSharp\" RuleNamespace=\" SonarLint.CSharp\" >\r \n " +
118
- " <Rule Id=\" S1004 \" Action=\" Warning\" />\r \n " +
119
- " <Rule Id=\" S1002 \" Action=\" None\" />\r \n " +
79
+ " <Rule Id=\" S1000 \" Action=\" Warning\" />\r \n " +
80
+ " <Rule Id=\" S1001 \" Action=\" None\" />\r \n " +
120
81
" </Rules>\r \n " +
121
82
"</RuleSet>\r \n " );
122
83
}
0 commit comments