xref: /OpenGrok/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/PendingTokenTest.java (revision c389802dce0d8fde10e602cd558c2c2fc332bc29)
11a2bb6b6SAdam Hornáček /*
21a2bb6b6SAdam Hornáček  * CDDL HEADER START
31a2bb6b6SAdam Hornáček  *
41a2bb6b6SAdam Hornáček  * The contents of this file are subject to the terms of the
51a2bb6b6SAdam Hornáček  * Common Development and Distribution License (the "License").
61a2bb6b6SAdam Hornáček  * You may not use this file except in compliance with the License.
71a2bb6b6SAdam Hornáček  *
81a2bb6b6SAdam Hornáček  * See LICENSE.txt included in this distribution for the specific
91a2bb6b6SAdam Hornáček  * language governing permissions and limitations under the License.
101a2bb6b6SAdam Hornáček  *
111a2bb6b6SAdam Hornáček  * When distributing Covered Code, include this CDDL HEADER in each
121a2bb6b6SAdam Hornáček  * file and include the License file at LICENSE.txt.
131a2bb6b6SAdam Hornáček  * If applicable, add the following below this CDDL HEADER, with the
141a2bb6b6SAdam Hornáček  * fields enclosed by brackets "[]" replaced with your own identifying
151a2bb6b6SAdam Hornáček  * information: Portions Copyright [yyyy] [name of copyright owner]
161a2bb6b6SAdam Hornáček  *
171a2bb6b6SAdam Hornáček  * CDDL HEADER END
181a2bb6b6SAdam Hornáček  */
191a2bb6b6SAdam Hornáček 
201a2bb6b6SAdam Hornáček /*
21*c389802dSVladimir Kotal  * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
221a2bb6b6SAdam Hornáček  * Copyright (c) 2018, Chris Fraire <cfraire@me.com>.
231a2bb6b6SAdam Hornáček  */
241a2bb6b6SAdam Hornáček package org.opengrok.indexer.analysis;
251a2bb6b6SAdam Hornáček 
2652d10766SAdam Hornacek import org.junit.jupiter.api.Test;
2752d10766SAdam Hornacek 
2852d10766SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertEquals;
2952d10766SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertFalse;
3052d10766SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertNotEquals;
3152d10766SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertTrue;
321a2bb6b6SAdam Hornáček 
331a2bb6b6SAdam Hornáček /**
341a2bb6b6SAdam Hornáček  * Represents a container for tests of {@link PendingToken}.
351a2bb6b6SAdam Hornáček  */
36*c389802dSVladimir Kotal class PendingTokenTest {
371a2bb6b6SAdam Hornáček 
381a2bb6b6SAdam Hornáček     @Test
testEquals1()39*c389802dSVladimir Kotal     void testEquals1() {
401a2bb6b6SAdam Hornáček         PendingToken instance = new PendingToken("", 0, 0);
411a2bb6b6SAdam Hornáček         boolean result = instance.equals(instance);
4252d10766SAdam Hornacek         assertTrue(result, "PendingToken instance equals itself");
431a2bb6b6SAdam Hornáček     }
441a2bb6b6SAdam Hornáček 
451a2bb6b6SAdam Hornáček     @Test
testEquals2()46*c389802dSVladimir Kotal     void testEquals2() {
471a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("a", 0, 1);
481a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("a", 0, 1);
491a2bb6b6SAdam Hornáček         boolean result = instance1.equals(instance2);
50*c389802dSVladimir Kotal         assertTrue(result, "PendingToken instance equivalence false");
511a2bb6b6SAdam Hornáček     }
521a2bb6b6SAdam Hornáček 
531a2bb6b6SAdam Hornáček     @Test
testNotEquals1()54*c389802dSVladimir Kotal     void testNotEquals1() {
551a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("", 0, 0);
561a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok
571a2bb6b6SAdam Hornáček         boolean result = instance1.equals(instance2);
5852d10766SAdam Hornacek         assertFalse(result, "PendingToken equals() only 2 immutables match");
591a2bb6b6SAdam Hornáček     }
601a2bb6b6SAdam Hornáček 
611a2bb6b6SAdam Hornáček     @Test
testNotEquals2()62*c389802dSVladimir Kotal     void testNotEquals2() {
631a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("", 0, 0);
641a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok
651a2bb6b6SAdam Hornáček         boolean result = instance1.equals(instance2);
6652d10766SAdam Hornacek         assertFalse(result, "PendingToken equals() only 2 immutables match");
671a2bb6b6SAdam Hornáček     }
681a2bb6b6SAdam Hornáček 
691a2bb6b6SAdam Hornáček     @Test
testNotEquals3()70*c389802dSVladimir Kotal     void testNotEquals3() {
711a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("", 0, 0);
721a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok
731a2bb6b6SAdam Hornáček         boolean result = instance1.equals(instance2);
7452d10766SAdam Hornacek         assertFalse(result, "PendingToken equals() only 2 immutables match");
751a2bb6b6SAdam Hornáček     }
761a2bb6b6SAdam Hornáček 
771a2bb6b6SAdam Hornáček     @Test
testSameHashCodes()78*c389802dSVladimir Kotal     void testSameHashCodes() {
791a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("a", 0, 1);
801a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("a", 0, 1);
81*c389802dSVladimir Kotal         assertEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken instance HashCode differs");
821a2bb6b6SAdam Hornáček     }
831a2bb6b6SAdam Hornáček 
841a2bb6b6SAdam Hornáček     @Test
testDifferentHashCodes1()85*c389802dSVladimir Kotal     void testDifferentHashCodes1() {
861a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("", 0, 0);
871a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok
8852d10766SAdam Hornacek         assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match");
891a2bb6b6SAdam Hornáček     }
901a2bb6b6SAdam Hornáček 
911a2bb6b6SAdam Hornáček     @Test
testDifferentHashCodes2()92*c389802dSVladimir Kotal     void testDifferentHashCodes2() {
931a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("", 0, 0);
941a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok
9552d10766SAdam Hornacek         assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match");
961a2bb6b6SAdam Hornáček     }
971a2bb6b6SAdam Hornáček 
981a2bb6b6SAdam Hornáček     @Test
testDifferentHashCodes3()99*c389802dSVladimir Kotal     void testDifferentHashCodes3() {
1001a2bb6b6SAdam Hornáček         PendingToken instance1 = new PendingToken("", 0, 0);
1011a2bb6b6SAdam Hornáček         PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok
10252d10766SAdam Hornacek         assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match");
1031a2bb6b6SAdam Hornáček     }
1041a2bb6b6SAdam Hornáček 
1051a2bb6b6SAdam Hornáček     @Test
testToString()106*c389802dSVladimir Kotal     void testToString() {
1071a2bb6b6SAdam Hornáček         PendingToken instance = new PendingToken("abc", 0, 4);
108*c389802dSVladimir Kotal         String expResult = "PendingToken{abc<<< start=0,end=4}";
1091a2bb6b6SAdam Hornáček         String result = instance.toString();
11052d10766SAdam Hornacek         assertEquals(expResult, result, "PendingToken toString()");
1111a2bb6b6SAdam Hornáček     }
1121a2bb6b6SAdam Hornáček }
113