org.apache.lucene.analysis
Class BaseTokenStreamTestCase

java.lang.Object
  extended by org.junit.Assert
      extended by org.apache.lucene.util.LuceneTestCase
          extended by org.apache.lucene.analysis.BaseTokenStreamTestCase

public abstract class BaseTokenStreamTestCase
extends LuceneTestCase

Base class for all Lucene unit tests that use TokenStreams.

When writing unit tests for analysis components, its highly recommended to use the helper methods here (especially in conjunction with MockAnalyzer or MockTokenizer), as they contain many assertions and checks to catch bugs.

See Also:
MockAnalyzer, MockTokenizer

Nested Class Summary
static interface BaseTokenStreamTestCase.CheckClearAttributesAttribute
          Attribute that records if it was cleared or not.
static class BaseTokenStreamTestCase.CheckClearAttributesAttributeImpl
          Attribute that records if it was cleared or not.
 
Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase
LuceneTestCase.AwaitsFix, LuceneTestCase.BadApple, LuceneTestCase.Nightly, LuceneTestCase.Slow, LuceneTestCase.SuppressCodecs, LuceneTestCase.Weekly
 
Field Summary
 
Fields inherited from class org.apache.lucene.util.LuceneTestCase
classRules, DEFAULT_LINE_DOCS_FILE, doesntSupportOffsets, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, PREFLEX_IMPERSONATION_IS_ACTIVE, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_BADAPPLES, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEMP_DIR, TEST_AWAITSFIX, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_VERSION_CURRENT, TEST_WEEKLY, VERBOSE
 
Constructor Summary
BaseTokenStreamTestCase()
           
 
Method Summary
static void assertAnalyzesTo(Analyzer a, String input, String[] output)
           
static void assertAnalyzesTo(Analyzer a, String input, String[] output, int[] posIncrements)
           
static void assertAnalyzesTo(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets)
           
static void assertAnalyzesTo(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets, int[] posIncrements)
           
static void assertAnalyzesTo(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements)
           
static void assertAnalyzesTo(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements, int[] posLengths)
           
static void assertAnalyzesTo(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements, int[] posLengths, boolean offsetsAreCorrect)
           
static void assertAnalyzesTo(Analyzer a, String input, String[] output, String[] types)
           
static void assertAnalyzesToPositions(Analyzer a, String input, String[] output, int[] posIncrements, int[] posLengths)
           
static void assertAnalyzesToReuse(Analyzer a, String input, String[] output)
           
static void assertAnalyzesToReuse(Analyzer a, String input, String[] output, int[] posIncrements)
           
static void assertAnalyzesToReuse(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets)
           
static void assertAnalyzesToReuse(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets, int[] posIncrements)
           
static void assertAnalyzesToReuse(Analyzer a, String input, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements)
           
static void assertAnalyzesToReuse(Analyzer a, String input, String[] output, String[] types)
           
static void assertTokenStreamContents(TokenStream ts, String[] output)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] posIncrements)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, int[] posIncrements)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, int[] posIncrements, int[] posLengths, Integer finalOffset)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, int[] posIncrements, Integer finalOffset)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, Integer finalOffset)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements, int[] posLengths, Integer finalOffset)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements, int[] posLengths, Integer finalOffset, boolean offsetsAreCorrect)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, int[] startOffsets, int[] endOffsets, String[] types, int[] posIncrements, Integer finalOffset)
           
static void assertTokenStreamContents(TokenStream ts, String[] output, String[] types)
           
static void checkAnalysisConsistency(Random random, Analyzer a, boolean useCharFilter, String text)
           
static void checkAnalysisConsistency(Random random, Analyzer a, boolean useCharFilter, String text, boolean offsetsAreCorrect)
           
static void checkOneTerm(Analyzer a, String input, String expected)
           
static void checkOneTermReuse(Analyzer a, String input, String expected)
           
static void checkRandomData(Random random, Analyzer a, int iterations)
          utility method for blasting tokenstreams with data to make sure they don't do anything crazy
static void checkRandomData(Random random, Analyzer a, int iterations, boolean simple)
          utility method for blasting tokenstreams with data to make sure they don't do anything crazy
static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength)
          utility method for blasting tokenstreams with data to make sure they don't do anything crazy
static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean simple)
           
static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean simple, boolean offsetsAreCorrect)
           
static String escape(String s)
           
protected  String toDot(Analyzer a, String inputText)
           
protected  void toDotFile(Analyzer a, String inputText, String localFileName)
           
 
Methods inherited from class org.apache.lucene.util.LuceneTestCase
assertSaneFieldCaches, asSet, assumeFalse, assumeNoException, assumeTrue, atLeast, atLeast, closeAfterSuite, closeAfterTest, defaultCodecSupportsDocValues, defaultCodecSupportsSortedSet, dumpArray, dumpIterator, getDataFile, getOnlySegmentReader, getTestClass, getTestName, isTestThread, localeForName, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMockDirectory, newMockDirectory, newMockFSDirectory, newSearcher, newSearcher, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, random, randomLocale, randomTimeZone, rarely, rarely, setUp, tearDown, usually, usually
 
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseTokenStreamTestCase

public BaseTokenStreamTestCase()
Method Detail

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             String[] types,
                                             int[] posIncrements,
                                             int[] posLengths,
                                             Integer finalOffset,
                                             boolean offsetsAreCorrect)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             String[] types,
                                             int[] posIncrements,
                                             int[] posLengths,
                                             Integer finalOffset)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             String[] types,
                                             int[] posIncrements,
                                             Integer finalOffset)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             String[] types,
                                             int[] posIncrements)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             String[] types)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] posIncrements)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             Integer finalOffset)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             int[] posIncrements)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             int[] posIncrements,
                                             Integer finalOffset)
                                      throws IOException
