1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. 22 * Copyright (c) 2018, Chris Fraire <cfraire@me.com>. 23 */ 24 package org.opengrok.indexer.analysis; 25 26 import org.junit.jupiter.api.Test; 27 28 import static org.junit.jupiter.api.Assertions.assertEquals; 29 import static org.junit.jupiter.api.Assertions.assertFalse; 30 import static org.junit.jupiter.api.Assertions.assertNotEquals; 31 import static org.junit.jupiter.api.Assertions.assertTrue; 32 33 /** 34 * Represents a container for tests of {@link PendingToken}. 35 */ 36 class PendingTokenTest { 37 38 @Test testEquals1()39 void testEquals1() { 40 PendingToken instance = new PendingToken("", 0, 0); 41 boolean result = instance.equals(instance); 42 assertTrue(result, "PendingToken instance equals itself"); 43 } 44 45 @Test testEquals2()46 void testEquals2() { 47 PendingToken instance1 = new PendingToken("a", 0, 1); 48 PendingToken instance2 = new PendingToken("a", 0, 1); 49 boolean result = instance1.equals(instance2); 50 assertTrue(result, "PendingToken instance equivalence false"); 51 } 52 53 @Test testNotEquals1()54 void testNotEquals1() { 55 PendingToken instance1 = new PendingToken("", 0, 0); 56 PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok 57 boolean result = instance1.equals(instance2); 58 assertFalse(result, "PendingToken equals() only 2 immutables match"); 59 } 60 61 @Test testNotEquals2()62 void testNotEquals2() { 63 PendingToken instance1 = new PendingToken("", 0, 0); 64 PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok 65 boolean result = instance1.equals(instance2); 66 assertFalse(result, "PendingToken equals() only 2 immutables match"); 67 } 68 69 @Test testNotEquals3()70 void testNotEquals3() { 71 PendingToken instance1 = new PendingToken("", 0, 0); 72 PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok 73 boolean result = instance1.equals(instance2); 74 assertFalse(result, "PendingToken equals() only 2 immutables match"); 75 } 76 77 @Test testSameHashCodes()78 void testSameHashCodes() { 79 PendingToken instance1 = new PendingToken("a", 0, 1); 80 PendingToken instance2 = new PendingToken("a", 0, 1); 81 assertEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken instance HashCode differs"); 82 } 83 84 @Test testDifferentHashCodes1()85 void testDifferentHashCodes1() { 86 PendingToken instance1 = new PendingToken("", 0, 0); 87 PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok 88 assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match"); 89 } 90 91 @Test testDifferentHashCodes2()92 void testDifferentHashCodes2() { 93 PendingToken instance1 = new PendingToken("", 0, 0); 94 PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok 95 assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match"); 96 } 97 98 @Test testDifferentHashCodes3()99 void testDifferentHashCodes3() { 100 PendingToken instance1 = new PendingToken("", 0, 0); 101 PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok 102 assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match"); 103 } 104 105 @Test testToString()106 void testToString() { 107 PendingToken instance = new PendingToken("abc", 0, 4); 108 String expResult = "PendingToken{abc<<< start=0,end=4}"; 109 String result = instance.toString(); 110 assertEquals(expResult, result, "PendingToken toString()"); 111 } 112 } 113