]> source.dussan.org Git - sonarqube.git/commitdiff
Fix tests
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 20 Apr 2018 09:27:25 +0000 (11:27 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 26 Apr 2018 18:20:52 +0000 (20:20 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/RuleTypeCopier.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java
sonar-scanner-engine/src/test/resources/mediumtest/xoo/sample/externalIssues.json
sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report.json

index 58234a9031aa78a51185da87a6bc3b838c4d88ca..040c88edf97b3d395e8b1b1e3ade475fee938f4b 100644 (file)
@@ -35,6 +35,7 @@ public class RuleTypeCopier extends IssueVisitor {
     if (issue.type() == null) {
       Rule rule = ruleRepository.getByKey(issue.ruleKey());
       if (!rule.isExternal()) {
+        // rule type should never be null for rules created by plugins (non-external rules)
         issue.setType(rule.getType());
       }
     }
index 0cee9bc2a96fe806ac03f2ac78e160107e16c73e..c43f0275b34d7453c5f6d721ea2145070f61e0de 100644 (file)
@@ -113,14 +113,14 @@ public class SensorContextTesterTest {
     assertThat(tester.allExternalIssues()).isEmpty();
     NewExternalIssue newExternalIssue = tester.newExternalIssue();
     newExternalIssue
-      .at(newExternalIssue.newLocation().on(new TestInputFileBuilder("foo", "src/Foo.java").build()))
+      .at(newExternalIssue.newLocation().message("message").on(new TestInputFileBuilder("foo", "src/Foo.java").build()))
       .forRule(RuleKey.of("repo", "rule"))
       .type(RuleType.BUG)
       .severity(Severity.BLOCKER)
       .save();
     newExternalIssue = tester.newExternalIssue();
     newExternalIssue
-      .at(newExternalIssue.newLocation().on(new TestInputFileBuilder("foo", "src/Foo.java").build()))
+      .at(newExternalIssue.newLocation().message("message").on(new TestInputFileBuilder("foo", "src/Foo.java").build()))
       .type(RuleType.BUG)
       .severity(Severity.BLOCKER)
       .forRule(RuleKey.of("repo", "rule"))
index 7f0d15a042060a0d8006e20d759a0e3942aeacb4..4a5e35e96f43fb1cbae45c1ecd258cc11c79506f 100644 (file)
@@ -103,7 +103,7 @@ public class ExternalIssueImporter {
   }
 
   @CheckForNull
-  private NewIssueLocation fillLocation(SensorContext context, NewIssueLocation newLocation, Location location) {
+  private static NewIssueLocation fillLocation(SensorContext context, NewIssueLocation newLocation, Location location) {
     InputFile file = findFile(context, location.filePath);
     if (file != null) {
       newLocation
index 3795ac37146146ac4d9074f18445a5995da922b6..e13e64d6b85d218ac42a9dbeadf8051c1de035ab 100644 (file)
@@ -39,7 +39,7 @@ public class ReportParserTest {
     System.out.println(Paths.get("org/sonar/scanner/externalissue/report.json").toAbsolutePath());
     Report report = parser.parse();
 
-    assertThat(report.issues).hasSize(2);
+    assertThat(report.issues).hasSize(3);
     assertThat(report.issues[0].engineId).isEqualTo("eslint");
     assertThat(report.issues[0].ruleId).isEqualTo("rule1");
     assertThat(report.issues[0].severity).isEqualTo("MAJOR");
@@ -47,10 +47,10 @@ public class ReportParserTest {
     assertThat(report.issues[0].type).isEqualTo("CODE_SMELL");
     assertThat(report.issues[0].primaryLocation.filePath).isEqualTo("file1.js");
     assertThat(report.issues[0].primaryLocation.message).isEqualTo("fix the issue here");
-    assertThat(report.issues[0].primaryLocation.textRange.startColumn).isNull();
+    assertThat(report.issues[0].primaryLocation.textRange.startColumn).isEqualTo(2);
     assertThat(report.issues[0].primaryLocation.textRange.startLine).isEqualTo(1);
-    assertThat(report.issues[0].primaryLocation.textRange.endColumn).isNull();
-    assertThat(report.issues[0].primaryLocation.textRange.endLine).isEqualTo(2);
+    assertThat(report.issues[0].primaryLocation.textRange.endColumn).isEqualTo(4);
+    assertThat(report.issues[0].primaryLocation.textRange.endLine).isEqualTo(3);
     assertThat(report.issues[0].secondaryLocations).isNull();
   }
 
index 4ababc77edb523c60feaf61d2aa963df837312b9..0e50bedd8dc1bf12fab23135057959792f2c0336 100644 (file)
@@ -25,8 +25,7 @@
       "message": "fix the bug here",
       "filePath": "xources/hello/HelloJava.xoo",
       "textRange": {
-        "startLine": 3,
-        "endLine": 3
+        "startLine": 3
       }
     }     
   },
@@ -39,8 +38,7 @@
       "message": "fix the bug here",
       "filePath": "invalidFile",
       "textRange": {
-        "startLine": 3,
-        "endLine": 3
+        "startLine": 3
       }
     }     
   },
index 6eb1024206d11f63d74deb3929d2bebb31a8aae2..06627d7106b3d2f377916433eff6342d9102aed0 100644 (file)
@@ -11,7 +11,9 @@
       "filePath": "file1.js",
       "textRange": {
         "startLine": 1,
-        "endLine": 2
+        "startColumn": 2,
+        "endLine": 3,
+        "endColumn": 4
       }
     }     
   },
       "message": "fix the bug here",
       "filePath": "file2.js",
       "textRange": {
-        "startLine": 3,
-        "endLine": 4
+        "startLine": 3
       }
+    } 
+  },  
+  { 
+    "engineId": "eslint",
+    "ruleId": "rule3",
+    "severity": "MAJOR",
+    "type": "BUG",
+    "primaryLocation": {
+      "message": "fix the bug here",
+      "filePath": "file3.js"
     }     
   }
 ]
 }
-