From 42c3d11f07a3c766d0ab89edb5df1304c0b0c56b Mon Sep 17 00:00:00 2001 From: Daniel Naber Date: Thu, 31 May 2007 19:00:30 +0000 Subject: [PATCH] small cleanup only: imports; no need for try...catch(...) { fail(); } in a test case git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@543216 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/search/spell/TestSpellChecker.java | 96 +++++++++---------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java b/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java index 13ce12705e6..cd975596cd3 100755 --- a/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java +++ b/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java @@ -1,22 +1,23 @@ package org.apache.lucene.search.spell; -import junit.framework.*; -import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.analysis.SimpleAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.util.English; -import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexReader; - import java.io.IOException; +import junit.framework.TestCase; + +import org.apache.lucene.analysis.SimpleAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.util.English; /** - * Test case + * Spell checker test case * * @author Nicolas Maisonneuve */ @@ -45,61 +46,55 @@ public class TestSpellChecker extends TestCase { } - public void testBuild() { - try { - IndexReader r = IndexReader.open(userindex); + public void testBuild() throws CorruptIndexException, IOException { + IndexReader r = IndexReader.open(userindex); - spellChecker.clearIndex(); + spellChecker.clearIndex(); - addwords(r, "field1"); - int num_field1 = this.numdoc(); + addwords(r, "field1"); + int num_field1 = this.numdoc(); - addwords(r, "field2"); - int num_field2 = this.numdoc(); + addwords(r, "field2"); + int num_field2 = this.numdoc(); - assertEquals(num_field2, num_field1 + 1); + assertEquals(num_field2, num_field1 + 1); - // test small word - String[] similar = spellChecker.suggestSimilar("fvie", 2); - assertEquals(1, similar.length); - assertEquals(similar[0], "five"); + // test small word + String[] similar = spellChecker.suggestSimilar("fvie", 2); + assertEquals(1, similar.length); + assertEquals(similar[0], "five"); - similar = spellChecker.suggestSimilar("five", 2); - assertEquals(1, similar.length); - assertEquals(similar[0], "nine"); // don't suggest a word for itself + similar = spellChecker.suggestSimilar("five", 2); + assertEquals(1, similar.length); + assertEquals(similar[0], "nine"); // don't suggest a word for itself - similar = spellChecker.suggestSimilar("fiv", 2); - assertEquals(1, similar.length); - assertEquals(similar[0], "five"); + similar = spellChecker.suggestSimilar("fiv", 2); + assertEquals(1, similar.length); + assertEquals(similar[0], "five"); - similar = spellChecker.suggestSimilar("ive", 2); - assertEquals(1, similar.length); - assertEquals(similar[0], "five"); + similar = spellChecker.suggestSimilar("ive", 2); + assertEquals(1, similar.length); + assertEquals(similar[0], "five"); - similar = spellChecker.suggestSimilar("fives", 2); - assertEquals(1, similar.length); - assertEquals(similar[0], "five"); + similar = spellChecker.suggestSimilar("fives", 2); + assertEquals(1, similar.length); + assertEquals(similar[0], "five"); - similar = spellChecker.suggestSimilar("fie", 2); - assertEquals(1, similar.length); - assertEquals(similar[0], "five"); + similar = spellChecker.suggestSimilar("fie", 2); + assertEquals(1, similar.length); + assertEquals(similar[0], "five"); - similar = spellChecker.suggestSimilar("fi", 2); - assertEquals(0, similar.length); + similar = spellChecker.suggestSimilar("fi", 2); + assertEquals(0, similar.length); - // test restraint to a field - similar = spellChecker.suggestSimilar("tousand", 10, r, "field1", false); - assertEquals(0, similar.length); // there isn't the term thousand in the field field1 + // test restraint to a field + similar = spellChecker.suggestSimilar("tousand", 10, r, "field1", false); + assertEquals(0, similar.length); // there isn't the term thousand in the field field1 - similar = spellChecker.suggestSimilar("tousand", 10, r, "field2", false); - assertEquals(1, similar.length); // there is the term thousand in the field field2 - } catch (IOException e) { - e.printStackTrace(); - fail(); - } + similar = spellChecker.suggestSimilar("tousand", 10, r, "field2", false); + assertEquals(1, similar.length); // there is the term thousand in the field field2 } - private void addwords(IndexReader r, String field) throws IOException { long time = System.currentTimeMillis(); spellChecker.indexDictionary(new LuceneDictionary(r, field)); @@ -115,4 +110,5 @@ public class TestSpellChecker extends TestCase { rs.close(); return num; } + }