lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r208807 - /lucene/java/trunk/src/test/org/apache/lucene/index/
Date Fri, 01 Jul 2005 22:13:55 GMT
Author: dnaber
Date: Fri Jul  1 15:13:53 2005
New Revision: 208807

URL: http://svn.apache.org/viewcvs?rev=208807&view=rev
Log:
clean up exception handling:  there's no need to manually catch exceptions in test 
cases (unless you expect the exception to be thrown)

Modified:
    lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentMerger.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermEnum.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsWriter.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java Fri Jul  1 15:13:53 2005
@@ -338,7 +338,9 @@
             // OK: this call correctly fails. We are now past the 1024 internal
             // buffer, so an actual IO is attempted, which fails
             b = in.readByte();
+            fail("expected readByte() to throw exception");
         } catch (IOException e) {
+          // expected exception
         }
     }
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java Fri Jul  1 15:13:53 2005
@@ -34,43 +34,28 @@
     super(s);
   }
 
-  protected void setUp() {
+  protected void setUp() throws IOException {
     fieldInfos = new FieldInfos();
     DocHelper.setupDoc(testDoc);
     fieldInfos.add(testDoc);
     DocumentWriter writer = new DocumentWriter(dir, new WhitespaceAnalyzer(),
             Similarity.getDefault(), 50);
     assertTrue(writer != null);
-    try {
-      writer.addDocument("test", testDoc);
-    }
-    catch (IOException e)
-    {
-      
-    }
+    writer.addDocument("test", testDoc);
   }
 
-  protected void tearDown() {
-
-  }
-
-  public void test() {
+  public void test() throws IOException {
     assertTrue(dir != null);
     assertTrue(fieldInfos != null);
-    try {
-      FieldsReader reader = new FieldsReader(dir, "test", fieldInfos);
-      assertTrue(reader != null);
-      assertTrue(reader.size() == 1);
-      Document doc = reader.doc(0);
-      assertTrue(doc != null);
-      assertTrue(doc.getField("textField1") != null);
-      Field field = doc.getField("textField2");
-      assertTrue(field != null);
-      assertTrue(field.isTermVectorStored() == true);
-      reader.close();
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }
+    FieldsReader reader = new FieldsReader(dir, "test", fieldInfos);
+    assertTrue(reader != null);
+    assertTrue(reader.size() == 1);
+    Document doc = reader.doc(0);
+    assertTrue(doc != null);
+    assertTrue(doc.getField("textField1") != null);
+    Field field = doc.getField("textField2");
+    assertTrue(field != null);
+    assertTrue(field.isTermVectorStored() == true);
+    reader.close();
   }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Fri Jul  1 15:13:53 2005
@@ -185,7 +185,7 @@
 
         } finally {
             if (tdocs != null)
-                try { tdocs.close(); } catch (Exception e) { }
+                tdocs.close();
         }
 
     }
@@ -498,18 +498,10 @@
         writer.addDocument(doc);
     }
     
-    private void addDoc(IndexWriter writer, String value)
+    private void addDoc(IndexWriter writer, String value) throws IOException
     {
         Document doc = new Document();
         doc.add(new Field("content", value, Field.Store.NO, Field.Index.TOKENIZED));
-
-        try
-        {
-            writer.addDocument(doc);
-        }
-        catch (IOException e)
-        {
-            e.printStackTrace();
-        }
+        writer.addDocument(doc);
     }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Fri Jul  1 15:13:53 2005
