3636public class PylintIssuesAnalyzerTest {
3737
3838 private static final Logger LOG = Loggers .get (PylintIssuesAnalyzerTest .class );
39+ static final String RESOURCE_DIR = "src/test/resources" ;
3940
4041 @ Test
4142 public void shouldParseCorrectly () {
4243 String resourceName = "/org/sonar/plugins/python/pylint/sample_pylint_output.txt" ;
43- String pathName = getClass ().getResource (resourceName ).getPath ();
4444 String pylintConfigPath = null ;
4545 String pylintPath = null ;
46- List <String > lines = readFile (pathName );
46+ List <String > lines = readFile (resourceName );
4747 List <Issue > issues = analyzer (pylintPath , pylintConfigPath ).parseOutput (lines );
4848 assertThat (issues .size ()).isEqualTo (21 );
4949 }
5050
5151 @ Test
5252 public void shouldParseCorrectlyNewFormat () {
5353 String resourceName = "/org/sonar/plugins/python/pylint/sample_pylint_output_new_format.txt" ;
54- String pathName = getClass ().getResource (resourceName ).getPath ();
5554 String pylintConfigPath = null ;
5655 String pylintPath = null ;
57- List <String > lines = readFile (pathName );
56+ List <String > lines = readFile (resourceName );
5857 List <Issue > issues = analyzer (pylintPath , pylintConfigPath ).parseOutput (lines );
5958 assertThat (issues .size ()).isEqualTo (1 );
6059 assertThat (issues .get (0 ).getRuleId ()).isEqualTo ("C0111" );
@@ -63,10 +62,9 @@ public void shouldParseCorrectlyNewFormat() {
6362 @ Test
6463 public void shouldParseCorrectlyOutputWithWindowsPaths () {
6564 String resourceName = "/org/sonar/plugins/python/pylint/sample_pylint_output_with_win_paths.txt" ;
66- String pathName = getClass ().getResource (resourceName ).getPath ();
6765 String pylintConfigPath = null ;
6866 String pylintPath = null ;
69- List <String > lines = readFile (pathName );
67+ List <String > lines = readFile (resourceName );
7068 List <Issue > issues = analyzer (pylintPath , pylintConfigPath ).parseOutput (lines );
7169 assertThat (issues .size ()).isEqualTo (1 );
7270 }
@@ -75,12 +73,10 @@ public void shouldParseCorrectlyOutputWithWindowsPaths() {
7573 public void shouldMapIssuesIdsCorrectly () {
7674 String resourceOld = "/org/sonar/plugins/python/pylint/sample_pylint_output_oldids.txt" ;
7775 String resourceNew = "/org/sonar/plugins/python/pylint/sample_pylint_output_newids.txt" ;
78- String pathNameOld = getClass ().getResource (resourceOld ).getPath ();
79- String pathNameNew = getClass ().getResource (resourceNew ).getPath ();
8076 String pylintConfigPath = null ;
8177 String pylintPath = null ;
82- List <String > linesOld = readFile (pathNameOld );
83- List <String > linesNew = readFile (pathNameNew );
78+ List <String > linesOld = readFile (resourceOld );
79+ List <String > linesNew = readFile (resourceNew );
8480 List <Issue > issuesOld = analyzer (pylintPath , pylintConfigPath ).parseOutput (linesOld );
8581 List <Issue > issuesNew = analyzer (pylintPath , pylintConfigPath ).parseOutput (linesNew );
8682 assertThat (getIds (issuesOld )).isEqualTo (getIds (issuesNew ));
@@ -151,7 +147,7 @@ public void shouldFailIfGivenInvalidParams() {
151147
152148 private static List <String > readFile (String path ) {
153149 try {
154- return Files .readAllLines (Paths .get (path ), UTF_8 );
150+ return Files .readAllLines (Paths .get (RESOURCE_DIR , path ), UTF_8 );
155151 } catch (IOException e ) {
156152 LOG .error ("Cannot read the file '{}'" , path );
157153 return Collections .emptyList ();
0 commit comments