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.utils;
    20
    21  import org.owasp.dependencycheck.utils.Filter;
    22  import java.util.List;
    23  import java.util.ArrayList;
    24  import org.junit.After;
    25  import org.junit.AfterClass;
    26  import org.junit.Before;
    27  import org.junit.BeforeClass;
    28  import org.junit.Test;
    29  import static org.junit.Assert.*;
    30
    31  /**
    32   *
    33   * @author Jeremy Long (jeremy.long@owasp.org)
    34   */
    35  public class FilterTest {
    36
    37      public FilterTest() {
    38      }
    39
    40      @BeforeClass
    41      public static void setUpClass() throws Exception {
    42      }
    43
    44      @AfterClass
    45      public static void tearDownClass() throws Exception {
    46      }
    47
    48      @Before
    49      public void setUp() {
    50      }
    51
    52      @After
    53      public void tearDown() {
    54      }
    55
    56      /**
    57       * Test of passes method, of class Filter.
    58       */
    59      @Test
    60      public void testPasses() {
    61          String keep = "keep";
    62          String fail = "fail";
    63
    64          assertTrue("String contained keep - but passes returned false.", TEST_FILTER.passes(keep));
    65          assertFalse("String contained fail - but passes returned true.", TEST_FILTER.passes(fail));
    66      }
    67
    68      /**
    69       * Test of filter method, of class Filter.
    70       */
    71      @Test
    72      public void testFilter_Iterable() {
    73          List<String> testData = new ArrayList<String>();
    74          testData.add("keep");
    75          testData.add("remove");
    76          testData.add("keep");
    77
    78          List<String> expResults = new ArrayList<String>();
    79          expResults.add("keep");
    80          expResults.add("keep");
    81
    82          List<String> actResults = new ArrayList<String>();
    83          for (String s : TEST_FILTER.filter(testData)) {
    84              actResults.add(s);
    85          }
    86          assertArrayEquals(expResults.toArray(), actResults.toArray());
    87      }
    88      private static final Filter<String> TEST_FILTER =
    89              new Filter<String>() {
    90          public boolean passes(String str) {
    91              return str.contains("keep");
    92          }
    93      };
    94  }