@@ -19,7 +19,7 @@
  */
 public class TestIndexWriter extends TestCase
 {
-    public void testDocCount()
+    public void testDocCount() throws IOException
     {
         Directory dir = new RAMDirectory();
 
@@ -27,60 +27,49 @@
         IndexReader reader = null;
         int i;
 
-        try {
-            writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+        writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
 
-            // add 100 documents
-            for (i = 0; i < 100; i++) {
-                addDoc(writer);
-            }
-            assertEquals(100, writer.docCount());
-            writer.close();
-
-            // delete 40 documents
-            reader = IndexReader.open(dir);
-            for (i = 0; i < 40; i++) {
-                reader.delete(i);
-            }
-            reader.close();
-
-            // test doc count before segments are merged/index is optimized
-            writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
-            assertEquals(100, writer.docCount());
-            writer.close();
-
-            reader = IndexReader.open(dir);
-            assertEquals(100, reader.maxDoc());
-            assertEquals(60, reader.numDocs());
-            reader.close();
-
-            // optimize the index and check that the new doc count is correct
-            writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
-            writer.optimize();
-            assertEquals(60, writer.docCount());
-            writer.close();
-
-            // check that the index reader gives the same numbers.
-            reader = IndexReader.open(dir);
-            assertEquals(60, reader.maxDoc());
-            assertEquals(60, reader.numDocs());
-            reader.close();
+        // add 100 documents
+        for (i = 0; i < 100; i++) {
+            addDoc(writer);
         }
-        catch (IOException e) {
-            e.printStackTrace();
+        assertEquals(100, writer.docCount());
+        writer.close();
+
+        // delete 40 documents
+        reader = IndexReader.open(dir);
+        for (i = 0; i < 40; i++) {
+            reader.delete(i);
         }
+        reader.close();
+
+        // test doc count before segments are merged/index is optimized
+        writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
+        assertEquals(100, writer.docCount());
+        writer.close();
+
+        reader = IndexReader.open(dir);
+        assertEquals(100, reader.maxDoc());
+        assertEquals(60, reader.numDocs());
+        reader.close();
+
+        // optimize the index and check that the new doc count is correct
+        writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
+        writer.optimize();
+        assertEquals(60, writer.docCount());
+        writer.close();
+
+        // check that the index reader gives the same numbers.
+        reader = IndexReader.open(dir);
+        assertEquals(60, reader.maxDoc());
+        assertEquals(60, reader.numDocs());
+        reader.close();
     }
 
-    private void addDoc(IndexWriter writer)
+    private void addDoc(IndexWriter writer) throws IOException
     {
         Document doc = new Document();
         doc.add(new Field("content", "aaa", Field.Store.NO, Field.Index.TOKENIZED));
-
-        try {
-            writer.addDocument(doc);
-        }
-        catch (IOException e) {
-            e.printStackTrace();
-        }
+        writer.addDocument(doc);
     }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java Fri Jul  1 15:13:53 2005
@@ -36,28 +36,16 @@
     super(s);
   }
 
-  protected void setUp() {
+  protected void setUp() throws IOException {
     DocHelper.setupDoc(doc1);
     DocHelper.setupDoc(doc2);
     DocHelper.writeDoc(dir, "seg-1", doc1);
     DocHelper.writeDoc(dir, "seg-2", doc2);
-    
-    try {
-      sis.write(dir);
-      reader1 = SegmentReader.get(new SegmentInfo("seg-1", 1, dir));
-      reader2 = SegmentReader.get(new SegmentInfo("seg-2", 1, dir));
-      readers[0] = reader1;
-      readers[1] = reader2;      
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-  }
-/*IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
-      writer.addDocument(doc1);
-      writer.addDocument(doc2);
-      writer.close();*/
-  protected void tearDown() {
-
+    sis.write(dir);
+    reader1 = SegmentReader.get(new SegmentInfo("seg-1", 1, dir));
+    reader2 = SegmentReader.get(new SegmentInfo("seg-2", 1, dir));
+    readers[0] = reader1;
+    readers[1] = reader2;
   }
   
   public void test() {
@@ -67,23 +55,18 @@
     assertTrue(sis != null);
   }    
 
-  public void testDocument() {
-    try {    
-      sis.read(dir);
-      MultiReader reader = new MultiReader(dir, sis, false, readers);
-      assertTrue(reader != null);
-      Document newDoc1 = reader.document(0);
-      assertTrue(newDoc1 != null);
-      assertTrue(DocHelper.numFields(newDoc1) == DocHelper.numFields(doc1) - 2);
-      Document newDoc2 = reader.document(1);
-      assertTrue(newDoc2 != null);
-      assertTrue(DocHelper.numFields(newDoc2) == DocHelper.numFields(doc2) - 2);
-      TermFreqVector vector = reader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
-      assertTrue(vector != null);
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }
+  public void testDocument() throws IOException {
+    sis.read(dir);
+    MultiReader reader = new MultiReader(dir, sis, false, readers);
+    assertTrue(reader != null);
+    Document newDoc1 = reader.document(0);
+    assertTrue(newDoc1 != null);
+    assertTrue(DocHelper.numFields(newDoc1) == DocHelper.numFields(doc1) - 2);
+    Document newDoc2 = reader.document(1);
+    assertTrue(newDoc2 != null);
+    assertTrue(DocHelper.numFields(newDoc2) == DocHelper.numFields(doc2) - 2);
+    TermFreqVector vector = reader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
+    assertTrue(vector != null);
   }
   
   public void testTermVectors() {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentMerger.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentMerger.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentMerger.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentMerger.java Fri Jul  1 15:13:53 2005
@@ -44,22 +44,13 @@
     super(s);
   }
 
-  protected void setUp() {
+  protected void setUp() throws IOException {
     DocHelper.setupDoc(doc1);
     DocHelper.writeDoc(merge1Dir, merge1Segment, doc1);
     DocHelper.setupDoc(doc2);
     DocHelper.writeDoc(merge2Dir, merge2Segment, doc2);
-    try {
-      reader1 = SegmentReader.get(new SegmentInfo(merge1Segment, 1, merge1Dir));
-      reader2 = SegmentReader.get(new SegmentInfo(merge2Segment, 1, merge2Dir));
-    } catch (IOException e) {
-      e.printStackTrace();                                                      
-    }
-
-  }
-
-  protected void tearDown() {
-
+    reader1 = SegmentReader.get(new SegmentInfo(merge1Segment, 1, merge1Dir));
+    reader2 = SegmentReader.get(new SegmentInfo(merge2Segment, 1, merge2Dir));
   }
 
   public void test() {
@@ -70,58 +61,51 @@
     assertTrue(reader2 != null);
   }
   
-  public void testMerge() {                             
-    //System.out.println("----------------TestMerge------------------");
+  public void testMerge() throws IOException {                             
     SegmentMerger merger = new SegmentMerger(mergedDir, mergedSegment);
     merger.add(reader1);
     merger.add(reader2);
-    try {
-      int docsMerged = merger.merge();
-      merger.closeReaders();
-      assertTrue(docsMerged == 2);
-      //Should be able to open a new SegmentReader against the new directory
-      SegmentReader mergedReader = SegmentReader.get(new SegmentInfo(mergedSegment, docsMerged, mergedDir));
-      assertTrue(mergedReader != null);
-      assertTrue(mergedReader.numDocs() == 2);
-      Document newDoc1 = mergedReader.document(0);
-      assertTrue(newDoc1 != null);
-      //There are 2 unstored fields on the document
-      assertTrue(DocHelper.numFields(newDoc1) == DocHelper.numFields(doc1) - 2);
-      Document newDoc2 = mergedReader.document(1);
-      assertTrue(newDoc2 != null);
-      assertTrue(DocHelper.numFields(newDoc2) == DocHelper.numFields(doc2) - 2);
-      
-      TermDocs termDocs = mergedReader.termDocs(new Term(DocHelper.TEXT_FIELD_2_KEY, "field"));
-      assertTrue(termDocs != null);
-      assertTrue(termDocs.next() == true);
-      
-      Collection stored = mergedReader.getFieldNames(IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR);
-      assertTrue(stored != null);
-      //System.out.println("stored size: " + stored.size());
-      assertTrue(stored.size() == 2);
-      
-      TermFreqVector vector = mergedReader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
-      assertTrue(vector != null);
-      String [] terms = vector.getTerms();
-      assertTrue(terms != null);
-      //System.out.println("Terms size: " + terms.length);
-      assertTrue(terms.length == 3);
-      int [] freqs = vector.getTermFrequencies();
-      assertTrue(freqs != null);
-      //System.out.println("Freqs size: " + freqs.length);
-      assertTrue(vector instanceof TermPositionVector == true);
-      
-      for (int i = 0; i < terms.length; i++) {
-        String term = terms[i];
-        int freq = freqs[i];
-        //System.out.println("Term: " + term + " Freq: " + freq);
-        assertTrue(DocHelper.FIELD_2_TEXT.indexOf(term) != -1);
-        assertTrue(DocHelper.FIELD_2_FREQS[i] == freq);
-      }                                                
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }
-    //System.out.println("---------------------end TestMerge-------------------");
+    int docsMerged = merger.merge();
+    merger.closeReaders();
+    assertTrue(docsMerged == 2);
+    //Should be able to open a new SegmentReader against the new directory
+    SegmentReader mergedReader = SegmentReader.get(new SegmentInfo(mergedSegment, docsMerged, mergedDir));
+    assertTrue(mergedReader != null);
+    assertTrue(mergedReader.numDocs() == 2);
+    Document newDoc1 = mergedReader.document(0);
+    assertTrue(newDoc1 != null);
+    //There are 2 unstored fields on the document
+    assertTrue(DocHelper.numFields(newDoc1) == DocHelper.numFields(doc1) - 2);
+    Document newDoc2 = mergedReader.document(1);
+    assertTrue(newDoc2 != null);
+    assertTrue(DocHelper.numFields(newDoc2) == DocHelper.numFields(doc2) - 2);
+    
+    TermDocs termDocs = mergedReader.termDocs(new Term(DocHelper.TEXT_FIELD_2_KEY, "field"));
+    assertTrue(termDocs != null);
+    assertTrue(termDocs.next() == true);
+    
+    Collection stored = mergedReader.getFieldNames(IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR);
+    assertTrue(stored != null);
+    //System.out.println("stored size: " + stored.size());
+    assertTrue(stored.size() == 2);
+    
+    TermFreqVector vector = mergedReader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
+    assertTrue(vector != null);
+    String [] terms = vector.getTerms();
+    assertTrue(terms != null);
+    //System.out.println("Terms size: " + terms.length);
+    assertTrue(terms.length == 3);
+    int [] freqs = vector.getTermFrequencies();
+    assertTrue(freqs != null);
+    //System.out.println("Freqs size: " + freqs.length);
+    assertTrue(vector instanceof TermPositionVector == true);
+    
+    for (int i = 0; i < terms.length; i++) {
+      String term = terms[i];
+      int freq = freqs[i];
+      //System.out.println("Term: " + term + " Freq: " + freq);
+      assertTrue(DocHelper.FIELD_2_TEXT.indexOf(term) != -1);
+      assertTrue(DocHelper.FIELD_2_FREQS[i] == freq);
+    }                                                
   }    
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentReader.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentReader.java Fri Jul  1 15:13:53 2005
@@ -36,15 +36,10 @@
   }
   
   //TODO: Setup the reader w/ multiple documents
-  protected void setUp() {
-
-    try {
-      DocHelper.setupDoc(testDoc);
-      DocHelper.writeDoc(dir, testDoc);
-      reader = SegmentReader.get(new SegmentInfo("test", 1, dir));
-    } catch (IOException e) {
-      
-    }
+  protected void setUp() throws IOException {
+    DocHelper.setupDoc(testDoc);
+    DocHelper.writeDoc(dir, testDoc);
+    reader = SegmentReader.get(new SegmentInfo("test", 1, dir));
   }
 
   protected void tearDown() {
@@ -58,48 +53,38 @@
     assertTrue(DocHelper.numFields(testDoc) == 6);
   }
   
-  public void testDocument() {
-    try {
-      assertTrue(reader.numDocs() == 1);
-      assertTrue(reader.maxDoc() >= 1);
-      Document result = reader.document(0);
-      assertTrue(result != null);
-      //There are 2 unstored fields on the document that are not preserved across writing
-      assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - 2);
-      
-      Enumeration fields = result.fields();
-      while (fields.hasMoreElements()) {
-        Field field = (Field) fields.nextElement();
-        assertTrue(field != null);
-        assertTrue(DocHelper.nameValues.containsKey(field.name()));
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
+  public void testDocument() throws IOException {
+    assertTrue(reader.numDocs() == 1);
+    assertTrue(reader.maxDoc() >= 1);
+    Document result = reader.document(0);
+    assertTrue(result != null);
+    //There are 2 unstored fields on the document that are not preserved across writing
+    assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - 2);
+    
+    Enumeration fields = result.fields();
+    while (fields.hasMoreElements()) {
+      Field field = (Field) fields.nextElement();
+      assertTrue(field != null);
+      assertTrue(DocHelper.nameValues.containsKey(field.name()));
     }
   }
   
-  public void testDelete() {
+  public void testDelete() throws IOException {
     Document docToDelete = new Document();
     DocHelper.setupDoc(docToDelete);
     DocHelper.writeDoc(dir, "seg-to-delete", docToDelete);
+    SegmentReader deleteReader = SegmentReader.get(new SegmentInfo("seg-to-delete", 1, dir));
+    assertTrue(deleteReader != null);
+    assertTrue(deleteReader.numDocs() == 1);
+    deleteReader.delete(0);
+    assertTrue(deleteReader.isDeleted(0) == true);
+    assertTrue(deleteReader.hasDeletions() == true);
+    assertTrue(deleteReader.numDocs() == 0);
     try {
-      SegmentReader deleteReader = SegmentReader.get(new SegmentInfo("seg-to-delete", 1, dir));
-      assertTrue(deleteReader != null);
-      assertTrue(deleteReader.numDocs() == 1);
-      deleteReader.delete(0);
-      assertTrue(deleteReader.isDeleted(0) == true);
-      assertTrue(deleteReader.hasDeletions() == true);
-      assertTrue(deleteReader.numDocs() == 0);
-      try {
-        Document test = deleteReader.document(0);
-        assertTrue(false);
-      } catch (IllegalArgumentException e) {
-        assertTrue(true);
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
+      Document test = deleteReader.document(0);
+      fail();
+    } catch (IllegalArgumentException e) {
+      // expcected exception
     }
   }    
   
@@ -133,34 +118,28 @@
     assertTrue(result.size() == 3);
   } 
   
-  public void testTerms() {
-    try {
-      TermEnum terms = reader.terms();
-      assertTrue(terms != null);
-      while (terms.next() == true)
-      {
-        Term term = terms.term();
-        assertTrue(term != null);
-        //System.out.println("Term: " + term);
-        String fieldValue = (String)DocHelper.nameValues.get(term.field());
-        assertTrue(fieldValue.indexOf(term.text()) != -1);
-      }
-      
-      TermDocs termDocs = reader.termDocs();
-      assertTrue(termDocs != null);
-      termDocs.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field"));
-      assertTrue(termDocs.next() == true);
-      
-      TermPositions positions = reader.termPositions();
-      positions.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field"));
-      assertTrue(positions != null);
-      assertTrue(positions.doc() == 0);
-      assertTrue(positions.nextPosition() >= 0);
-      
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
+  public void testTerms() throws IOException {
+    TermEnum terms = reader.terms();
+    assertTrue(terms != null);
+    while (terms.next() == true)
+    {
+      Term term = terms.term();
+      assertTrue(term != null);
+      //System.out.println("Term: " + term);
+      String fieldValue = (String)DocHelper.nameValues.get(term.field());
+      assertTrue(fieldValue.indexOf(term.text()) != -1);
     }
+    
+    TermDocs termDocs = reader.termDocs();
+    assertTrue(termDocs != null);
+    termDocs.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field"));
+    assertTrue(termDocs.next() == true);
+    
+    TermPositions positions = reader.termPositions();
+    positions.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field"));
+    assertTrue(positions != null);
+    assertTrue(positions.doc() == 0);
+    assertTrue(positions.nextPosition() >= 0);
   }    
   
   public void testNorms() {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermDocs.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermDocs.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermDocs.java Fri Jul  1 15:13:53 2005
@@ -47,29 +47,25 @@
     assertTrue(dir != null);
   }
   
-  public void testTermDocs() {
-    try {
-      //After adding the document, we should be able to read it back in
-      SegmentReader reader = SegmentReader.get(new SegmentInfo("test", 1, dir));
-      assertTrue(reader != null);
-      SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
-      assertTrue(segTermDocs != null);
-      segTermDocs.seek(new Term(DocHelper.TEXT_FIELD_2_KEY, "field"));
-      if (segTermDocs.next() == true)
-      {
-        int docId = segTermDocs.doc();
-        assertTrue(docId == 0);
-        int freq = segTermDocs.freq();
-        assertTrue(freq == 3);  
-      }
-      reader.close();
-    } catch (IOException e) {
-      assertTrue(false);
+  public void testTermDocs() throws IOException {
+    //After adding the document, we should be able to read it back in
+    SegmentReader reader = SegmentReader.get(new SegmentInfo("test", 1, dir));
+    assertTrue(reader != null);
+    SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
+    assertTrue(segTermDocs != null);
+    segTermDocs.seek(new Term(DocHelper.TEXT_FIELD_2_KEY, "field"));
+    if (segTermDocs.next() == true)
+    {
+      int docId = segTermDocs.doc();
+      assertTrue(docId == 0);
+      int freq = segTermDocs.freq();
+      assertTrue(freq == 3);  
     }
+    reader.close();
   }  
   
-  public void testBadSeek() {
-    try {
+  public void testBadSeek() throws IOException {
+    {
       //After adding the document, we should be able to read it back in
       SegmentReader reader = SegmentReader.get(new SegmentInfo("test", 3, dir));
       assertTrue(reader != null);
@@ -78,10 +74,8 @@
       segTermDocs.seek(new Term("textField2", "bad"));
       assertTrue(segTermDocs.next() == false);
       reader.close();
-    } catch (IOException e) {
-      assertTrue(false);
     }
-    try {
+    {
       //After adding the document, we should be able to read it back in
       SegmentReader reader = SegmentReader.get(new SegmentInfo("test", 3, dir));
       assertTrue(reader != null);
@@ -90,137 +84,131 @@
       segTermDocs.seek(new Term("junk", "bad"));
       assertTrue(segTermDocs.next() == false);
       reader.close();
-    } catch (IOException e) {
-      assertTrue(false);
     }
   }
   
-  public void testSkipTo() {
-    try {
-      Directory dir = new RAMDirectory();
-      IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
-      
-      Term ta = new Term("content","aaa");
-      for(int i = 0; i < 10; i++)
-        addDoc(writer, "aaa aaa aaa aaa");
-        
-      Term tb = new Term("content","bbb");
-      for(int i = 0; i < 16; i++)
-        addDoc(writer, "bbb bbb bbb bbb");
-        
-      Term tc = new Term("content","ccc");
-      for(int i = 0; i < 50; i++)
-        addDoc(writer, "ccc ccc ccc ccc");
-        
-      // assure that we deal with a single segment  
-      writer.optimize();
-      writer.close();
-      
-      IndexReader reader = IndexReader.open(dir);
-      TermDocs tdocs = reader.termDocs();
-      
-      // without optimization (assumption skipInterval == 16)
-      
-      // with next
-      tdocs.seek(ta);
-      assertTrue(tdocs.next());
-      assertEquals(0, tdocs.doc());
-      assertEquals(4, tdocs.freq());
-      assertTrue(tdocs.next());
-      assertEquals(1, tdocs.doc());
-      assertEquals(4, tdocs.freq());
-      assertTrue(tdocs.skipTo(0));
-      assertEquals(2, tdocs.doc());
-      assertTrue(tdocs.skipTo(4));
-      assertEquals(4, tdocs.doc());
-      assertTrue(tdocs.skipTo(9));
-      assertEquals(9, tdocs.doc());
-      assertFalse(tdocs.skipTo(10));
-      
-      // without next
-      tdocs.seek(ta);
-      assertTrue(tdocs.skipTo(0));
-      assertEquals(0, tdocs.doc());
-      assertTrue(tdocs.skipTo(4));
-      assertEquals(4, tdocs.doc());
-      assertTrue(tdocs.skipTo(9));
-      assertEquals(9, tdocs.doc());
-      assertFalse(tdocs.skipTo(10));
-      
-      // exactly skipInterval documents and therefore with optimization
-      
-      // with next
-      tdocs.seek(tb);
-      assertTrue(tdocs.next());
-      assertEquals(10, tdocs.doc());
-      assertEquals(4, tdocs.freq());
-      assertTrue(tdocs.next());
-      assertEquals(11, tdocs.doc());
-      assertEquals(4, tdocs.freq());
-      assertTrue(tdocs.skipTo(5));
-      assertEquals(12, tdocs.doc());
-      assertTrue(tdocs.skipTo(15));
-      assertEquals(15, tdocs.doc());
-      assertTrue(tdocs.skipTo(24));
-      assertEquals(24, tdocs.doc());
-      assertTrue(tdocs.skipTo(25));
-      assertEquals(25, tdocs.doc());
-      assertFalse(tdocs.skipTo(26));
-      
-      // without next
-      tdocs.seek(tb);
-      assertTrue(tdocs.skipTo(5));
-      assertEquals(10, tdocs.doc());
-      assertTrue(tdocs.skipTo(15));
-      assertEquals(15, tdocs.doc());
-      assertTrue(tdocs.skipTo(24));
-      assertEquals(24, tdocs.doc());
-      assertTrue(tdocs.skipTo(25));
-      assertEquals(25, tdocs.doc());
-      assertFalse(tdocs.skipTo(26));
-      
-      // much more than skipInterval documents and therefore with optimization
-      
-      // with next
-      tdocs.seek(tc);
-      assertTrue(tdocs.next());
-      assertEquals(26, tdocs.doc());
-      assertEquals(4, tdocs.freq());
-      assertTrue(tdocs.next());
-      assertEquals(27, tdocs.doc());
-      assertEquals(4, tdocs.freq());
-      assertTrue(tdocs.skipTo(5));
-      assertEquals(28, tdocs.doc());
-      assertTrue(tdocs.skipTo(40));
-      assertEquals(40, tdocs.doc());
-      assertTrue(tdocs.skipTo(57));
-      assertEquals(57, tdocs.doc());
-      assertTrue(tdocs.skipTo(74));
-      assertEquals(74, tdocs.doc());
-      assertTrue(tdocs.skipTo(75));
-      assertEquals(75, tdocs.doc());
-      assertFalse(tdocs.skipTo(76));
-      
-      //without next
-      tdocs.seek(tc);
-      assertTrue(tdocs.skipTo(5));
-      assertEquals(26, tdocs.doc());
-      assertTrue(tdocs.skipTo(40));
-      assertEquals(40, tdocs.doc());
-      assertTrue(tdocs.skipTo(57));
-      assertEquals(57, tdocs.doc());
-      assertTrue(tdocs.skipTo(74));
-      assertEquals(74, tdocs.doc());
-      assertTrue(tdocs.skipTo(75));
-      assertEquals(75, tdocs.doc());
-      assertFalse(tdocs.skipTo(76));
-      
-      tdocs.close();
-      reader.close();
-      dir.close();
-    } catch (IOException e) {
-        assertTrue(false);
-    }
+  public void testSkipTo() throws IOException {
+    Directory dir = new RAMDirectory();
+    IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+    
+    Term ta = new Term("content","aaa");
+    for(int i = 0; i < 10; i++)
+      addDoc(writer, "aaa aaa aaa aaa");
+      
+    Term tb = new Term("content","bbb");
+    for(int i = 0; i < 16; i++)
+      addDoc(writer, "bbb bbb bbb bbb");
+      
+    Term tc = new Term("content","ccc");
+    for(int i = 0; i < 50; i++)
+      addDoc(writer, "ccc ccc ccc ccc");
+      
+    // assure that we deal with a single segment  
+    writer.optimize();
+    writer.close();
+    
+    IndexReader reader = IndexReader.open(dir);
+    TermDocs tdocs = reader.termDocs();
+    
+    // without optimization (assumption skipInterval == 16)
+    
+    // with next
+    tdocs.seek(ta);
+    assertTrue(tdocs.next());
+    assertEquals(0, tdocs.doc());
+    assertEquals(4, tdocs.freq());
+    assertTrue(tdocs.next());
+    assertEquals(1, tdocs.doc());
+    assertEquals(4, tdocs.freq());
+    assertTrue(tdocs.skipTo(0));
+    assertEquals(2, tdocs.doc());
+    assertTrue(tdocs.skipTo(4));
+    assertEquals(4, tdocs.doc());
+    assertTrue(tdocs.skipTo(9));
+    assertEquals(9, tdocs.doc());
+    assertFalse(tdocs.skipTo(10));
+    
+    // without next
+    tdocs.seek(ta);
+    assertTrue(tdocs.skipTo(0));
+    assertEquals(0, tdocs.doc());
+    assertTrue(tdocs.skipTo(4));
+    assertEquals(4, tdocs.doc());
+    assertTrue(tdocs.skipTo(9));
+    assertEquals(9, tdocs.doc());
+    assertFalse(tdocs.skipTo(10));
+    
+    // exactly skipInterval documents and therefore with optimization
+    
+    // with next
+    tdocs.seek(tb);
+    assertTrue(tdocs.next());
+    assertEquals(10, tdocs.doc());
+    assertEquals(4, tdocs.freq());
+    assertTrue(tdocs.next());
+    assertEquals(11, tdocs.doc());
+    assertEquals(4, tdocs.freq());
+    assertTrue(tdocs.skipTo(5));
+    assertEquals(12, tdocs.doc());
+    assertTrue(tdocs.skipTo(15));
+    assertEquals(15, tdocs.doc());
+    assertTrue(tdocs.skipTo(24));
+    assertEquals(24, tdocs.doc());
+    assertTrue(tdocs.skipTo(25));
+    assertEquals(25, tdocs.doc());
+    assertFalse(tdocs.skipTo(26));
+    
+    // without next
+    tdocs.seek(tb);
+    assertTrue(tdocs.skipTo(5));
+    assertEquals(10, tdocs.doc());
+    assertTrue(tdocs.skipTo(15));
+    assertEquals(15, tdocs.doc());
+    assertTrue(tdocs.skipTo(24));
+    assertEquals(24, tdocs.doc());
+    assertTrue(tdocs.skipTo(25));
+    assertEquals(25, tdocs.doc());
+    assertFalse(tdocs.skipTo(26));
+    
+    // much more than skipInterval documents and therefore with optimization
+    
+    // with next
+    tdocs.seek(tc);
+    assertTrue(tdocs.next());
+    assertEquals(26, tdocs.doc());
+    assertEquals(4, tdocs.freq());
+    assertTrue(tdocs.next());
+    assertEquals(27, tdocs.doc());
+    assertEquals(4, tdocs.freq());
+    assertTrue(tdocs.skipTo(5));
+    assertEquals(28, tdocs.doc());
+    assertTrue(tdocs.skipTo(40));
+    assertEquals(40, tdocs.doc());
+    assertTrue(tdocs.skipTo(57));
+    assertEquals(57, tdocs.doc());
+    assertTrue(tdocs.skipTo(74));
+    assertEquals(74, tdocs.doc());
+    assertTrue(tdocs.skipTo(75));
+    assertEquals(75, tdocs.doc());
+    assertFalse(tdocs.skipTo(76));
+    
+    //without next
+    tdocs.seek(tc);
+    assertTrue(tdocs.skipTo(5));
+    assertEquals(26, tdocs.doc());
+    assertTrue(tdocs.skipTo(40));
+    assertEquals(40, tdocs.doc());
+    assertTrue(tdocs.skipTo(57));
+    assertEquals(57, tdocs.doc());
+    assertTrue(tdocs.skipTo(74));
+    assertEquals(74, tdocs.doc());
+    assertTrue(tdocs.skipTo(75));
+    assertEquals(75, tdocs.doc());
+    assertFalse(tdocs.skipTo(76));
+    
+    tdocs.close();
+    reader.close();
+    dir.close();
   }
   
   private void addDoc(IndexWriter writer, String value) throws IOException

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermEnum.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermEnum.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermEnum.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermEnum.java Fri Jul  1 15:13:53 2005
@@ -21,42 +21,32 @@
 {
   Directory dir = new RAMDirectory();
 
-  public void testTermEnum()
+  public void testTermEnum() throws IOException
   {
     IndexWriter writer = null;
 
-    try {
-      writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
+    writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
 
-      // add 100 documents with term : aaa
-      // add 100 documents with terms: aaa bbb
-      // Therefore, term 'aaa' has document frequency of 200 and term 'bbb' 100
-      for (int i = 0; i < 100; i++) {
-        addDoc(writer, "aaa");
-        addDoc(writer, "aaa bbb");
-      }
-
-      writer.close();
-    }
-    catch (IOException e) {
-      e.printStackTrace();
+    // add 100 documents with term : aaa
+    // add 100 documents with terms: aaa bbb
+    // Therefore, term 'aaa' has document frequency of 200 and term 'bbb' 100
+    for (int i = 0; i < 100; i++) {
+      addDoc(writer, "aaa");
+      addDoc(writer, "aaa bbb");
     }
 
-    try {
-      // verify document frequency of terms in an unoptimized index
-      verifyDocFreq();
-
-      // merge segments by optimizing the index
-      writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
-      writer.optimize();
-      writer.close();
+    writer.close();
 
-      // verify document frequency of terms in an optimized index
-      verifyDocFreq();
-    }
-    catch (IOException e2) {
-      e2.printStackTrace();
-    }
+    // verify document frequency of terms in an unoptimized index
+    verifyDocFreq();
+
+    // merge segments by optimizing the index
+    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
+    writer.optimize();
+    writer.close();
+
+    // verify document frequency of terms in an optimized index
+    verifyDocFreq();
   }
 
   private void verifyDocFreq()
@@ -95,16 +85,10 @@
     termEnum.close();
   }
 
-  private void addDoc(IndexWriter writer, String value)
+  private void addDoc(IndexWriter writer, String value) throws IOException
   {
     Document doc = new Document();
     doc.add(new Field("content", value, Field.Store.NO, Field.Index.TOKENIZED));
-
-    try {
-      writer.addDocument(doc);
-    }
-    catch (IOException e) {
-      e.printStackTrace();
-    }
+    writer.addDocument(doc);
   }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsReader.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsReader.java Fri Jul  1 15:13:53 2005
@@ -24,7 +24,7 @@
     super(s);
   }
 
-  protected void setUp() {
+  protected void setUp() throws IOException {
     for (int i = 0; i < testFields.length; i++) {
       fieldInfos.add(testFields[i], true, true, testFieldsStorePos[i], testFieldsStoreOff[i]);
     }
@@ -42,27 +42,21 @@
         offsets[i][j] = new TermVectorOffsetInfo(j * 10, j * 10 + testTerms[i].length());
       }        
     }
-    try {
-      Arrays.sort(testTerms);
-      for (int j = 0; j < 5; j++) {
-        writer = new TermVectorsWriter(dir, seg, fieldInfos);
-        writer.openDocument();
-
-        for (int k = 0; k < testFields.length; k++) {
-          writer.openField(testFields[k]);
-          for (int i = 0; i < testTerms.length; i++) {
-            writer.addTerm(testTerms[i], 3, positions[i], offsets[i]);      
-          }
-          writer.closeField();
+    Arrays.sort(testTerms);
+    for (int j = 0; j < 5; j++) {
+      writer = new TermVectorsWriter(dir, seg, fieldInfos);
+      writer.openDocument();
+
+      for (int k = 0; k < testFields.length; k++) {
+        writer.openField(testFields[k]);
+        for (int i = 0; i < testTerms.length; i++) {
+          writer.addTerm(testTerms[i], 3, positions[i], offsets[i]);      
         }
-        writer.closeDocument();
-        writer.close();
+        writer.closeField();
       }
-
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }    
+      writer.closeDocument();
+      writer.close();
+    }
   }
 
   protected void tearDown() {
@@ -76,120 +70,90 @@
       assertTrue(dir.fileExists(seg + TermVectorsWriter.TVX_EXTENSION));
   }
   
-  public void testReader() {
-    try {
-      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-      assertTrue(reader != null);
-      TermFreqVector vector = reader.get(0, testFields[0]);
-      assertTrue(vector != null);
-      String [] terms = vector.getTerms();
-      assertTrue(terms != null);
-      assertTrue(terms.length == testTerms.length);
-      for (int i = 0; i < terms.length; i++) {
-        String term = terms[i];
-        //System.out.println("Term: " + term);
-        assertTrue(term.equals(testTerms[i]));
-      }
-      
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
+  public void testReader() throws IOException {
+    TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
+    assertTrue(reader != null);
+    TermFreqVector vector = reader.get(0, testFields[0]);
+    assertTrue(vector != null);
+    String [] terms = vector.getTerms();
+    assertTrue(terms != null);
+    assertTrue(terms.length == testTerms.length);
+    for (int i = 0; i < terms.length; i++) {
+      String term = terms[i];
+      //System.out.println("Term: " + term);
+      assertTrue(term.equals(testTerms[i]));
     }
   }  
   
-  public void testPositionReader() {
-    try {
-      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-      assertTrue(reader != null);
-      TermPositionVector vector;
-      String [] terms;
-      vector = (TermPositionVector)reader.get(0, testFields[0]);
-      assertTrue(vector != null);      
-      terms = vector.getTerms();
-      assertTrue(terms != null);
-      assertTrue(terms.length == testTerms.length);
-      for (int i = 0; i < terms.length; i++) {
-        String term = terms[i];
-        //System.out.println("Term: " + term);
-        assertTrue(term.equals(testTerms[i]));
-        int [] positions = vector.getTermPositions(i);
-        assertTrue(positions != null);
-        assertTrue(positions.length == this.positions[i].length);
-        for (int j = 0; j < positions.length; j++) {
-          int position = positions[j];
-          assertTrue(position == this.positions[i][j]);
-        }
-        TermVectorOffsetInfo [] offset = vector.getOffsets(i);
-        assertTrue(offset != null);
-        assertTrue(offset.length == this.offsets[i].length);
-        for (int j = 0; j < offset.length; j++) {
-          TermVectorOffsetInfo termVectorOffsetInfo = offset[j];
-          assertTrue(termVectorOffsetInfo.equals(offsets[i][j]));
-        }
-      }
-      
-      TermFreqVector freqVector = reader.get(0, testFields[1]); //no pos, no offset
-      assertTrue(freqVector != null);      
-      assertTrue(freqVector instanceof TermPositionVector == false);
-      terms = freqVector.getTerms();
-      assertTrue(terms != null);
-      assertTrue(terms.length == testTerms.length);
-      for (int i = 0; i < terms.length; i++) {
-        String term = terms[i];
-        //System.out.println("Term: " + term);
-        assertTrue(term.equals(testTerms[i]));        
+  public void testPositionReader() throws IOException {
+    TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
+    assertTrue(reader != null);
+    TermPositionVector vector;
+    String [] terms;
+    vector = (TermPositionVector)reader.get(0, testFields[0]);
+    assertTrue(vector != null);      
+    terms = vector.getTerms();
+    assertTrue(terms != null);
+    assertTrue(terms.length == testTerms.length);
+    for (int i = 0; i < terms.length; i++) {
+      String term = terms[i];
+      //System.out.println("Term: " + term);
+      assertTrue(term.equals(testTerms[i]));
+      int [] positions = vector.getTermPositions(i);
+      assertTrue(positions != null);
+      assertTrue(positions.length == this.positions[i].length);
+      for (int j = 0; j < positions.length; j++) {
+        int position = positions[j];
+        assertTrue(position == this.positions[i][j]);
+      }
+      TermVectorOffsetInfo [] offset = vector.getOffsets(i);
+      assertTrue(offset != null);
+      assertTrue(offset.length == this.offsets[i].length);
+      for (int j = 0; j < offset.length; j++) {
+        TermVectorOffsetInfo termVectorOffsetInfo = offset[j];
+        assertTrue(termVectorOffsetInfo.equals(offsets[i][j]));
       }
-      
-      
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
     }
-    catch (ClassCastException cce)
-    {
-      cce.printStackTrace();
-      assertTrue(false);
+    
+    TermFreqVector freqVector = reader.get(0, testFields[1]); //no pos, no offset
+    assertTrue(freqVector != null);      
+    assertTrue(freqVector instanceof TermPositionVector == false);
+    terms = freqVector.getTerms();
+    assertTrue(terms != null);
+    assertTrue(terms.length == testTerms.length);
+    for (int i = 0; i < terms.length; i++) {
+      String term = terms[i];
+      //System.out.println("Term: " + term);
+      assertTrue(term.equals(testTerms[i]));        
     }
   }
   
-  public void testOffsetReader() {
-    try {
-      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-      assertTrue(reader != null);
-      TermPositionVector vector = (TermPositionVector)reader.get(0, testFields[0]);
-      assertTrue(vector != null);
-      String [] terms = vector.getTerms();
-      assertTrue(terms != null);
-      assertTrue(terms.length == testTerms.length);
-      for (int i = 0; i < terms.length; i++) {
-        String term = terms[i];
-        //System.out.println("Term: " + term);
-        assertTrue(term.equals(testTerms[i]));
-        int [] positions = vector.getTermPositions(i);
-        assertTrue(positions != null);
-        assertTrue(positions.length == this.positions[i].length);
-        for (int j = 0; j < positions.length; j++) {
-          int position = positions[j];
-          assertTrue(position == this.positions[i][j]);
-        }
-        TermVectorOffsetInfo [] offset = vector.getOffsets(i);
-        assertTrue(offset != null);
-        assertTrue(offset.length == this.offsets[i].length);
-        for (int j = 0; j < offset.length; j++) {
-          TermVectorOffsetInfo termVectorOffsetInfo = offset[j];
-          assertTrue(termVectorOffsetInfo.equals(offsets[i][j]));
-        }
+  public void testOffsetReader() throws IOException {
+    TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
+    assertTrue(reader != null);
+    TermPositionVector vector = (TermPositionVector)reader.get(0, testFields[0]);
+    assertTrue(vector != null);
+    String [] terms = vector.getTerms();
+    assertTrue(terms != null);
+    assertTrue(terms.length == testTerms.length);
+    for (int i = 0; i < terms.length; i++) {
+      String term = terms[i];
+      //System.out.println("Term: " + term);
+      assertTrue(term.equals(testTerms[i]));
+      int [] positions = vector.getTermPositions(i);
+      assertTrue(positions != null);
+      assertTrue(positions.length == this.positions[i].length);
+      for (int j = 0; j < positions.length; j++) {
+        int position = positions[j];
+        assertTrue(position == this.positions[i][j]);
+      }
+      TermVectorOffsetInfo [] offset = vector.getOffsets(i);
+      assertTrue(offset != null);
+      assertTrue(offset.length == this.offsets[i].length);
+      for (int j = 0; j < offset.length; j++) {
+        TermVectorOffsetInfo termVectorOffsetInfo = offset[j];
+        assertTrue(termVectorOffsetInfo.equals(offsets[i][j]));
       }
-      
-      
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }
-    catch (ClassCastException cce)
-    {
-      cce.printStackTrace();
-      assertTrue(false);
     }
   }
   
@@ -203,18 +167,18 @@
       assertTrue(reader != null);
       //Bad document number, good field number
       reader.get(50, testFields[0]);
-      assertTrue(false);      
+      fail();      
     } catch (IOException e) {
-      assertTrue(true);
+      // expected exception
     }
     try {
       TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
       assertTrue(reader != null);
       //Bad document number, no field
       reader.get(50);
-      assertTrue(false);      
+      fail();      
     } catch (IOException e) {
-      assertTrue(true);
+      // expected exception
     }
     try {
       TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
@@ -223,7 +187,7 @@
       TermFreqVector vector = reader.get(0, "f50");
       assertTrue(vector == null);      
     } catch (IOException e) {
-      assertTrue(false);
+      fail();
     }
   }    
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsWriter.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsWriter.java?rev=208807&r1=208806&r2=208807&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestTermVectorsWriter.java Fri Jul  1 15:13:53 2005
@@ -89,26 +89,21 @@
     }
   }  */  
 
-  public void testWriter() {
-    try {
-      TermVectorsWriter writer = new TermVectorsWriter(dir, seg, fieldInfos);
-      writer.openDocument();
-      assertTrue(writer.isDocumentOpen() == true);
-      writeField(writer, testFields[0]);
-      writer.closeDocument();
-      writer.close();
-      assertTrue(writer.isDocumentOpen() == false);
-      //Check to see the files were created
-      assertTrue(dir.fileExists(seg + TermVectorsWriter.TVD_EXTENSION));
-      assertTrue(dir.fileExists(seg + TermVectorsWriter.TVX_EXTENSION));
-      //Now read it back in
-      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-      assertTrue(reader != null);
-      checkTermVector(reader, 0, testFields[0]);
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }
+  public void testWriter() throws IOException {
+    TermVectorsWriter writer = new TermVectorsWriter(dir, seg, fieldInfos);
+    writer.openDocument();
+    assertTrue(writer.isDocumentOpen() == true);
+    writeField(writer, testFields[0]);
+    writer.closeDocument();
+    writer.close();
+    assertTrue(writer.isDocumentOpen() == false);
+    //Check to see the files were created
+    assertTrue(dir.fileExists(seg + TermVectorsWriter.TVD_EXTENSION));
+    assertTrue(dir.fileExists(seg + TermVectorsWriter.TVX_EXTENSION));
+    //Now read it back in
+    TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
+    assertTrue(reader != null);
+    checkTermVector(reader, 0, testFields[0]);
   }
   
   private void checkTermVector(TermVectorsReader reader, int docNum, String field) throws IOException {
@@ -125,28 +120,24 @@
 
   /**
    * Test one document, multiple fields
+   * @throws IOException
    */
-  public void testMultipleFields() {
-    try {
-      TermVectorsWriter writer = new TermVectorsWriter(dir, seg, fieldInfos);
-      writeDocument(writer, testFields.length);
+  public void testMultipleFields() throws IOException {
+    TermVectorsWriter writer = new TermVectorsWriter(dir, seg, fieldInfos);
+    writeDocument(writer, testFields.length);
 
-      writer.close();
+    writer.close();
 
-      assertTrue(writer.isDocumentOpen() == false);
-      //Check to see the files were created
-      assertTrue(dir.fileExists(seg + TermVectorsWriter.TVD_EXTENSION));
-      assertTrue(dir.fileExists(seg + TermVectorsWriter.TVX_EXTENSION));
-      //Now read it back in
-      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-      assertTrue(reader != null);
+    assertTrue(writer.isDocumentOpen() == false);
+    //Check to see the files were created
+    assertTrue(dir.fileExists(seg + TermVectorsWriter.TVD_EXTENSION));
+    assertTrue(dir.fileExists(seg + TermVectorsWriter.TVX_EXTENSION));
+    //Now read it back in
+    TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
+    assertTrue(reader != null);
 
-      for (int j = 0; j < testFields.length; j++) {
-        checkTermVector(reader, 0, testFields[j]);
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
+    for (int j = 0; j < testFields.length; j++) {
+      checkTermVector(reader, 0, testFields[j]);
     }
   }
 
@@ -177,30 +168,19 @@
   }
 
 
-  public void testMultipleDocuments() {
-
-    try {
-      TermVectorsWriter writer = new TermVectorsWriter(dir, seg, fieldInfos);
-      assertTrue(writer != null);
-      for (int i = 0; i < 10; i++) {
-        writeDocument(writer, testFields.length);
-      }
-      writer.close();
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }      
+  public void testMultipleDocuments() throws IOException {
+    TermVectorsWriter writer = new TermVectorsWriter(dir, seg, fieldInfos);
+    assertTrue(writer != null);
+    for (int i = 0; i < 10; i++) {
+      writeDocument(writer, testFields.length);
+    }
+    writer.close();
     //Do some arbitrary tests
-    try {
-      TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-      for (int i = 0; i < 10; i++) {        
-        assertTrue(reader != null);
-        checkTermVector(reader, 5, testFields[0]);
-        checkTermVector(reader, 2, testFields[2]);
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
-      assertTrue(false);
+    TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
+    for (int i = 0; i < 10; i++) {        
+      assertTrue(reader != null);
+      checkTermVector(reader, 5, testFields[0]);
+      checkTermVector(reader, 2, testFields[2]);
     }
   }
   
@@ -208,23 +188,19 @@
    * Test that no NullPointerException will be raised,
    * when adding one document with a single, empty field
    * and term vectors enabled.
+   * @throws IOException
    *
    */
-  public void testBadSegment() {
-    try {
-      dir = new RAMDirectory();
-      IndexWriter ir = new IndexWriter(dir, new StandardAnalyzer(), true);
-      
-      Document document = new Document();
-      document.add(new Field("tvtest", "", Field.Store.NO, Field.Index.TOKENIZED,
-          Field.TermVector.YES));
-      ir.addDocument(document);
-      ir.close();
-      dir.close();
-    } catch (Exception e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }
+  public void testBadSegment() throws IOException {
+    dir = new RAMDirectory();
+    IndexWriter ir = new IndexWriter(dir, new StandardAnalyzer(), true);
+    
+    Document document = new Document();
+    document.add(new Field("tvtest", "", Field.Store.NO, Field.Index.TOKENIZED,
+        Field.TermVector.YES));
+    ir.addDocument(document);
+    ir.close();
+    dir.close();
   }
 
 }



Mime
View raw message