Throws:
IOException

assertTokenStreamContents

public static void assertTokenStreamContents(TokenStream ts,
                                             String[] output,
                                             int[] startOffsets,
                                             int[] endOffsets,
                                             int[] posIncrements,
                                             int[] posLengths,
                                             Integer finalOffset)
                                      throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output,
                                    int[] startOffsets,
                                    int[] endOffsets,
                                    String[] types,
                                    int[] posIncrements)
                             throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output,
                                    int[] startOffsets,
                                    int[] endOffsets,
                                    String[] types,
                                    int[] posIncrements,
                                    int[] posLengths)
                             throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output,
                                    int[] startOffsets,
                                    int[] endOffsets,
                                    String[] types,
                                    int[] posIncrements,
                                    int[] posLengths,
                                    boolean offsetsAreCorrect)
                             throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output)
                             throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output,
                                    String[] types)
                             throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output,
                                    int[] posIncrements)
                             throws IOException
Throws:
IOException

assertAnalyzesToPositions

public static void assertAnalyzesToPositions(Analyzer a,
                                             String input,
                                             String[] output,
                                             int[] posIncrements,
                                             int[] posLengths)
                                      throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output,
                                    int[] startOffsets,
                                    int[] endOffsets)
                             throws IOException
Throws:
IOException

assertAnalyzesTo

public static void assertAnalyzesTo(Analyzer a,
                                    String input,
                                    String[] output,
                                    int[] startOffsets,
                                    int[] endOffsets,
                                    int[] posIncrements)
                             throws IOException
Throws:
IOException

assertAnalyzesToReuse

public static void assertAnalyzesToReuse(Analyzer a,
                                         String input,
                                         String[] output,
                                         int[] startOffsets,
                                         int[] endOffsets,
                                         String[] types,
                                         int[] posIncrements)
                                  throws IOException
Throws:
IOException

assertAnalyzesToReuse

public static void assertAnalyzesToReuse(Analyzer a,
                                         String input,
                                         String[] output)
                                  throws IOException
Throws:
IOException

assertAnalyzesToReuse

public static void assertAnalyzesToReuse(Analyzer a,
                                         String input,
                                         String[] output,
                                         String[] types)
                                  throws IOException
Throws:
IOException

assertAnalyzesToReuse

public static void assertAnalyzesToReuse(Analyzer a,
                                         String input,
                                         String[] output,
                                         int[] posIncrements)
                                  throws IOException
Throws:
IOException

assertAnalyzesToReuse

public static void assertAnalyzesToReuse(Analyzer a,
                                         String input,
                                         String[] output,
                                         int[] startOffsets,
                                         int[] endOffsets)
                                  throws IOException
Throws:
IOException

assertAnalyzesToReuse

public static void assertAnalyzesToReuse(Analyzer a,
                                         String input,
                                         String[] output,
                                         int[] startOffsets,
                                         int[] endOffsets,
                                         int[] posIncrements)
                                  throws IOException
Throws:
IOException

checkOneTerm

public static void checkOneTerm(Analyzer a,
                                String input,
                                String expected)
                         throws IOException
Throws:
IOException

checkOneTermReuse

public static void checkOneTermReuse(Analyzer a,
                                     String input,
                                     String expected)
                              throws IOException
Throws:
IOException

checkRandomData

public static void checkRandomData(Random random,
                                   Analyzer a,
                                   int iterations)
                            throws IOException
utility method for blasting tokenstreams with data to make sure they don't do anything crazy

Throws:
IOException

checkRandomData

public static void checkRandomData(Random random,
                                   Analyzer a,
                                   int iterations,
                                   int maxWordLength)
                            throws IOException
utility method for blasting tokenstreams with data to make sure they don't do anything crazy

Throws:
IOException

checkRandomData

public static void checkRandomData(Random random,
                                   Analyzer a,
                                   int iterations,
                                   boolean simple)
                            throws IOException
utility method for blasting tokenstreams with data to make sure they don't do anything crazy

Parameters:
simple - true if only ascii strings will be used (try to avoid)
Throws:
IOException

checkRandomData

public static void checkRandomData(Random random,
                                   Analyzer a,
                                   int iterations,
                                   int maxWordLength,
                                   boolean simple)
                            throws IOException
Throws:
IOException

checkRandomData

public static void checkRandomData(Random random,
                                   Analyzer a,
                                   int iterations,
                                   int maxWordLength,
                                   boolean simple,
                                   boolean offsetsAreCorrect)
                            throws IOException
Throws:
IOException

escape

public static String escape(String s)

checkAnalysisConsistency

public static void checkAnalysisConsistency(Random random,
                                            Analyzer a,
                                            boolean useCharFilter,
                                            String text)
                                     throws IOException
Throws:
IOException

checkAnalysisConsistency

public static void checkAnalysisConsistency(Random random,
                                            Analyzer a,
                                            boolean useCharFilter,
                                            String text,
                                            boolean offsetsAreCorrect)
                                     throws IOException
Throws:
IOException

toDot

protected String toDot(Analyzer a,
                       String inputText)
                throws IOException
Throws:
IOException

toDotFile

protected void toDotFile(Analyzer a,
                         String inputText,
                         String localFileName)
                  throws IOException
Throws:
IOException


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.