KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > TestCachingWrapperFilter


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 org.apache.lucene.store.Directory;
21 import org.apache.lucene.store.RAMDirectory;
22 import org.apache.lucene.index.IndexReader;
23 import org.apache.lucene.index.IndexWriter;
24 import org.apache.lucene.analysis.standard.StandardAnalyzer;
25
26 public class TestCachingWrapperFilter extends TestCase {
27   public void testCachingWorks() throws Exception JavaDoc {
28     Directory dir = new RAMDirectory();
29     IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true);
30     writer.close();
31
32     IndexReader reader = IndexReader.open(dir);
33
34     MockFilter filter = new MockFilter();
35     CachingWrapperFilter cacher = new CachingWrapperFilter(filter);
36
37     // first time, nested filter is called
38
cacher.bits(reader);
39     assertTrue("first time", filter.wasCalled());
40
41     // second time, nested filter should not be called
42
filter.clear();
43     cacher.bits(reader);
44     assertFalse("second time", filter.wasCalled());
45
46     reader.close();
47  }
48 }
49
Popular Tags