@@ -35,12 +35,11 @@ public class TestExamples {
3535 public void testPath (final Path path ) {
3636 String pathName = path .getFileName ().toString ();
3737 boolean isDirectory = Files .isDirectory (path );
38-
39- // run verification
4038 CommandLineLauncher .launch (path .toFile ().toString ());
4139
4240 List <Pair <String , Integer >> expectedWarnings = isDirectory ? getExpectedWarningsFromDirectory (path )
4341 : getExpectedWarningsFromFile (path );
42+
4443 List <Pair <String , Integer >> expectedErrors = isDirectory ? getExpectedErrorsFromDirectory (path )
4544 : getExpectedErrorsFromFile (path );
4645
@@ -54,8 +53,8 @@ public void testPath(final Path path) {
5453 private static void checkExpectedDiagnostics (String pathName , Collection <? extends LJDiagnostic > found ,
5554 List <Pair <String , Integer >> expected , String output ) {
5655 if (found .size () != expected .size ()) {
57- System .out .println ("Unexpected number of diagnostics found in: " + pathName + " --- expected exactly "
58- + expected .size () + ". \n " + output );
56+ System .out .printf ("Unexpected number of diagnostics found in: %s --- expected exactly %d.%n%s%n" , pathName ,
57+ expected .size (), output );
5958 fail ();
6059 }
6160 List <Pair <String , Integer >> unmatched = new ArrayList <>(expected );
@@ -68,8 +67,7 @@ private static void checkExpectedDiagnostics(String pathName, Collection<? exten
6867 }
6968 }
7069 if (match < 0 ) {
71- System .out .println (
72- "Unexpected diagnostic in: " + pathName + " --- expected: " + expected + ". \n " + output );
70+ System .out .printf ("Unexpected diagnostic in: %s --- expected: %s.%n%s%n" , pathName , expected , output );
7371 fail ();
7472 }
7573 unmatched .remove (match );
@@ -79,6 +77,7 @@ private static void checkExpectedDiagnostics(String pathName, Collection<? exten
7977 private static boolean matches (LJDiagnostic diagnostic , Pair <String , Integer > expected ) {
8078 if (diagnostic .getPosition ().getLine () != expected .second ())
8179 return false ;
80+
8281 return !(diagnostic instanceof LJError ) || diagnostic .getTitle ().equals (expected .first ());
8382 }
8483
@@ -92,26 +91,17 @@ private static Stream<Path> sourcePaths() throws IOException {
9291 && path .toString ().endsWith (".java" ) && !isLeafDirectory (path .getParent ()));
9392 }
9493
95- private static boolean isLeafDirectory (Path path ) {
96- try (Stream <Path > children = Files .list (path )) {
97- return children .noneMatch (Files ::isDirectory );
98- } catch (IOException e ) {
99- return false ;
100- }
101- }
102-
10394 /**
10495 * Verifies that multiple correct inputs can be processed together
10596 */
10697 @ Test
10798 public void testMultiplePaths () {
10899 String [] paths = { "../liquidjava-example/src/main/java/testSuite/CorrectSimple.java" ,
109- "../liquidjava-example/src/main/java/testSuite/classes/arraylist_correct" , };
100+ "../liquidjava-example/src/main/java/testSuite/classes/arraylist_correct" };
110101 CommandLineLauncher .launch (paths );
111- // The inputs have no expected diagnostics.
112102 if (diagnostics .foundError () || !diagnostics .getWarnings ().isEmpty ()) {
113- System .out .println (
114- "Unexpected diagnostic found. \n " + diagnostics . getErrorOutput () + diagnostics .getWarningOutput ());
103+ System .out .printf ( "Unexpected diagnostic found.%n%s%s%n" , diagnostics . getErrorOutput (),
104+ diagnostics .getWarningOutput ());
115105 fail ();
116106 }
117107 }
0 commit comments