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: import java.text.SimpleDateFormat;
27:
28: public class DateRecognizerSinkTokenizerTest extends TestCase {
29:
30: public DateRecognizerSinkTokenizerTest(String s) {
31: super (s);
32: }
33:
34: protected void setUp() {
35: }
36:
37: protected void tearDown() {
38:
39: }
40:
41: public void test() throws IOException {
42: DateRecognizerSinkTokenizer sink = new DateRecognizerSinkTokenizer(
43: new SimpleDateFormat("MM/dd/yyyy"));
44: String test = "The quick red fox jumped over the lazy brown dogs on 7/11/2006 The dogs finally reacted on 7/12/2006";
45: TeeTokenFilter tee = new TeeTokenFilter(
46: new WhitespaceTokenizer(new StringReader(test)), sink);
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: if (tok.termBuffer()[0] == '7') {
52: assertTrue(
53: tok.type() + " is not equal to "
54: + DateRecognizerSinkTokenizer.DATE_TYPE,
55: tok.type().equals(
56: DateRecognizerSinkTokenizer.DATE_TYPE) == true);
57: }
58: count++;
59: }
60: assertTrue(count + " does not equal: " + 18, count == 18);
61: assertTrue("sink Size: " + sink.getTokens().size()
62: + " is not: " + 2, sink.getTokens().size() == 2);
63:
64: }
65: }
|