01: package org.apache.lucene.analysis.sinks;
02:
03: /**
04: * Copyright 2004 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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.analysis.TeeTokenFilter;
21: import org.apache.lucene.analysis.WhitespaceTokenizer;
22: import org.apache.lucene.analysis.Token;
23:
24: import java.io.StringReader;
25: import java.io.IOException;
26:
27: public class TokenRangeSinkTokenizerTest extends TestCase {
28:
29: public TokenRangeSinkTokenizerTest(String s) {
30: super (s);
31: }
32:
33: protected void setUp() {
34: }
35:
36: protected void tearDown() {
37:
38: }
39:
40: public void test() throws IOException {
41: TokenRangeSinkTokenizer rangeToks = new TokenRangeSinkTokenizer(
42: 2, 4);
43: String test = "The quick red fox jumped over the lazy brown dogs";
44: TeeTokenFilter tee = new TeeTokenFilter(
45: new WhitespaceTokenizer(new StringReader(test)),
46: rangeToks);
47: Token tok = null;
48: int count = 0;
49: while ((tok = tee.next()) != null) {
50: assertTrue("tok is null and it shouldn't be", tok != null);
51: count++;
52: }
53: assertTrue(count + " does not equal: " + 10, count == 10);
54: assertTrue("rangeToks Size: " + rangeToks.getTokens().size()
55: + " is not: " + 2, rangeToks.getTokens().size() == 2);
56: }
57: }
|