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