Class 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
    • Constructor Detail

      • BaseTokenStreamTestCase

        public BaseTokenStreamTestCase()
    • Method Detail

      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.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​(org.apache.lucene.analysis.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​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] startOffsets,
                                                     int[] endOffsets,
                                                     String[] types,
                                                     int[] posIncrements,
                                                     Integer finalOffset)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] startOffsets,
                                                     int[] endOffsets,
                                                     String[] types,
                                                     int[] posIncrements)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     String[] types)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] posIncrements)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] startOffsets,
                                                     int[] endOffsets)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] startOffsets,
                                                     int[] endOffsets,
                                                     Integer finalOffset)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] startOffsets,
                                                     int[] endOffsets,
                                                     int[] posIncrements)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] startOffsets,
                                                     int[] endOffsets,
                                                     int[] posIncrements,
                                                     Integer finalOffset)
                                              throws IOException
        Throws:
        IOException
      • assertTokenStreamContents

        public static void assertTokenStreamContents​(org.apache.lucene.analysis.TokenStream ts,
                                                     String[] output,
                                                     int[] startOffsets,
                                                     int[] endOffsets,
                                                     int[] posIncrements,
                                                     int[] posLengths,
                                                     Integer finalOffset)
                                              throws IOException
        Throws:
        IOException
      • assertAnalyzesTo

        public static void assertAnalyzesTo​(org.apache.lucene.analysis.Analyzer a,
                                            String input,
                                            String[] output,
                                            int[] startOffsets,
                                            int[] endOffsets,
                                            String[] types,
                                            int[] posIncrements)
                                     throws IOException
        Throws:
        IOException
      • assertAnalyzesTo

        public static void assertAnalyzesTo​(org.apache.lucene.analysis.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​(org.apache.lucene.analysis.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​(org.apache.lucene.analysis.Analyzer a,
                                            String input,
                                            String[] output)
                                     throws IOException
        Throws:
        IOException
      • assertAnalyzesTo

        public static void assertAnalyzesTo​(org.apache.lucene.analysis.Analyzer a,
                                            String input,
                                            String[] output,
                                            int[] posIncrements)
                                     throws IOException
        Throws:
        IOException
      • assertAnalyzesToPositions

        public static void assertAnalyzesToPositions​(org.apache.lucene.analysis.Analyzer a,
                                                     String input,
                                                     String[] output,
                                                     int[] posIncrements,
                                                     int[] posLengths)
                                              throws IOException
        Throws:
        IOException
      • assertAnalyzesTo

        public static void assertAnalyzesTo​(org.apache.lucene.analysis.Analyzer a,
                                            String input,
                                            String[] output,
                                            int[] startOffsets,
                                            int[] endOffsets)
                                     throws IOException
        Throws:
        IOException
      • assertAnalyzesTo

        public static void assertAnalyzesTo​(org.apache.lucene.analysis.Analyzer a,
                                            String input,
                                            String[] output,
                                            int[] startOffsets,
                                            int[] endOffsets,
                                            int[] posIncrements)
                                     throws IOException
        Throws:
        IOException
      • assertAnalyzesToReuse

        public static void assertAnalyzesToReuse​(org.apache.lucene.analysis.Analyzer a,
                                                 String input,
                                                 String[] output,
                                                 int[] startOffsets,
                                                 int[] endOffsets,
                                                 String[] types,
                                                 int[] posIncrements)
                                          throws IOException
        Throws:
        IOException
      • assertAnalyzesToReuse

        public static void assertAnalyzesToReuse​(org.apache.lucene.analysis.Analyzer a,
                                                 String input,
                                                 String[] output)
                                          throws IOException
        Throws:
        IOException
      • assertAnalyzesToReuse

        public static void assertAnalyzesToReuse​(org.apache.lucene.analysis.Analyzer a,
                                                 String input,
                                                 String[] output,
                                                 int[] posIncrements)
                                          throws IOException
        Throws:
        IOException
      • assertAnalyzesToReuse

        public static void assertAnalyzesToReuse​(org.apache.lucene.analysis.Analyzer a,
                                                 String input,
                                                 String[] output,
                                                 int[] startOffsets,
                                                 int[] endOffsets)
                                          throws IOException
        Throws:
        IOException
      • assertAnalyzesToReuse

        public static void assertAnalyzesToReuse​(org.apache.lucene.analysis.Analyzer a,
                                                 String input,
                                                 String[] output,
                                                 int[] startOffsets,
                                                 int[] endOffsets,
                                                 int[] posIncrements)
                                          throws IOException
        Throws:
        IOException
      • checkOneTermReuse

        public static void checkOneTermReuse​(org.apache.lucene.analysis.Analyzer a,
                                             String input,
                                             String expected)
                                      throws IOException
        Throws:
        IOException
      • checkRandomData

        public static void checkRandomData​(Random random,
                                           org.apache.lucene.analysis.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,
                                           org.apache.lucene.analysis.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,
                                           org.apache.lucene.analysis.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,
                                           org.apache.lucene.analysis.Analyzer a,
                                           int iterations,
                                           int maxWordLength,
                                           boolean simple)
                                    throws IOException
        Throws:
        IOException
      • checkRandomData

        public static void checkRandomData​(Random random,
                                           org.apache.lucene.analysis.Analyzer a,
                                           int iterations,
                                           int maxWordLength,
                                           boolean simple,
                                           boolean offsetsAreCorrect)
                                    throws IOException
        Throws:
        IOException
      • checkAnalysisConsistency

        public static void checkAnalysisConsistency​(Random random,
                                                    org.apache.lucene.analysis.Analyzer a,
                                                    boolean useCharFilter,
                                                    String text)
                                             throws IOException
        Throws:
        IOException
      • checkAnalysisConsistency

        public static void checkAnalysisConsistency​(Random random,
                                                    org.apache.lucene.analysis.Analyzer a,
                                                    boolean useCharFilter,
                                                    String text,
                                                    boolean offsetsAreCorrect)
                                             throws IOException
        Throws:
        IOException