Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
29   104   8   7.25
6   66   0.28   4
4     2  
1    
 
  TestBooleanPrefixQuery       Line # 41 29 8 84.6% 0.84615386
 
  (1)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import junit.framework.TestCase;
20    import junit.framework.Test;
21    import junit.framework.TestSuite;
22    import junit.textui.TestRunner;
23    import org.apache.lucene.store.RAMDirectory;
24    import org.apache.lucene.index.IndexWriter;
25    import org.apache.lucene.index.Term;
26    import org.apache.lucene.index.IndexReader;
27    import org.apache.lucene.analysis.WhitespaceAnalyzer;
28    import org.apache.lucene.document.Document;
29    import org.apache.lucene.document.Field;
30    import org.apache.lucene.search.PrefixQuery;
31    import org.apache.lucene.search.Query;
32    import org.apache.lucene.search.BooleanQuery;
33   
34    import java.io.IOException;
35   
36    /**
37    * @author schnee
38    * @version $Id: TestBooleanPrefixQuery.java 150492 2004-09-06 22:01:49Z dnaber $
39    **/
40   
 
41    public class TestBooleanPrefixQuery extends TestCase {
42   
 
43  0 toggle public static void main(String[] args) {
44  0 TestRunner.run(suite());
45    }
46   
 
47  1 toggle public static Test suite() {
48  1 return new TestSuite(TestBooleanPrefixQuery.class);
49    }
50   
 
51  1 toggle public TestBooleanPrefixQuery(String name) {
52  1 super(name);
53    }
54   
 
55  1 toggle public void testMethod() {
56  1 RAMDirectory directory = new RAMDirectory();
57   
58  1 String[] categories = new String[]{"food",
59    "foodanddrink",
60    "foodanddrinkandgoodtimes",
61    "food and drink"};
62   
63  1 Query rw1 = null;
64  1 Query rw2 = null;
65  1 try {
66  1 IndexWriter writer = new IndexWriter(directory, new
67    WhitespaceAnalyzer(), true);
68  5 for (int i = 0; i < categories.length; i++) {
69  4 Document doc = new Document();
70  4 doc.add(new Field("category", categories[i], Field.Store.YES, Field.Index.UN_TOKENIZED));
71  4 writer.addDocument(doc);
72    }
73  1 writer.close();
74   
75  1 IndexReader reader = IndexReader.open(directory);
76  1 PrefixQuery query = new PrefixQuery(new Term("category", "foo"));
77   
78  1 rw1 = query.rewrite(reader);
79   
80  1 BooleanQuery bq = new BooleanQuery();
81  1 bq.add(query, BooleanClause.Occur.MUST);
82   
83  1 rw2 = bq.rewrite(reader);
84    } catch (IOException e) {
85  0 fail(e.getMessage());
86    }
87   
88  1 BooleanQuery bq1 = null;
89  1 if (rw1 instanceof BooleanQuery) {
90  1 bq1 = (BooleanQuery) rw1;
91    }
92   
93  1 BooleanQuery bq2 = null;
94  1 if (rw2 instanceof BooleanQuery) {
95  1 bq2 = (BooleanQuery) rw2;
96    } else {
97  0 fail("Rewrite");
98    }
99   
100  1 assertEquals("Number of Clauses Mismatch", bq1.getClauses().length,
101    bq2.getClauses().length);
102    }
103    }
104