2222 *
2323 * @author pesse
2424 */
25- public class RunCommandCoverageReporterIT {
25+ public class RunCommandCoverageReporterIT extends AbstractFileOutputTest {
2626
2727 private static final Pattern REGEX_COVERAGE_TITLE = Pattern .compile ("<a href=\" [a-zA-Z0-9#]+\" class=\" src_link\" title=\" [a-zA-Z\\ ._]+\" >([a-zA-Z0-9\\ ._]+)<\\ /a>" );
2828
29- private Set <Path > tempPaths ;
30-
31- private void addTempPath (Path path ) {
32- tempPaths .add (path );
33- }
3429
3530 private String getTempCoverageFileName (int counter ) {
3631
@@ -47,7 +42,7 @@ private Path getTempCoverageFilePath() {
4742 int i = 1 ;
4843 Path p = Paths .get (getTempCoverageFileName (i ));
4944
50- while ((Files .exists (p ) || tempPaths . contains (p )) && i < 100 )
45+ while ((Files .exists (p ) || tempPathExists (p )) && i < 100 )
5146 p = Paths .get (getTempCoverageFileName (i ++));
5247
5348 if (i >= 100 )
@@ -77,11 +72,6 @@ private boolean hasCoverageListed(String content, String packageName) {
7772 return false ;
7873 }
7974
80- @ BeforeEach
81- public void setupTest () {
82- tempPaths = new HashSet <>();
83- }
84-
8575 @ Test
8676 public void run_CodeCoverageWithIncludeAndExclude () throws Exception {
8777
@@ -90,10 +80,9 @@ public void run_CodeCoverageWithIncludeAndExclude() throws Exception {
9080 RunCommand runCmd = RunCommandTestHelper .createRunCommand (RunCommandTestHelper .getConnectionString (),
9181 "-f=ut_coverage_html_reporter" , "-o=" + coveragePath , "-s" , "-exclude=app.award_bonus,app.betwnstr" );
9282
93-
9483 int result = runCmd .run ();
9584
96- String content = new Scanner ( coveragePath ). useDelimiter ( " \\ Z" ). next ( );
85+ String content = new String ( Files . readAllBytes ( coveragePath ) );
9786
9887 assertEquals (true , hasCoverageListed (content , "app.remove_rooms_by_name" ));
9988 assertEquals (false , hasCoverageListed (content , "app.award_bonus" ));
@@ -122,27 +111,11 @@ public void coverageReporterWriteAssetsToOutput() throws Exception {
122111 assertTrue (applicationJs .exists ());
123112
124113 // Check correct script-part in HTML source exists
125- String content = new Scanner ( coveragePath ). useDelimiter ( " \\ Z" ). next ( );
114+ String content = new String ( Files . readAllBytes ( coveragePath ) );
126115 assertTrue (content .contains ("<script src='" + coverageAssetsPath .toString () + "/application.js' type='text/javascript'>" ));
127116
128117 // Check correct title exists
129118 assertTrue (content .contains ("<title>Code coverage</title>" ));
130119 }
131120
132- @ AfterEach
133- public void deleteTempFiles () {
134- tempPaths .forEach (p -> deleteDir (p .toFile ()));
135- }
136-
137- void deleteDir (File file ) {
138- if (file .exists ()) {
139- File [] contents = file .listFiles ();
140- if (contents != null ) {
141- for (File f : contents ) {
142- deleteDir (f );
143- }
144- }
145- file .delete ();
146- }
147- }
148121}
0 commit comments