-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. compatibility with SonarQube 9.X version 2. fixed import java issue failed issue
- Loading branch information
Showing
10 changed files
with
163 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...rc/test/java/com/github/sonar/next/sonarqube/java/issues/infer/InferReportParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.github.sonar.next.sonarqube.java.issues.infer; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.json.simple.parser.ParseException; | ||
import org.junit.Rule; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.sonar.api.batch.fs.FilePredicate; | ||
import org.sonar.api.batch.fs.FilePredicates; | ||
import org.sonar.api.batch.fs.FileSystem; | ||
import org.sonar.api.batch.fs.InputFile; | ||
import org.sonar.api.batch.fs.internal.DefaultFilePredicates; | ||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | ||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | ||
import org.sonar.api.batch.sensor.SensorContext; | ||
import org.sonar.api.batch.sensor.issue.NewIssueLocation; | ||
import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; | ||
import org.sonar.api.rule.RuleKey; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Objects; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class InferReportParserTest { | ||
|
||
@Rule | ||
public TemporaryFolder temp = new TemporaryFolder(); | ||
|
||
private DefaultFileSystem fs; | ||
private Path moduleBasePath; | ||
|
||
@Mock | ||
SensorContext sensorContext; | ||
|
||
@Mock | ||
FileSystem fileSystem; | ||
private InferReportParser self; | ||
|
||
|
||
@org.junit.jupiter.api.BeforeEach | ||
void setUp() throws IOException { | ||
moduleBasePath = temp.newFolder().toPath(); | ||
fs = new DefaultFileSystem(moduleBasePath); | ||
|
||
MockitoAnnotations.openMocks(this); | ||
self = new InferReportParser(sensorContext); | ||
} | ||
|
||
@org.junit.jupiter.api.AfterEach | ||
void tearDown() { | ||
} | ||
|
||
|
||
@Test | ||
void parseReport() throws IOException, ParseException { | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
File reportFile = new File(Objects.requireNonNull(classLoader.getResource("report_java.json")).getFile()); | ||
File file = new File(Objects.requireNonNull(classLoader.getResource("Hello.java")).getFile()); | ||
|
||
FilePredicates predicates = new DefaultFilePredicates(temp.newFolder().toPath()); | ||
InputFile javaFile = new TestInputFileBuilder("foo", "Hello.java") | ||
.setModuleBaseDir(moduleBasePath) | ||
.setLanguage("java") | ||
.setContents(new String(Files.readAllBytes(file.toPath()))) | ||
.setStatus(InputFile.Status.SAME) | ||
.build(); | ||
|
||
fs.add(javaFile); | ||
|
||
|
||
when(sensorContext.fileSystem()).thenReturn(fs); | ||
when(fileSystem.predicates()).thenReturn(predicates); | ||
|
||
DefaultIssue defaultIssue = mock(DefaultIssue.class); | ||
when(defaultIssue.addFlow(anyIterable())).thenReturn(defaultIssue); | ||
when(defaultIssue.forRule(any(RuleKey.class))).thenReturn(defaultIssue); | ||
when(defaultIssue.at(any(NewIssueLocation.class))).thenReturn(defaultIssue); | ||
when(sensorContext.newIssue()).thenReturn(defaultIssue); | ||
doNothing().when(defaultIssue).save(); | ||
|
||
self.parseReport(reportFile); | ||
|
||
verify(defaultIssue, times(1)).addFlow(anyIterable()); | ||
verify(defaultIssue, times(1)).forRule(any(RuleKey.class)); | ||
verify(defaultIssue, times(1)).at(any(NewIssueLocation.class)); | ||
verify(defaultIssue, times(1)).save(); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
class Hello { | ||
int test() { | ||
String s = null; | ||
return s.length(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"bug_type":"NULL_DEREFERENCE","qualifier":"object `s` last assigned on line 10 could be null and is dereferenced at line 11.","severity":"ERROR","line":11,"column":-1,"procedure":"Hello.test():int","procedure_start_line":9,"file":"Hello.java","bug_trace":[{"level":0,"filename":"Hello.java","line_number":9,"column_number":-1,"description":"start of procedure test()"},{"level":0,"filename":"Hello.java","line_number":10,"column_number":-1,"description":""},{"level":0,"filename":"Hello.java","line_number":11,"column_number":-1,"description":""}],"key":"Hello.java|test|NULL_DEREFERENCE","node_key":"c8c6b1f0f8892a67c957e59c27c08c9f","hash":"f21e4baf23b546897421c6f1f10c2e78","bug_type_hum":"Null Dereference"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters