Skip to content

Commit d8c7897

Browse files
committed
Code Refactoring
1 parent 20885c9 commit d8c7897

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

liquidjava-verifier/src/test/java/liquidjava/api/tests/TestExamples.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

liquidjava-verifier/src/test/java/liquidjava/utils/TestUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.regex.Matcher;
1010
import java.util.regex.Pattern;
11+
import java.util.stream.Stream;
1112

1213
import liquidjava.processor.context.Context;
1314
import liquidjava.rj_language.Predicate;
@@ -72,4 +73,12 @@ public static void addIntVariableToContext(String name) {
7273
context.addVarToContext(name, factory.Type().INTEGER_PRIMITIVE, new Predicate(),
7374
factory.Code().createCodeSnippetStatement(""));
7475
}
76+
77+
public static boolean isLeafDirectory(Path path) {
78+
try (Stream<Path> children = Files.list(path)) {
79+
return children.noneMatch(Files::isDirectory);
80+
} catch (IOException e) {
81+
return false;
82+
}
83+
}
7584
}

0 commit comments

Comments
 (0)