View Javadoc
1   /*
2    * This file is part of dependency-check-core.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.analyzer;
19  
20  import static org.junit.Assert.assertEquals;
21  import org.junit.Test;
22  import org.owasp.dependencycheck.BaseTest;
23  import org.owasp.dependencycheck.dependency.Dependency;
24  
25  /**
26   *
27   * @author Jeremy Long
28   */
29  public class DependencyBundlingAnalyzerTest extends BaseTest {
30  
31      /**
32       * Test of getName method, of class DependencyBundlingAnalyzer.
33       */
34      @Test
35      public void testGetName() {
36          DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
37          String expResult = "Dependency Bundling Analyzer";
38          String result = instance.getName();
39          assertEquals(expResult, result);
40      }
41  
42      /**
43       * Test of getAnalysisPhase method, of class DependencyBundlingAnalyzer.
44       */
45      @Test
46      public void testGetAnalysisPhase() {
47          DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
48          AnalysisPhase expResult = AnalysisPhase.PRE_FINDING_ANALYSIS;
49          AnalysisPhase result = instance.getAnalysisPhase();
50          assertEquals(expResult, result);
51      }
52  
53      /**
54       * Test of analyze method, of class DependencyBundlingAnalyzer.
55       */
56      @Test
57      public void testAnalyze() throws Exception {
58  //        Dependency ignore = null;
59  //        Engine engine = null;
60  //        DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
61  //        instance.analyze(ignore, engine);
62  //        // TODO review the generated test code and remove the default call to fail.
63  //        fail("The test case is a prototype.");
64      }
65  
66      /**
67       * Test of isCore method, of class DependencyBundlingAnalyzer.
68       */
69      @Test
70      public void testIsCore() {
71          Dependency left = new Dependency();
72          Dependency right = new Dependency();
73  
74          left.setFileName("axis2-kernel-1.4.1.jar");
75          right.setFileName("axis2-adb-1.4.1.jar");
76          DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
77          boolean expResult = true;
78          boolean result = instance.isCore(left, right);
79          assertEquals(expResult, result);
80  
81          left.setFileName("struts-1.2.7.jar");
82          right.setFileName("file.tar.gz\\file.tar\\struts.jar");
83  
84          expResult = true;
85          result = instance.isCore(left, right);
86          assertEquals(expResult, result);
87      }
88  
89      @Test
90      public void testFirstPathIsShortest() {
91          DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
92  
93          String left = "./a/c.jar";
94          String right = "./d/e/f.jar";
95          boolean expResult = true;
96          boolean result = instance.firstPathIsShortest(left, right);
97          assertEquals(expResult, result);
98  
99          left = "./a/b/c.jar";
100         right = "./d/e/f.jar";
101         expResult = true;
102         result = instance.firstPathIsShortest(left, right);
103         assertEquals(expResult, result);
104 
105         left = "./d/b/c.jar";
106         right = "./a/e/f.jar";
107         expResult = false;
108         result = instance.firstPathIsShortest(left, right);
109         assertEquals(expResult, result);
110 
111         left = "./a/b/c.jar";
112         right = "./d/f.jar";
113         expResult = false;
114         result = instance.firstPathIsShortest(left, right);
115         assertEquals(expResult, result);
116 
117         left = "./a/b/c.jar";
118         right = "./a/b/c.jar";
119         expResult = true;
120         result = instance.firstPathIsShortest(left, right);
121         assertEquals(expResult, result);
122 
123     }
124 
125 }