View Javadoc

    1   /*
    2    * To change this template, choose Tools | Templates
    3    * and open the template in the editor.
    4    */
    5   package org.owasp.dependencycheck.data.lucene;
    6
    7   import java.io.IOException;
    8   import java.io.Reader;
    9   import java.io.StringReader;
    10  import org.apache.lucene.analysis.Analyzer;
    11  import org.apache.lucene.analysis.BaseTokenStreamTestCase;
    12  import static org.apache.lucene.analysis.BaseTokenStreamTestCase.assertAnalyzesTo;
    13  import static org.apache.lucene.analysis.BaseTokenStreamTestCase.assertTokenStreamContents;
    14  import static org.apache.lucene.analysis.BaseTokenStreamTestCase.checkOneTerm;
    15  import org.apache.lucene.analysis.MockTokenizer;
    16  import org.apache.lucene.analysis.TokenStream;
    17  import org.apache.lucene.analysis.Tokenizer;
    18  import org.apache.lucene.analysis.core.WhitespaceTokenizer;
    19  import org.apache.lucene.analysis.tokenattributes.TypeAttributeImpl;
    20  import org.apache.lucene.util.Version;
    21  import org.junit.After;
    22  import org.junit.AfterClass;
    23  import org.junit.Before;
    24  import org.junit.BeforeClass;
    25  import org.junit.Test;
    26  import static org.junit.Assert.*;
    27
    28  /**
    29   *
    30   * @author Jeremy Long (jeremy.long@owasp.org)
    31   */
    32  public class TokenPairConcatenatingFilterTest extends BaseTokenStreamTestCase {
    33
    34      @BeforeClass
    35      public static void setUpClass() {
    36      }
    37
    38      @AfterClass
    39      public static void tearDownClass() {
    40      }
    41
    42      @Before
    43      public void setUp() throws Exception {
    44          super.setUp();
    45      }
    46
    47      @After
    48      public void tearDown() throws Exception {
    49          super.tearDown();
    50      }
    51
    52      /**
    53       * test some examples
    54       */
    55      public void testExamples() throws IOException {
    56          Tokenizer wsTokenizer = new WhitespaceTokenizer(Version.LUCENE_43, new StringReader("one two three"));
    57          TokenStream filter = new TokenPairConcatenatingFilter(wsTokenizer);
    58          assertTokenStreamContents(filter,
    59                  new String[]{"one", "onetwo", "two", "twothree", "three"});
    60      }
    61
    62      /**
    63       * Test of clear method, of class TokenPairConcatenatingFilter.
    64       */
    65      @Test
    66      public void testClear() throws IOException {
    67
    68          TokenStream ts = new WhitespaceTokenizer(Version.LUCENE_43, new StringReader("one two three"));
    69          TokenPairConcatenatingFilter filter = new TokenPairConcatenatingFilter(ts);
    70          assertTokenStreamContents(filter, new String[]{"one", "onetwo", "two", "twothree", "three"});
    71
    72          assertNotNull(filter.getPreviousWord());
    73          filter.clear();
    74          assertNull(filter.getPreviousWord());
    75          assertTrue(filter.getWords().isEmpty());
    76      }
    77  }