pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / sinks / DateRecognizerSinkTokenizerTest.java
1 package org.apache.lucene.analysis.sinks;
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 java.io.IOException;
20 import java.io.StringReader;
21 import java.text.SimpleDateFormat;
22 import java.util.Locale;
23
24 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
25 import org.apache.lucene.analysis.TeeSinkTokenFilter;
26 import org.apache.lucene.analysis.TeeSinkTokenFilter.SinkTokenStream;
27 import org.apache.lucene.analysis.MockTokenizer;
28
29 public class DateRecognizerSinkTokenizerTest extends BaseTokenStreamTestCase {
30
31   public void test() throws IOException {
32     DateRecognizerSinkFilter sinkFilter = new DateRecognizerSinkFilter(new SimpleDateFormat("MM/dd/yyyy", Locale.US));
33     String test = "The quick red fox jumped over the lazy brown dogs on 7/11/2006  The dogs finally reacted on 7/12/2006";
34     TeeSinkTokenFilter tee = new TeeSinkTokenFilter(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false));
35     SinkTokenStream sink = tee.newSinkTokenStream(sinkFilter);
36     int count = 0;
37     
38     tee.reset();
39     while (tee.incrementToken()) {
40       count++;
41     }
42     assertTrue(count + " does not equal: " + 18, count == 18);
43     
44     int sinkCount = 0;
45     sink.reset();
46     while (sink.incrementToken()) {
47       sinkCount++;
48     }
49     assertTrue("sink Size: " + sinkCount + " is not: " + 2, sinkCount == 2);
50
51   }
52 }