mirror of
https://github.com/apache/lucene.git
synced 2025-02-12 21:15:19 +00:00
fix test: don't use hardcoded index
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1089813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
19ae952e80
commit
522ab5b583
@ -22,16 +22,17 @@ import java.io.File;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
|
import org.apache.lucene.util._TestUtil;
|
||||||
|
|
||||||
public class TestDemo extends LuceneTestCase {
|
public class TestDemo extends LuceneTestCase {
|
||||||
|
|
||||||
private void testOneSearch(String query, int expectedHitCount) throws Exception {
|
private void testOneSearch(File indexPath, String query, int expectedHitCount) throws Exception {
|
||||||
PrintStream outSave = System.out;
|
PrintStream outSave = System.out;
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
PrintStream fakeSystemOut = new PrintStream(bytes);
|
PrintStream fakeSystemOut = new PrintStream(bytes);
|
||||||
System.setOut(fakeSystemOut);
|
System.setOut(fakeSystemOut);
|
||||||
SearchFiles.main(new String[] {"-query", query});
|
SearchFiles.main(new String[] {"-query", query, "-index", indexPath.getPath()});
|
||||||
fakeSystemOut.flush();
|
fakeSystemOut.flush();
|
||||||
String output = bytes.toString(); // intentionally use default encoding
|
String output = bytes.toString(); // intentionally use default encoding
|
||||||
assertTrue("output=" + output, output.contains(expectedHitCount + " total matching documents"));
|
assertTrue("output=" + output, output.contains(expectedHitCount + " total matching documents"));
|
||||||
@ -42,12 +43,13 @@ public class TestDemo extends LuceneTestCase {
|
|||||||
|
|
||||||
public void testIndexSearch() throws Exception {
|
public void testIndexSearch() throws Exception {
|
||||||
File dir = getDataFile("test-files/docs");
|
File dir = getDataFile("test-files/docs");
|
||||||
IndexFiles.main(new String[] { "-create", "-docs", dir.getPath() });
|
File indexDir = _TestUtil.getTempDir("ContribDemoTest");
|
||||||
testOneSearch("apache", 3);
|
IndexFiles.main(new String[] { "-create", "-docs", dir.getPath(), "-index", indexDir.getPath()});
|
||||||
testOneSearch("patent", 8);
|
testOneSearch(indexDir, "apache", 3);
|
||||||
testOneSearch("lucene", 0);
|
testOneSearch(indexDir, "patent", 8);
|
||||||
testOneSearch("gnu", 6);
|
testOneSearch(indexDir, "lucene", 0);
|
||||||
testOneSearch("derivative", 8);
|
testOneSearch(indexDir, "gnu", 6);
|
||||||
testOneSearch("license", 13);
|
testOneSearch(indexDir, "derivative", 8);
|
||||||
|
testOneSearch(indexDir, "license", 13);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user