01: package org.apache.lucene.index;
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 java.io.BufferedReader;
21: import java.io.IOException;
22: import java.io.StringReader;
23: import java.util.HashSet;
24:
25: import org.apache.lucene.util.LuceneTestCase;
26:
27: import org.apache.lucene.analysis.WordlistLoader;
28:
29: public class TestWordlistLoader extends LuceneTestCase {
30:
31: public void testWordlistLoading() throws IOException {
32: String s = "ONE\n two \nthree";
33: HashSet wordSet1 = WordlistLoader
34: .getWordSet(new StringReader(s));
35: checkSet(wordSet1);
36: HashSet wordSet2 = WordlistLoader
37: .getWordSet(new BufferedReader(new StringReader(s)));
38: checkSet(wordSet2);
39: }
40:
41: private void checkSet(HashSet wordset) {
42: assertEquals(3, wordset.size());
43: assertTrue(wordset.contains("ONE")); // case is not modified
44: assertTrue(wordset.contains("two")); // surrounding whitespace is removed
45: assertTrue(wordset.contains("three"));
46: assertFalse(wordset.contains("four"));
47: }
48:
49: }
|