1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.analyzer;
19
20 import mockit.Mocked;
21 import mockit.Verifications;
22 import org.junit.Test;
23 import org.owasp.dependencycheck.BaseTest;
24 import org.owasp.dependencycheck.Engine;
25 import org.owasp.dependencycheck.dependency.Dependency;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30
31
32
33
34 public class DependencyBundlingAnalyzerTest extends BaseTest {
35
36 @Mocked
37 Engine engineMock;
38
39
40
41
42 @Test
43 public void testGetName() {
44 DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
45 String expResult = "Dependency Bundling Analyzer";
46 String result = instance.getName();
47 assertEquals(expResult, result);
48 }
49
50
51
52
53 @Test
54 public void testGetAnalysisPhase() {
55 DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
56 AnalysisPhase expResult = AnalysisPhase.FINAL;
57 AnalysisPhase result = instance.getAnalysisPhase();
58 assertEquals(expResult, result);
59 }
60
61
62
63
64
65 @Test
66 public void testAnalyze() throws Exception {
67 DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
68
69
70 assertFalse(instance.getAnalyzed());
71 instance.analyze(null, engineMock);
72
73
74 assertTrue(instance.getAnalyzed());
75 instance.analyze(null, engineMock);
76 instance.analyze(null, engineMock);
77 instance.analyze(null, engineMock);
78 assertTrue(instance.getAnalyzed());
79
80 new Verifications() {{
81 engineMock.getDependencies();
82 times = 2;
83 }};
84 }
85
86
87
88
89 @Test
90 public void testIsCore() {
91 Dependency left = new Dependency();
92 Dependency right = new Dependency();
93
94 left.setFileName("axis2-kernel-1.4.1.jar");
95 right.setFileName("axis2-adb-1.4.1.jar");
96 DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
97 boolean expResult = true;
98 boolean result = instance.isCore(left, right);
99 assertEquals(expResult, result);
100
101 left.setFileName("struts-1.2.7.jar");
102 right.setFileName("file.tar.gz\\file.tar\\struts.jar");
103
104 expResult = true;
105 result = instance.isCore(left, right);
106 assertEquals(expResult, result);
107 }
108
109 @Test
110 public void testFirstPathIsShortest() {
111 DependencyBundlingAnalyzer instance = new DependencyBundlingAnalyzer();
112
113 String left = "./a/c.jar";
114 String right = "./d/e/f.jar";
115 boolean expResult = true;
116 boolean result = instance.firstPathIsShortest(left, right);
117 assertEquals(expResult, result);
118
119 left = "./a/b/c.jar";
120 right = "./d/e/f.jar";
121 expResult = true;
122 result = instance.firstPathIsShortest(left, right);
123 assertEquals(expResult, result);
124
125 left = "./d/b/c.jar";
126 right = "./a/e/f.jar";
127 expResult = false;
128 result = instance.firstPathIsShortest(left, right);
129 assertEquals(expResult, result);
130
131 left = "./a/b/c.jar";
132 right = "./d/f.jar";
133 expResult = false;
134 result = instance.firstPathIsShortest(left, right);
135 assertEquals(expResult, result);
136
137 left = "./a/b/c.jar";
138 right = "./a/b/c.jar";
139 expResult = true;
140 result = instance.firstPathIsShortest(left, right);
141 assertEquals(expResult, result);
142 }
143 }