lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r208846 - in /lucene/java/trunk/src/test/org/apache/lucene: document/TestDateTools.java document/TestDocument.java index/DocHelper.java index/TestSegmentTermDocs.java queryParser/TestQueryParser.java search/TestMultiSearcher.java
Date Sat, 02 Jul 2005 16:40:49 GMT
Author: dnaber
Date: Sat Jul  2 09:40:44 2005
New Revision: 208846

URL: http://svn.apache.org/viewcvs?rev=208846&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/document/TestDateTools.java
    lucene/java/trunk/src/test/org/apache/lucene/document/TestDocument.java
    lucene/java/trunk/src/test/org/apache/lucene/index/DocHelper.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
    lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java?rev=208846&r1=208845&r2=208846&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java Sat Jul  2 09:40:44
2005
@@ -40,15 +40,15 @@
     try {
       d = DateTools.stringToDate("97");    // no date
       fail();
-    } catch(ParseException e) { /* expected excpetion */ }
+    } catch(ParseException e) { /* expected exception */ }
     try {
       d = DateTools.stringToDate("200401011235009999");    // no date
       fail();
-    } catch(ParseException e) { /* expected excpetion */ }
+    } catch(ParseException e) { /* expected exception */ }
     try {
       d = DateTools.stringToDate("aaaa");    // no date
       fail();
-    } catch(ParseException e) { /* expected excpetion */ }
+    } catch(ParseException e) { /* expected exception */ }
 
   }
   

Modified: lucene/java/trunk/src/test/org/apache/lucene/document/TestDocument.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/document/TestDocument.java?rev=208846&r1=208845&r2=208846&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/document/TestDocument.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/document/TestDocument.java Sat Jul  2 09:40:44
2005
@@ -172,19 +172,8 @@
         Hits hits = searcher.search(query);
 	assertEquals(1, hits.length());
 
-        try
-        {
-            doAssert(hits.doc(0), true);
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace(System.err);
-            System.err.print("\n");
-        }
-        finally
-        {
-            searcher.close();
-        }
+         doAssert(hits.doc(0), true);
+         searcher.close();
     }
 
     private Document makeDocumentWithFields()

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/DocHelper.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/index/DocHelper.java?rev=208846&r1=208845&r2=208846&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/DocHelper.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/DocHelper.java Sat Jul  2 09:40:44
2005
@@ -87,8 +87,9 @@
    * Writes the document to the directory using a segment named "test"
    * @param dir
    * @param doc
+   * @throws IOException
    */ 
-  public static void writeDoc(Directory dir, Document doc)
+  public static void writeDoc(Directory dir, Document doc) throws IOException
   {
     writeDoc(dir, "test", doc);
   }
@@ -98,8 +99,9 @@
    * @param dir
    * @param segment
    * @param doc
+   * @throws IOException
    */ 
-  public static void writeDoc(Directory dir, String segment, Document doc)
+  public static void writeDoc(Directory dir, String segment, Document doc) throws IOException
   {
     Analyzer analyzer = new WhitespaceAnalyzer();
     Similarity similarity = Similarity.getDefault();
@@ -112,8 +114,9 @@
    * @param analyzer
    * @param similarity
    * @param doc
+   * @throws IOException
    */ 
-  public static void writeDoc(Directory dir, Analyzer analyzer, Similarity similarity, Document
doc)
+  public static void writeDoc(Directory dir, Analyzer analyzer, Similarity similarity, Document
doc) throws IOException
   {
     writeDoc(dir, analyzer, similarity, "test", doc);
   }
@@ -125,15 +128,12 @@
    * @param similarity
    * @param segment
    * @param doc
+   * @throws IOException
    */ 
-  public static void writeDoc(Directory dir, Analyzer analyzer, Similarity similarity, String
segment, Document doc)
+  public static void writeDoc(Directory dir, Analyzer analyzer, Similarity similarity, String
segment, Document doc) throws IOException
   {
     DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
-    try {
-      writer.addDocument(segment, doc);
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
+    writer.addDocument(segment, doc);
   }
 
   public static int numFields(Document doc) {

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=208846&r1=208845&r2=208846&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 Sat Jul  2
09:40:44 2005
@@ -33,7 +33,7 @@
     super(s);
   }
 
-  protected void setUp() {
+  protected void setUp() throws IOException {
     DocHelper.setupDoc(testDoc);
     DocHelper.writeDoc(dir, testDoc);
   }

Modified: lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java?rev=208846&r1=208845&r2=208846&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java Sat Jul
 2 09:40:44 2005
@@ -497,19 +497,19 @@
   public void testCustomQueryParserWildcard() {
     try {
       new QPTestParser("contents", new WhitespaceAnalyzer()).parse("a?t");
+      fail("Wildcard queries should not be allowed");
     } catch (ParseException expected) {
-      return;
+      // expected exception
     }
-    fail("Wildcard queries should not be allowed");
   }
 
   public void testCustomQueryParserFuzzy() throws Exception {
     try {
       new QPTestParser("contents", new WhitespaceAnalyzer()).parse("xunit~");
+      fail("Fuzzy queries should not be allowed");
     } catch (ParseException expected) {
-      return;
+      // expected exception
     }
-    fail("Fuzzy queries should not be allowed");
   }
 
   public void testBooleanQuery() throws Exception {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java?rev=208846&r1=208845&r2=208846&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java Sat Jul  2
09:40:44 2005
@@ -112,19 +112,11 @@
 
         assertEquals(3, hits.length());
 
-        try {
-            // iterating over the hit documents
-            for (int i = 0; i < hits.length(); i++) {
-                Document d = hits.doc(i);
-            }
-        }
-        catch (ArrayIndexOutOfBoundsException e)
-        {
-            fail("ArrayIndexOutOfBoundsException thrown: " + e.getMessage());
-            e.printStackTrace();
-        } finally{
-            mSearcher.close();
+        // iterating over the hit documents
+        for (int i = 0; i < hits.length(); i++) {
+            Document d = hits.doc(i);
         }
+        mSearcher.close();
 
 
         //--------------------------------------------------------------------
@@ -149,20 +141,12 @@
 
         assertEquals(4, hits2.length());
 
-        try {
-            // iterating over the hit documents
-            for (int i = 0; i < hits2.length(); i++) {
-                // no exception should happen at this point
-                Document d = hits2.doc(i);
-            }
-        }
-        catch (Exception e)
-        {
-            fail("Exception thrown: " + e.getMessage());
-            e.printStackTrace();
-        } finally{
-            mSearcher2.close();
+        // iterating over the hit documents
+        for (int i = 0; i < hits2.length(); i++) {
+            // no exception should happen at this point
+            Document d = hits2.doc(i);
         }
+        mSearcher2.close();
 
         //--------------------------------------------------------------------
         // scenario 3
@@ -191,18 +175,10 @@
 
         assertEquals(3, hits3.length());
 
-        try {
-            // iterating over the hit documents
-            for (int i = 0; i < hits3.length(); i++) {
-                Document d = hits3.doc(i);
-            }
-        }
-        catch (IOException e)
-        {
-            fail("IOException thrown: " + e.getMessage());
-            e.printStackTrace();
-        } finally{
-            mSearcher3.close();
+        // iterating over the hit documents
+        for (int i = 0; i < hits3.length(); i++) {
+            Document d = hits3.doc(i);
         }
+        mSearcher3.close();
     }
 }



Mime
View raw message