You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2011/04/07 12:51:55 UTC

svn commit: r1089814 - /lucene/dev/branches/branch_3x/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java

Author: mikemccand
Date: Thu Apr  7 10:51:54 2011
New Revision: 1089814

URL: http://svn.apache.org/viewvc?rev=1089814&view=rev
Log:
fix test: don't use hardcoded index

Modified:
    lucene/dev/branches/branch_3x/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java

Modified: lucene/dev/branches/branch_3x/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java?rev=1089814&r1=1089813&r2=1089814&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/demo/src/test/org/apache/lucene/demo/TestDemo.java Thu Apr  7 10:51:54 2011
@@ -22,16 +22,17 @@ import java.io.File;
 import java.io.PrintStream;
 
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
 
 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;
     try {
       ByteArrayOutputStream bytes = new ByteArrayOutputStream();
       PrintStream fakeSystemOut = new PrintStream(bytes);
       System.setOut(fakeSystemOut);
-      SearchFiles.main(new String[] {"-query", query});
+      SearchFiles.main(new String[] {"-query", query, "-index", indexPath.getPath()});
       fakeSystemOut.flush();
       String output = bytes.toString(); // intentionally use default encoding
       assertTrue("output=" + output, output.contains(expectedHitCount + " total matching documents"));
@@ -42,12 +43,13 @@ public class TestDemo extends LuceneTest
 
   public void testIndexSearch() throws Exception {
     File dir = getDataFile("test-files/docs");
-    IndexFiles.main(new String[] { "-create", "-docs", dir.getPath() });
-    testOneSearch("apache", 3);
-    testOneSearch("patent", 8);
-    testOneSearch("lucene", 0);
-    testOneSearch("gnu", 6);
-    testOneSearch("derivative", 8);
-    testOneSearch("license", 13);
+    File indexDir = _TestUtil.getTempDir("ContribDemoTest");
+    IndexFiles.main(new String[] { "-create", "-docs", dir.getPath(), "-index", indexDir.getPath()});
+    testOneSearch(indexDir, "apache", 3);
+    testOneSearch(indexDir, "patent", 8);
+    testOneSearch(indexDir, "lucene", 0);
+    testOneSearch(indexDir, "gnu", 6);
+    testOneSearch(indexDir, "derivative", 8);
+    testOneSearch(indexDir, "license", 13);
   }
 }