22
33import java .io .File ;
44import java .io .IOException ;
5+ import java .nio .file .Files ;
6+ import java .nio .file .Paths ;
7+ import java .util .stream .Collectors ;
8+ import java .util .stream .Stream ;
59
610import org .apache .commons .io .FileUtils ;
711import org .apache .maven .plugin .testing .MojoRule ;
@@ -29,7 +33,7 @@ public void testDefinition() throws Exception
2933 Assert .assertNotNull (myMojo );
3034 myMojo .execute ();
3135
32- checkCoverReportsGenerated (PROJECT_NAME ,"utplsql/coverage-sonar-reporter.xml" , "utplsql/sonar-test-reporter.xml" );
36+ checkReportsGenerated (PROJECT_NAME ,"utplsql/coverage-sonar-reporter.xml" , "utplsql/sonar-test-reporter.xml" );
3337 }
3438 catch (Exception e )
3539 {
@@ -49,7 +53,7 @@ public void testRegexDefinition() throws Exception
4953 Assert .assertNotNull (myMojo );
5054 myMojo .execute ();
5155
52- checkCoverReportsGenerated (PROJECT_NAME ,"utplsql/coverage-sonar-reporter.xml" , "utplsql/sonar-test-reporter.xml" );
56+ checkReportsGenerated (PROJECT_NAME ,"utplsql/coverage-sonar-reporter.xml" , "utplsql/sonar-test-reporter.xml" );
5357 }
5458 catch (Exception e )
5559 {
@@ -62,7 +66,7 @@ public void testRegexDefinition() throws Exception
6266 *
6367 * @param files
6468 */
65- private void checkCoverReportsGenerated (String projectName , String ... files )
69+ private void checkReportsGenerated (String projectName , String ... files )
6670 {
6771 for (String filename : files )
6872 {
@@ -71,16 +75,23 @@ private void checkCoverReportsGenerated(String projectName, String... files)
7175
7276 Assert .assertTrue ("The reporter for " + filename + " was not generated" , outputFile .exists ());
7377 try {
74- // Duration is set to 1 before comparing contents.
78+ // Duration is set to 1 before comparing contents as it is always different.
79+ // Path separator is set to "/" to ensure windows / linux / mac compatibility
80+ Stream <String > stream = Files .lines (Paths .get (TARGET_DIRECTORY ,projectName ,"target" ,filename ));
81+ String outputContent = stream .map (line -> line .replaceAll ("(duration=\" [0-9\\ .]*\" )" , "duration=\" 1\" " ))
82+ .map (line -> line .replaceAll ("\\ \\ " , "/" ))
83+ .map (line -> line .replaceAll ("\r " , "" ).replaceAll ("\n " , "" ))
84+ .collect (Collectors .joining ("\n " ));
85+
86+ stream .close ();
7587 Assert .assertEquals ("The files differ!" ,
76- FileUtils . readFileToString ( outputFile , "utf-8" ). replaceAll ( "(duration= \" [0-9 \\ .]* \" )" , "duration= \" 1 \" " ),
77- FileUtils .readFileToString (expectedOutputFile , "utf-8" ));
88+ outputContent ,
89+ FileUtils .readFileToString (expectedOutputFile , "utf-8" ). replace ( " \r " , "" ) );
7890 } catch (IOException e ) {
7991 // TODO Auto-generated catch block
8092 e .printStackTrace ();
8193 Assert .fail ("Unexpected Exception running the test of Definition" );
8294 }
8395 }
8496 }
85-
8697}
0 commit comments