01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.util.LuceneTestCase;
21: import org.apache.lucene.store.Directory;
22: import org.apache.lucene.store.RAMDirectory;
23: import org.apache.lucene.index.IndexReader;
24: import org.apache.lucene.index.IndexWriter;
25: import org.apache.lucene.analysis.standard.StandardAnalyzer;
26:
27: public class TestCachingWrapperFilter extends LuceneTestCase {
28: public void testCachingWorks() throws Exception {
29: Directory dir = new RAMDirectory();
30: IndexWriter writer = new IndexWriter(dir,
31: new StandardAnalyzer(), true);
32: writer.close();
33:
34: IndexReader reader = IndexReader.open(dir);
35:
36: MockFilter filter = new MockFilter();
37: CachingWrapperFilter cacher = new CachingWrapperFilter(filter);
38:
39: // first time, nested filter is called
40: cacher.bits(reader);
41: assertTrue("first time", filter.wasCalled());
42:
43: // second time, nested filter should not be called
44: filter.clear();
45: cacher.bits(reader);
46: assertFalse("second time", filter.wasCalled());
47:
48: reader.close();
49: }
50: }
|