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.analyzer;
    20
    21  import org.owasp.dependencycheck.analyzer.AnalysisPhase;
    22  import org.owasp.dependencycheck.analyzer.FileNameAnalyzer;
    23  import java.io.File;
    24  import java.util.Set;
    25  import org.owasp.dependencycheck.dependency.Dependency;
    26  import org.junit.After;
    27  import org.junit.AfterClass;
    28  import org.junit.Before;
    29  import org.junit.BeforeClass;
    30  import org.junit.Test;
    31  import static org.junit.Assert.*;
    32
    33  /**
    34   *
    35   * @author Jeremy Long (jeremy.long@owasp.org)
    36   */
    37  public class FileNameAnalyzerTest {
    38
    39      public FileNameAnalyzerTest() {
    40      }
    41
    42      @BeforeClass
    43      public static void setUpClass() throws Exception {
    44      }
    45
    46      @AfterClass
    47      public static void tearDownClass() throws Exception {
    48      }
    49
    50      @Before
    51      public void setUp() {
    52      }
    53
    54      @After
    55      public void tearDown() {
    56      }
    57
    58      /**
    59       * Test of getSupportedExtensions method, of class FileNameAnalyzer.
    60       */
    61      @Test
    62      public void testGetSupportedExtensions() {
    63          FileNameAnalyzer instance = new FileNameAnalyzer();
    64          Set expResult = null;
    65          Set result = instance.getSupportedExtensions();
    66          assertEquals(expResult, result);
    67      }
    68
    69      /**
    70       * Test of getName method, of class FileNameAnalyzer.
    71       */
    72      @Test
    73      public void testGetName() {
    74          FileNameAnalyzer instance = new FileNameAnalyzer();
    75          String expResult = "File Name Analyzer";
    76          String result = instance.getName();
    77          assertEquals(expResult, result);
    78      }
    79
    80      /**
    81       * Test of supportsExtension method, of class FileNameAnalyzer.
    82       */
    83      @Test
    84      public void testSupportsExtension() {
    85          String extension = "any";
    86          FileNameAnalyzer instance = new FileNameAnalyzer();
    87          boolean expResult = true;
    88          boolean result = instance.supportsExtension(extension);
    89          assertEquals(expResult, result);
    90      }
    91
    92      /**
    93       * Test of getAnalysisPhase method, of class FileNameAnalyzer.
    94       */
    95      @Test
    96      public void testGetAnalysisPhase() {
    97          FileNameAnalyzer instance = new FileNameAnalyzer();
    98          AnalysisPhase expResult = AnalysisPhase.INFORMATION_COLLECTION;
    99          AnalysisPhase result = instance.getAnalysisPhase();
    100         assertEquals(expResult, result);
    101     }
    102
    103     /**
    104      * Test of analyze method, of class FileNameAnalyzer.
    105      */
    106     @Test
    107     public void testAnalyze() throws Exception {
    108         File struts = new File(this.getClass().getClassLoader().getResource("struts2-core-2.1.2.jar").getPath());
    109         Dependency resultStruts = new Dependency(struts);
    110         File axis = new File(this.getClass().getClassLoader().getResource("axis2-adb-1.4.1.jar").getPath());
    111         Dependency resultAxis = new Dependency(axis);
    112         FileNameAnalyzer instance = new FileNameAnalyzer();
    113         instance.analyze(resultStruts, null);
    114         assertTrue(resultStruts.getVendorEvidence().toString().toLowerCase().contains("struts"));
    115
    116         instance.analyze(resultAxis, null);
    117         assertTrue(resultStruts.getVersionEvidence().toString().toLowerCase().contains("2.1.2"));
    118
    119     }
    120
    121     /**
    122      * Test of initialize method, of class FileNameAnalyzer.
    123      */
    124     @Test
    125     public void testInitialize() throws Exception {
    126         FileNameAnalyzer instance = new FileNameAnalyzer();
    127         instance.initialize();
    128         assertTrue(true); //initialize does nothing.
    129     }
    130
    131     /**
    132      * Test of close method, of class FileNameAnalyzer.
    133      */
    134     @Test
    135     public void testClose() throws Exception {
    136         FileNameAnalyzer instance = new FileNameAnalyzer();
    137         instance.close();
    138         assertTrue(true); //close does nothing.
    139     }
    140 }