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.dependency;
19  
20  import org.junit.Test;
21  import static org.junit.Assert.*;
22  import static org.hamcrest.CoreMatchers.*;
23  
24  /**
25   *
26   * @author Jeremy Long
27   */
28  public class EvidenceTest {
29  
30      /**
31       * Test of equals method, of class Evidence.
32       */
33      @Test
34      public void testEquals() {
35          Evidence that0 = new Evidence("file", "name", "guice-3.0", Confidence.HIGHEST);
36          Evidence that1 = new Evidence("jar", "package name", "dependency", Confidence.HIGHEST);
37          Evidence that2 = new Evidence("jar", "package name", "google", Confidence.HIGHEST);
38          Evidence that3 = new Evidence("jar", "package name", "guice", Confidence.HIGHEST);
39          Evidence that4 = new Evidence("jar", "package name", "inject", Confidence.HIGHEST);
40          Evidence that5 = new Evidence("jar", "package name", "inject", Confidence.LOW);
41          Evidence that6 = new Evidence("jar", "package name", "internal", Confidence.LOW);
42          Evidence that7 = new Evidence("manifest", "Bundle-Description", "Guice is a lightweight dependency injection framework for Java 5 and above", Confidence.MEDIUM);
43          Evidence that8 = new Evidence("Manifest", "Implementation-Title", "Spring Framework", Confidence.HIGH);
44  
45          Evidence instance = new Evidence("Manifest", "Implementation-Title", "Spring Framework", Confidence.HIGH);
46          assertFalse(instance.equals(that0));
47          assertFalse(instance.equals(that1));
48          assertFalse(instance.equals(that2));
49          assertFalse(instance.equals(that3));
50          assertFalse(instance.equals(that4));
51          assertFalse(instance.equals(that5));
52          assertFalse(instance.equals(that6));
53          assertFalse(instance.equals(that7));
54          assertTrue(instance.equals(that8));
55      }
56  
57      @Test
58      public void testHashcodeContract() throws Exception {
59          final Evidence titleCase = new Evidence("Manifest", "Implementation-Title", "Spring Framework", Confidence.HIGH);
60          final Evidence lowerCase = new Evidence("manifest", "implementation-title", "spring framework", Confidence.HIGH);
61          assertThat(titleCase, is(equalTo(lowerCase)));
62          assertThat(titleCase.hashCode(), is(equalTo(lowerCase.hashCode())));
63      }
64  
65      /**
66       * Test of compareTo method, of class Evidence.
67       */
68      @Test
69      public void testCompareTo() {
70          Evidence that0 = new Evidence("file", "name", "guice-3.0", Confidence.HIGHEST);
71          Evidence that1 = new Evidence("jar", "package name", "dependency", Confidence.HIGHEST);
72          Evidence that2 = new Evidence("jar", "package name", "google", Confidence.HIGHEST);
73          Evidence that3 = new Evidence("jar", "package name", "guice", Confidence.HIGHEST);
74          Evidence that4 = new Evidence("jar", "package name", "inject", Confidence.HIGHEST);
75          Evidence that5 = new Evidence("jar", "package name", "inject", Confidence.LOW);
76          Evidence that6 = new Evidence("jar", "package name", "internal", Confidence.LOW);
77          Evidence that7 = new Evidence("manifest", "Bundle-Description", "Guice is a lightweight dependency injection framework for Java 5 and above", Confidence.MEDIUM);
78          Evidence that8 = new Evidence("Manifest", "Implementation-Title", "Spring Framework", Confidence.HIGH);
79  
80          Evidence that9 = new Evidence("manifest", "implementation-title", "zippy", Confidence.HIGH);
81  
82          Evidence instance = new Evidence("Manifest", "Implementation-Title", "Spring Framework", Confidence.HIGH);
83  
84          int result = instance.compareTo(that0);
85          assertTrue(result > 0);
86  
87          result = instance.compareTo(that1);
88          assertTrue(result > 0);
89  
90          result = instance.compareTo(that2);
91          assertTrue(result > 0);
92  
93          result = instance.compareTo(that3);
94          assertTrue(result > 0);
95  
96          result = instance.compareTo(that4);
97          assertTrue(result > 0);
98  
99          result = instance.compareTo(that5);
100         assertTrue(result > 0);
101 
102         result = instance.compareTo(that6);
103         assertTrue(result > 0);
104 
105         result = instance.compareTo(that7);
106         assertTrue(result > 0);
107 
108         result = instance.compareTo(that8);
109         assertTrue(result == 0);
110 
111         result = instance.compareTo(that9);
112         assertTrue(result < 0);
113     }
114 }