Apache Solr open-source search software
clean up exception handling: there's no need to manually catch exceptions in test cases (unless you expect the exception to be thrown)
Daniel Naberf2ac11048255
diff --git a/src/test/org/apache/lucene/document/TestDateTools.java b/src/test/org/apache/lucene/document/TestDateTools.javaindex 776742fe877..2a22f369b02 100644--- a/src/test/org/apache/lucene/document/TestDateTools.java+++ b/src/test/org/apache/lucene/document/TestDateTools.java@@ -40,15 +40,15 @@ public class TestDateTools extends TestCase {try {d = DateTools.stringToDate("97"); // no datefail();- } catch(ParseException e) { /* expected excpetion */ }+ } catch(ParseException e) { /* expected exception */ }try {d = DateTools.stringToDate("200401011235009999"); // no datefail();- } catch(ParseException e) { /* expected excpetion */ }+ } catch(ParseException e) { /* expected exception */ }try {d = DateTools.stringToDate("aaaa"); // no datefail();- } catch(ParseException e) { /* expected excpetion */ }+ } catch(ParseException e) { /* expected exception */ }}diff --git a/src/test/org/apache/lucene/document/TestDocument.java b/src/test/org/apache/lucene/document/TestDocument.javaindex 182056552d0..937c7fff4f2 100644--- a/src/test/org/apache/lucene/document/TestDocument.java+++ b/src/test/org/apache/lucene/document/TestDocument.java@@ -172,19 +172,8 @@ public class TestDocument extends TestCaseHits 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()diff --git a/src/test/org/apache/lucene/index/DocHelper.java b/src/test/org/apache/lucene/index/DocHelper.javaindex 47472d34397..9620e23ebca 100644--- a/src/test/org/apache/lucene/index/DocHelper.java+++ b/src/test/org/apache/lucene/index/DocHelper.java@@ -87,8 +87,9 @@ class DocHelper {* 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 @@ class DocHelper {* @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 @@ class DocHelper {* @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 @@ class DocHelper {* @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) {diff --git a/src/test/org/apache/lucene/index/TestSegmentTermDocs.java b/src/test/org/apache/lucene/index/TestSegmentTermDocs.javaindex 5472c992d82..0f45e52f724 100644--- a/src/test/org/apache/lucene/index/TestSegmentTermDocs.java+++ b/src/test/org/apache/lucene/index/TestSegmentTermDocs.java@@ -33,7 +33,7 @@ public class TestSegmentTermDocs extends TestCase {super(s);}- protected void setUp() {+ protected void setUp() throws IOException {DocHelper.setupDoc(testDoc);DocHelper.writeDoc(dir, testDoc);}diff --git a/src/test/org/apache/lucene/queryParser/TestQueryParser.java b/src/test/org/apache/lucene/queryParser/TestQueryParser.javaindex e409d4d5715..36a18423f1a 100644--- a/src/test/org/apache/lucene/queryParser/TestQueryParser.java+++ b/src/test/org/apache/lucene/queryParser/TestQueryParser.java@@ -497,19 +497,19 @@ public class TestQueryParser extends TestCase {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 {diff --git a/src/test/org/apache/lucene/search/TestMultiSearcher.java b/src/test/org/apache/lucene/search/TestMultiSearcher.javaindex 490fa8989f2..c27e1480534 100644--- a/src/test/org/apache/lucene/search/TestMultiSearcher.java+++ b/src/test/org/apache/lucene/search/TestMultiSearcher.java@@ -112,19 +112,11 @@ public class TestMultiSearcher extends TestCaseassertEquals(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 @@ public class TestMultiSearcher extends TestCaseassertEquals(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 @@ public class TestMultiSearcher extends TestCaseassertEquals(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();}}