1
1
package org .utplsql .maven .plugin ;
2
2
3
+ import com .soebes .itf .jupiter .maven .MavenExecutionResult ;
3
4
import org .apache .commons .io .FileUtils ;
4
- import org .junit .jupiter .api .Assertions ;
5
5
6
6
import java .io .File ;
7
7
import java .io .IOException ;
8
8
import java .nio .file .Files ;
9
9
import java .util .stream .Collectors ;
10
10
import java .util .stream .Stream ;
11
11
12
- import static org .junit .jupiter .api .Assertions .assertTrue ;
12
+ import static com .soebes .itf .extension .assertj .MavenProjectResultAssert .assertThat ;
13
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
14
+ import static org .junit .jupiter .api .Assertions .fail ;
13
15
14
16
public class ReportChecker {
15
17
@@ -21,17 +23,15 @@ private ReportChecker() {
21
23
* Path separator is set to "/" to ensure windows / linux / mac compatibility.
22
24
* \r and \n are removed to provide simpler comparison.
23
25
*
24
- * @param testClass Class under test
25
- * @param testFolder Folder name
26
- * @param files Files to compare
26
+ * @param result {@link MavenExecutionResult}
27
+ * @param files Files to compare
27
28
*/
28
- public static void checkReports (Class <?> testClass , String testFolder , String ... files ) throws IOException {
29
- String fullyQualifiedClassNameDirectory = testClass .getName ().replace ("." , "/" );
30
-
29
+ public static void assertThatReportsAreGeneratedAsExpected (MavenExecutionResult result , String ... files ) {
31
30
for (String filename : files ) {
32
- File expectedOutputFile = new File ("target/maven-it/" + fullyQualifiedClassNameDirectory + "/" + testFolder + "/project/expected-output/utplsql" , filename );
33
- File outputFile = new File ("target/maven-it/" + fullyQualifiedClassNameDirectory + "/" + testFolder + "/project/target/utplsql" , filename );
34
- assertTrue (outputFile .exists (), "The report " + outputFile .getPath () + " was not generated" );
31
+ File expectedOutputFile = new File (result .getMavenProjectResult ().getTargetProjectDirectory (), "/expected-output/utplsql/" + filename );
32
+ File outputFile = new File (result .getMavenProjectResult ().getTargetProjectDirectory (), "/target/utplsql/" + filename );
33
+
34
+ assertThat (result .getMavenProjectResult ()).withFile ("/utplsql/" + filename ).exists ();
35
35
36
36
try (Stream <String > stream = Files .lines (outputFile .toPath ())) {
37
37
String outputContent = stream
@@ -41,27 +41,26 @@ public static void checkReports(Class<?> testClass, String testFolder, String...
41
41
.map (line -> line .replaceAll ("\r " , "" ).replaceAll ("\n " , "" ))
42
42
.collect (Collectors .joining ("\n " ));
43
43
44
- Assertions . assertEquals (
44
+ assertEquals (
45
45
FileUtils .readFileToString (expectedOutputFile , "utf-8" )
46
46
.replace ("\r " , "" )
47
47
.replace ("\n " , "" ),
48
48
outputContent .replace ("\n " , "" ), "The files differ!" );
49
+ } catch (IOException e ) {
50
+ fail (e );
49
51
}
50
52
}
51
53
}
52
54
53
55
/**
54
- * Check if a report file exits
56
+ * Check if the report was generated
55
57
*
56
- * @param testClass Class under test
57
- * @param testFolder Folder name
58
- * @param filename File Name
59
- * @return true or false
58
+ * @param result {@link MavenExecutionResult}
59
+ * @param filename File Name
60
+ * @return if report exits
60
61
*/
61
- public static boolean reportExists (Class <?> testClass , String testFolder , String filename ) {
62
- String fullyQualifiedClassNameDirectory = testClass .getName ().replace ("." , "/" );
63
-
64
- File outputFile = new File ("target/maven-it/" + fullyQualifiedClassNameDirectory + "/" + testFolder + "/project/target/utplsql" , filename );
62
+ public static boolean reportWasGenerated (MavenExecutionResult result , String filename ) {
63
+ File outputFile = new File (result .getMavenProjectResult ().getTargetProjectDirectory (), "/target/utplsql/" + filename );
65
64
return outputFile .exists ();
66
65
}
67
66
}
0 commit comments