From 1e5eccf552274f4348fc0d5115671c267d3bfdad Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Sat, 20 Sep 2003 20:29:34 +0000 Subject: [PATCH] test case cleanup - no need to catch unexpected exceptions in test cases, let it fail git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150052 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/search/TestRangeQuery.java | 177 +++++++----------- 1 file changed, 72 insertions(+), 105 deletions(-) diff --git a/src/test/org/apache/lucene/search/TestRangeQuery.java b/src/test/org/apache/lucene/search/TestRangeQuery.java index 1b75ad0dba2..e9346b1c48b 100644 --- a/src/test/org/apache/lucene/search/TestRangeQuery.java +++ b/src/test/org/apache/lucene/search/TestRangeQuery.java @@ -1,11 +1,8 @@ package org.apache.lucene.search; -import java.io.IOException; - import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; @@ -14,128 +11,98 @@ import org.apache.lucene.store.RAMDirectory; import junit.framework.TestCase; /** - * * @author goller */ public class TestRangeQuery extends TestCase { - private int docCount = 0; + private int docCount = 0; - public TestRangeQuery() { - super(); - } + public void testExclusive() throws Exception { + Directory dir = new RAMDirectory(); + Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false); + Hits hits = null; - public void testNotInclusive() - { - Directory dir = new RAMDirectory(); - IndexWriter writer = null; - Searcher searcher = null; - Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false); - Hits hits = null; + IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); + addDoc(writer, "A"); + addDoc(writer, "B"); + addDoc(writer, "C"); + addDoc(writer, "D"); + writer.close(); - try { + IndexSearcher searcher = new IndexSearcher(dir); + hits = searcher.search(query); + assertEquals(1, hits.length()); + searcher.close(); - writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); - addDoc(writer, "A"); - addDoc(writer, "B"); - addDoc(writer, "C"); - addDoc(writer, "D"); - writer.close(); + writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); + addDoc(writer, "A"); + addDoc(writer, "B"); + addDoc(writer, "D"); + writer.close(); - searcher = new IndexSearcher(dir); - hits = searcher.search(query); - assertEquals(1, hits.length()); - searcher.close(); + searcher = new IndexSearcher(dir); + hits = searcher.search(query); + assertEquals(1, hits.length()); + searcher.close(); - writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); - addDoc(writer, "A"); - addDoc(writer, "B"); - addDoc(writer, "D"); - writer.close(); + writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false); + addDoc(writer, "C"); + writer.close(); - searcher = new IndexSearcher(dir); - hits = searcher.search(query); - assertEquals(1, hits.length()); - searcher.close(); + searcher = new IndexSearcher(dir); + hits = searcher.search(query); + assertEquals(1, hits.length()); + searcher.close(); + } - writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false); - addDoc(writer, "C"); - writer.close(); + public void testInclusive() throws Exception { + Directory dir = new RAMDirectory(); + IndexWriter writer = null; + Searcher searcher = null; + Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true); + Hits hits = null; - searcher = new IndexSearcher(dir); - hits = searcher.search(query); - assertEquals(1, hits.length()); - searcher.close(); + writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); + addDoc(writer, "A"); + addDoc(writer, "B"); + addDoc(writer, "C"); + addDoc(writer, "D"); + writer.close(); - } - catch (IOException e) { - e.printStackTrace(); - } + searcher = new IndexSearcher(dir); + hits = searcher.search(query); + assertEquals(3, hits.length()); + searcher.close(); - } + writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); + addDoc(writer, "A"); + addDoc(writer, "B"); + addDoc(writer, "D"); + writer.close(); - public void testInclusive() - { - Directory dir = new RAMDirectory(); - IndexWriter writer = null; - Searcher searcher = null; - Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true); - Hits hits = null; + searcher = new IndexSearcher(dir); + hits = searcher.search(query); + assertEquals(2, hits.length()); + searcher.close(); - try { + writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false); + addDoc(writer, "C"); + writer.close(); - writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); - addDoc(writer, "A"); - addDoc(writer, "B"); - addDoc(writer, "C"); - addDoc(writer, "D"); - writer.close(); + searcher = new IndexSearcher(dir); + hits = searcher.search(query); + assertEquals(3, hits.length()); + searcher.close(); + } - searcher = new IndexSearcher(dir); - hits = searcher.search(query); - assertEquals(3, hits.length()); - searcher.close(); + private void addDoc(IndexWriter writer, String content) throws Exception { + Document doc = new Document(); - writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); - addDoc(writer, "A"); - addDoc(writer, "B"); - addDoc(writer, "D"); - writer.close(); + doc.add(Field.Keyword("id", "id" + docCount)); + doc.add(Field.UnStored("content", content)); - searcher = new IndexSearcher(dir); - hits = searcher.search(query); - assertEquals(2, hits.length()); - searcher.close(); - - writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false); - addDoc(writer, "C"); - writer.close(); - - searcher = new IndexSearcher(dir); - hits = searcher.search(query); - assertEquals(3, hits.length()); - searcher.close(); - - } - catch (IOException e) { - e.printStackTrace(); - } - } - - private void addDoc(IndexWriter writer, String content) - { - Document doc = new Document(); - - doc.add(Field.Keyword("id","id" + docCount)); - doc.add(Field.UnStored("content", content)); - - try { - writer.addDocument(doc); - } - catch (IOException e) { - e.printStackTrace(); - } - docCount++; - } + writer.addDocument(doc); + docCount++; + } }