View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core is free software: you can redistribute it and/or modify it
    5    * under the terms of the GNU General Public License as published by the Free
    6    * Software Foundation, either version 3 of the License, or (at your option) any
    7    * later version.
    8    *
    9    * Dependency-check-core is distributed in the hope that it will be useful, but
    10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12   * details.
    13   *
    14   * You should have received a copy of the GNU General Public License along with
    15   * dependency-check-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.data.lucene;
    20
    21  import org.owasp.dependencycheck.data.lucene.LuceneUtils;
    22  import org.junit.After;
    23  import org.junit.AfterClass;
    24  import org.junit.Before;
    25  import org.junit.BeforeClass;
    26  import org.junit.Test;
    27  import static org.junit.Assert.*;
    28
    29  /**
    30   *
    31   * @author Jeremy Long (jeremy.long@owasp.org)
    32   */
    33  public class LuceneUtilsTest {
    34
    35      @BeforeClass
    36      public static void setUpClass() throws Exception {
    37      }
    38
    39      @AfterClass
    40      public static void tearDownClass() throws Exception {
    41      }
    42
    43      @Before
    44      public void setUp() {
    45      }
    46
    47      @After
    48      public void tearDown() {
    49      }
    50
    51      /**
    52       * Test of appendEscapedLuceneQuery method, of class LuceneUtils.
    53       */
    54      @Test
    55      public void testAppendEscapedLuceneQuery() {
    56          StringBuilder buf = new StringBuilder();
    57          CharSequence text = "test encoding + - & | ! ( ) { } [ ] ^ \" ~ * ? : \\";
    58          String expResult = "test encoding \\+ \\- \\& \\| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\\" \\~ \\* \\? \\: \\\\";
    59          LuceneUtils.appendEscapedLuceneQuery(buf, text);
    60          assertEquals(expResult, buf.toString());
    61      }
    62
    63      /**
    64       * Test of appendEscapedLuceneQuery method, of class LuceneUtils.
    65       */
    66      @Test
    67      public void testAppendEscapedLuceneQuery_null() {
    68          StringBuilder buf = new StringBuilder();
    69          CharSequence text = null;
    70          LuceneUtils.appendEscapedLuceneQuery(buf, text);
    71          assertEquals(0, buf.length());
    72      }
    73
    74      /**
    75       * Test of escapeLuceneQuery method, of class LuceneUtils.
    76       */
    77      @Test
    78      public void testEscapeLuceneQuery() {
    79          CharSequence text = "test encoding + - & | ! ( ) { } [ ] ^ \" ~ * ? : \\";
    80          String expResult = "test encoding \\+ \\- \\& \\| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\\" \\~ \\* \\? \\: \\\\";
    81          String result = LuceneUtils.escapeLuceneQuery(text);
    82          assertEquals(expResult, result);
    83      }
    84
    85      /**
    86       * Test of escapeLuceneQuery method, of class LuceneUtils.
    87       */
    88      @Test
    89      public void testEscapeLuceneQuery_null() {
    90          CharSequence text = null;
    91          String expResult = null;
    92          String result = LuceneUtils.escapeLuceneQuery(text);
    93          assertEquals(expResult, result);
    94      }
    95  }