Skip to content

Commit d1e78bf

Browse files
idodeclaretarzanek
authored andcommitted
Add PendingTokenTest
1 parent 2d5093e commit d1e78bf

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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) 2018, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opensolaris.opengrok.analysis;
25+
26+
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertNotEquals;
29+
import static org.junit.Assert.assertTrue;
30+
import org.junit.Test;
31+
32+
/**
33+
* Represents a container for tests of {@link PendingToken}.
34+
*/
35+
public class PendingTokenTest {
36+
37+
@Test
38+
public void testEquals1() {
39+
PendingToken instance = new PendingToken("", 0, 0);
40+
boolean result = instance.equals(instance);
41+
assertTrue("PendingToken instance equals itself", result);
42+
}
43+
44+
@Test
45+
public void testEquals2() {
46+
PendingToken instance1 = new PendingToken("a", 0, 1);
47+
assertEquals("PendingToken default nonpos", false, instance1.nonpos);
48+
49+
PendingToken instance2 = new PendingToken("a", 0, 1);
50+
instance2.nonpos = true;
51+
boolean result = instance1.equals(instance2);
52+
assertTrue("PendingToken instance equivalence ignores nonpos", result);
53+
}
54+
55+
@Test
56+
public void testNotEquals1() {
57+
PendingToken instance1 = new PendingToken("", 0, 0);
58+
PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok
59+
boolean result = instance1.equals(instance2);
60+
assertFalse("PendingToken equals() only 2 immutables match", result);
61+
}
62+
63+
@Test
64+
public void testNotEquals2() {
65+
PendingToken instance1 = new PendingToken("", 0, 0);
66+
PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok
67+
boolean result = instance1.equals(instance2);
68+
assertFalse("PendingToken equals() only 2 immutables match", result);
69+
}
70+
71+
@Test
72+
public void testNotEquals3() {
73+
PendingToken instance1 = new PendingToken("", 0, 0);
74+
PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok
75+
boolean result = instance1.equals(instance2);
76+
assertFalse("PendingToken equals() only 2 immutables match", result);
77+
}
78+
79+
@Test
80+
public void testSameHashCodes() {
81+
PendingToken instance1 = new PendingToken("a", 0, 1);
82+
assertEquals("PendingToken default nonpos", false, instance1.nonpos);
83+
84+
PendingToken instance2 = new PendingToken("a", 0, 1);
85+
instance2.nonpos = true;
86+
assertEquals("PendingToken instance HashCode ignores nonpos",
87+
instance1.hashCode(), instance2.hashCode());
88+
}
89+
90+
@Test
91+
public void testDifferentHashCodes1() {
92+
PendingToken instance1 = new PendingToken("", 0, 0);
93+
PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok
94+
assertNotEquals("PendingToken hashCode() only 2 immutables match",
95+
instance1.hashCode(), instance2.hashCode());
96+
}
97+
98+
@Test
99+
public void testDifferentHashCodes2() {
100+
PendingToken instance1 = new PendingToken("", 0, 0);
101+
PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok
102+
assertNotEquals("PendingToken hashCode() only 2 immutables match",
103+
instance1.hashCode(), instance2.hashCode());
104+
}
105+
106+
@Test
107+
public void testDifferentHashCodes3() {
108+
PendingToken instance1 = new PendingToken("", 0, 0);
109+
PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok
110+
assertNotEquals("PendingToken hashCode() only 2 immutables match",
111+
instance1.hashCode(), instance2.hashCode());
112+
}
113+
114+
@Test
115+
public void testToString() {
116+
PendingToken instance = new PendingToken("abc", 0, 4);
117+
String expResult = "PendingToken{abc<<< start=0,end=4,nonpos=false}";
118+
String result = instance.toString();
119+
assertEquals("PendingToken toString()", expResult, result);
120+
121+
instance.nonpos = true;
122+
expResult = "PendingToken{abc<<< start=0,end=4,nonpos=true}";
123+
result = instance.toString();
124+
assertEquals("PendingToken toString()", expResult, result);
125+
}
126+
}

0 commit comments

Comments
 (0)