11package org .utplsql .maven .plugin ;
22
3+ import com .soebes .itf .jupiter .maven .MavenExecutionResult ;
34import org .apache .commons .io .FileUtils ;
4- import org .junit .jupiter .api .Assertions ;
55
66import java .io .File ;
77import java .io .IOException ;
88import java .nio .file .Files ;
99import java .util .stream .Collectors ;
1010import java .util .stream .Stream ;
1111
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 ;
1315
1416public class ReportChecker {
1517
@@ -21,17 +23,15 @@ private ReportChecker() {
2123 * Path separator is set to "/" to ensure windows / linux / mac compatibility.
2224 * \r and \n are removed to provide simpler comparison.
2325 *
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
2728 */
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 ) {
3130 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 ();
3535
3636 try (Stream <String > stream = Files .lines (outputFile .toPath ())) {
3737 String outputContent = stream
@@ -41,27 +41,26 @@ public static void checkReports(Class<?> testClass, String testFolder, String...
4141 .map (line -> line .replaceAll ("\r " , "" ).replaceAll ("\n " , "" ))
4242 .collect (Collectors .joining ("\n " ));
4343
44- Assertions . assertEquals (
44+ assertEquals (
4545 FileUtils .readFileToString (expectedOutputFile , "utf-8" )
4646 .replace ("\r " , "" )
4747 .replace ("\n " , "" ),
4848 outputContent .replace ("\n " , "" ), "The files differ!" );
49+ } catch (IOException e ) {
50+ fail (e );
4951 }
5052 }
5153 }
5254
5355 /**
54- * Check if a report file exits
56+ * Check if the report was generated
5557 *
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
6061 */
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 );
6564 return outputFile .exists ();
6665 }
6766}
0 commit comments