LUCENE-7178: TestCoreParser tweaks

Summary:
 * rename testSimpleXML to testTermQueryXML
 * rename testSimpleTermsQueryXML to testTermsQueryXML
 * try-with-resources and file-not-found-assert for TestCoreParser.parse
 * TestCoreParser.dumpResults verbose logging now includes qType and numDocs

(Ramkumar Aiyengar, Nathan Visagan, Christine Poerschke)
This commit is contained in:
Christine Poerschke 2016-04-06 12:48:52 +01:00
parent 4205b1c804
commit 2259288ca0
1 changed files with 8 additions and 7 deletions

View File

@ -95,12 +95,12 @@ public class TestCoreParser extends LuceneTestCase {
analyzer = null;
}
public void testSimpleXML() throws ParserException, IOException {
public void testTermQueryXML() throws ParserException, IOException {
Query q = parse("TermQuery.xml");
dumpResults("TermQuery", q, 5);
}
public void testSimpleTermsQueryXML() throws ParserException, IOException {
public void testTermsQueryXML() throws ParserException, IOException {
Query q = parse("TermsQuery.xml");
dumpResults("TermsQuery", q, 5);
}
@ -187,10 +187,11 @@ public class TestCoreParser extends LuceneTestCase {
}
protected Query parse(String xmlFileName) throws ParserException, IOException {
InputStream xmlStream = TestCoreParser.class.getResourceAsStream(xmlFileName);
Query result = coreParser().parse(xmlStream);
xmlStream.close();
return result;
try (InputStream xmlStream = TestCoreParser.class.getResourceAsStream(xmlFileName)) {
assertNotNull("Test XML file " + xmlFileName + " cannot be found", xmlStream);
Query result = coreParser().parse(xmlStream);
return result;
}
}
protected Query rewrite(Query q) throws IOException {
@ -199,7 +200,7 @@ public class TestCoreParser extends LuceneTestCase {
protected void dumpResults(String qType, Query q, int numDocs) throws IOException {
if (VERBOSE) {
System.out.println("TEST: query=" + q);
System.out.println("TEST: qType=" + qType + " query=" + q + " numDocs=" + numDocs);
}
TopDocs hits = searcher.search(q, numDocs);
assertTrue(qType + " should produce results ", hits.totalHits > 0);