From f7bf3cc07bdf26385eb9e0f69cea384bad570d49 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 20 Nov 2026 13:17:47 +0100 Subject: [PATCH] Clean up test output and improve failure diagnostics Remove stdout logging from parser and visitor tests, adding query, file, and iteration context to assertion failures instead. Handle PROX and NOT in the prefix visitor to avoid unhandled enum warnings. --- .../z3950/zing/cql/CQLNodeVisitorTest.java | 24 +++++++++---------- .../org/z3950/zing/cql/CQLParserTest.java | 19 ++++----------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/test/java/org/z3950/zing/cql/CQLNodeVisitorTest.java b/src/test/java/org/z3950/zing/cql/CQLNodeVisitorTest.java index b2da280..8513214 100644 --- a/src/test/java/org/z3950/zing/cql/CQLNodeVisitorTest.java +++ b/src/test/java/org/z3950/zing/cql/CQLNodeVisitorTest.java @@ -8,8 +8,6 @@ import org.junit.Test; import static org.junit.Assert.*; -import static java.lang.System.*; - /** * * @author jakub @@ -40,7 +38,6 @@ public void testPrefixVisitor() { String cql = "((x=a and y=b) or z=c)"; String epxected = "@or @and @attr 1=x a @attr 1=y b @attr 1=z c"; CQLParser p = new CQLParser(CQLParser.V1POINT2); - out.println("Parsing " + cql); try { CQLNode n = p.parse(cql); CQLNodeVisitor v = new CQLDefaultNodeVisitor() { @@ -57,6 +54,12 @@ public void onBooleanNodeStart(CQLBooleanNode node) { case OR: op = "@or"; break; + case PROX: + op = "@prox"; + break; + case NOT: + op = "@not"; + break; } actual += op + " "; } @@ -73,12 +76,11 @@ public String toString() { } }; n.traverse(v); - out.println(v); - assertEquals(epxected, v.toString()); + assertEquals("Query: " + cql, epxected, v.toString()); } catch (CQLParseException ex) { - fail(ex.getMessage()); + fail("Query: " + cql + "\n" + ex.getMessage()); } catch (IOException ex) { - fail(ex.getMessage()); + fail("Query: " + cql + "\n" + ex.getMessage()); } } @@ -87,7 +89,6 @@ public void testInfixVisitor() { String cql = "((x=a and y=b) or z=c)"; String epxected = "((x:a OG y:b) ELLER z:c)"; CQLParser p = new CQLParser(CQLParser.V1POINT2); - out.println("Parsing " + cql); try { CQLNode n = p.parse(cql); CQLNodeVisitor v = new CQLDefaultNodeVisitor() { @@ -128,12 +129,11 @@ public String toString() { } }; n.traverse(v); - out.println(v); - assertEquals(epxected, v.toString()); + assertEquals("Query: " + cql, epxected, v.toString()); } catch (CQLParseException ex) { - fail(ex.getMessage()); + fail("Query: " + cql + "\n" + ex.getMessage()); } catch (IOException ex) { - fail(ex.getMessage()); + fail("Query: " + cql + "\n" + ex.getMessage()); } } } diff --git a/src/test/java/org/z3950/zing/cql/CQLParserTest.java b/src/test/java/org/z3950/zing/cql/CQLParserTest.java index 5995b5c..9b4ac86 100644 --- a/src/test/java/org/z3950/zing/cql/CQLParserTest.java +++ b/src/test/java/org/z3950/zing/cql/CQLParserTest.java @@ -21,7 +21,6 @@ import org.junit.Test; import static org.junit.Assert.*; -import static java.lang.System.out; /** * @@ -52,7 +51,6 @@ public void tearDown() { */ @Test public void testRegressionQueries() throws IOException { - System.out.println("Testing the parser using pre-canned regression queries..."); // we might be running the test from within the jar // list all resource dirs, then traverse them String[] dirs = getResourceListing(this.getClass(), "regression"); @@ -61,13 +59,11 @@ public void testRegressionQueries() throws IOException { for (String file : files) { if (!file.endsWith(".cql")) continue; - out.println("Parsing " + dir + "/" + file); InputStream is = this.getClass().getResourceAsStream("/regression/" + dir + "/" + file); BufferedReader reader = null, reader2 = null; try { reader = new BufferedReader(new InputStreamReader(is)); String input = reader.readLine(); - out.println("Query: " + input); String result; try { CQLParser parser = new CQLParser(); @@ -76,8 +72,6 @@ public void testRegressionQueries() throws IOException { } catch (CQLParseException pe) { result = pe.getMessage() + "\n"; } - out.println("Parsed:"); - out.println(result); // read the expected xcql output String expected = ""; String prefix = file.substring(0, file.length() - 4); @@ -92,9 +86,8 @@ public void testRegressionQueries() throws IOException { } expected = sb.toString(); } - out.println("Expected: "); - out.println(expected); - assertEquals("Assertion failure for " + dir + "/" + file, expected, result); + assertEquals("Regression query " + dir + "/" + file + "\nQuery: " + input, + expected, result); } finally { if (reader != null) reader.close(); @@ -121,7 +114,6 @@ public void testRegressionQueries() throws IOException { */ @Test public void testRandomQueries() throws IOException, MissingParameterException { - out.println("Testing the parser using 100 randomly generated queries..."); Properties params = new Properties(); InputStream is = getClass().getResourceAsStream("/generate.properties"); if (is == null) @@ -132,14 +124,14 @@ public void testRandomQueries() throws IOException, MissingParameterException { for (int i = 0; i < 1000; i++) { CQLNode random = generator.generate(); String expected = random.toCQL(); - out.println("Generated query: " + expected); CQLParser parser = new CQLParser(); try { CQLNode parsed = parser.parse(expected); String result = parsed.toCQL(); - assertEquals(expected, result); + assertEquals("Generated query " + (i + 1) + "\nQuery: " + expected, expected, result); } catch (CQLParseException pe) { - fail("Generated query failed to parse: " + pe.getMessage()); + fail("Generated query " + (i + 1) + " failed to parse: " + expected + + "\n" + pe.getMessage()); } } } @@ -205,7 +197,6 @@ public void testMakeOID() { }; int i = 0; for (String oid : oids) { - out.println("Testing OID: " + oid); byte[] encoded = CQLNode.makeOID(oid); for (int j = 0; j < expected[i].length && j < encoded.length; j++) { assertEquals("Byte " + j + " of OID " + oid, expected[i][j], encoded[j] & 0xff);