-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathIntIdentityTest.java
More file actions
148 lines (132 loc) · 5.82 KB
/
Copy pathIntIdentityTest.java
File metadata and controls
148 lines (132 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* IntIdentityTest.java
*
*/
package javax.jdo.identity;
import javax.jdo.JDONullIdentityException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/** */
class IntIdentityTest extends SingleFieldIdentityTest {
/** Creates a new instance of IntIdentityTest */
public IntIdentityTest() {
// This method body is intentionally left blank
}
@Override
@Test
void testConstructor() {
IntIdentity c1 = new IntIdentity(Object.class, 1);
IntIdentity c2 = new IntIdentity(Object.class, 1);
IntIdentity c3 = new IntIdentity(Object.class, 2);
Assertions.assertEquals(c1, c2, "Equal IntIdentity instances compare not equal.");
Assertions.assertNotEquals(c1, c3, "Not equal IntIdentity instances compare equal");
}
@Test
void testIntegerConstructor() {
IntIdentity c1 = new IntIdentity(Object.class, 1);
IntIdentity c2 = new IntIdentity(Object.class, Integer.valueOf(1));
IntIdentity c3 = new IntIdentity(Object.class, Integer.valueOf(2));
Assertions.assertEquals(c1, c2, "Equal intIdentity instances compare not equal.");
Assertions.assertNotEquals(c1, c3, "Not equal IntIdentity instances compare equal");
}
@Test
void testToStringConstructor() {
IntIdentity c1 = new IntIdentity(Object.class, 1);
IntIdentity c2 = new IntIdentity(Object.class, c1.toString());
Assertions.assertEquals(c1, c2, "Equal IntIdentity instances compare not equal.");
}
@Test
void testStringConstructor() {
IntIdentity c1 = new IntIdentity(Object.class, 1);
IntIdentity c2 = new IntIdentity(Object.class, "1");
IntIdentity c3 = new IntIdentity(Object.class, "2");
Assertions.assertEquals(c1, c2, "Equal IntIdentity instances compare not equal.");
Assertions.assertNotEquals(c1, c3, "Not equal IntIdentity instances compare equal");
}
@Test
void testIllegalStringConstructor() {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> new IntIdentity(Object.class, "b"),
"No exception caught for illegal String.");
}
@Override
@Test
void testSerialized() {
IntIdentity c1 = new IntIdentity(Object.class, 1);
IntIdentity c2 = new IntIdentity(Object.class, "1");
IntIdentity c3 = new IntIdentity(Object.class, "2");
Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
Object sc1 = scis[0];
Object sc2 = scis[1];
Object sc3 = scis[2];
Assertions.assertEquals(c1, sc1, "Equal IntIdentity instances compare not equal.");
Assertions.assertEquals(c2, sc2, "Equal IntIdentity instances compare not equal.");
Assertions.assertEquals(sc1, c2, "Equal IntIdentity instances compare not equal.");
Assertions.assertEquals(sc2, c1, "Equal IntIdentity instances compare not equal.");
Assertions.assertNotEquals(c1, sc3, "Not equal InrIdentity instances compare equal.");
Assertions.assertNotEquals(sc1, c3, "Not equal IntIdentity instances compare equal.");
Assertions.assertNotEquals(sc1, sc3, "Not equal IntIdentity instances compare equal.");
Assertions.assertNotEquals(sc3, sc1, "Not equal IntIdentity instances compare equal.");
}
@Test
void testGetKeyAsObjectPrimitive() {
IntIdentity c1 = new IntIdentity(Object.class, 1);
Assertions.assertEquals(c1.getKeyAsObject(), Integer.valueOf(1), "keyAsObject doesn't match.");
}
@Test
void testGetKeyAsObject() {
IntIdentity c1 = new IntIdentity(Object.class, Integer.valueOf(1));
Assertions.assertEquals(c1.getKeyAsObject(), Integer.valueOf(1), "keyAsObject doesn't match.");
}
@Test
void testBadConstructorNullIntegerParam() {
Assertions.assertThrows(
JDONullIdentityException.class,
() -> new IntIdentity(Object.class, (Integer) null),
"Failed to catch expected exception.");
}
@Test
void testBadConstructorNullStringParam() {
Assertions.assertThrows(
JDONullIdentityException.class,
() -> new IntIdentity(Object.class, (String) null),
"Failed to catch expected exception.");
}
@Test
void testCompareTo() {
IntIdentity c1 = new IntIdentity(Object.class, 1);
IntIdentity c2 = new IntIdentity(Object.class, 1);
IntIdentity c3 = new IntIdentity(Object.class, 2);
IntIdentity c4 = new IntIdentity(Class.class, 1);
IntIdentity c6 = new IntIdentity(Object.class, Integer.MIN_VALUE);
IntIdentity c7 = new IntIdentity(Object.class, Integer.MAX_VALUE);
Assertions.assertEquals(0, c1.compareTo(c2), "Equal IntIdentity instances compare not equal.");
Assertions.assertTrue(
c1.compareTo(c3) < 0, "Not equal IntIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c3.compareTo(c1) > 0, "Not equal IntIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c1.compareTo(c4) > 0, "Not equal IntIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c6.compareTo(c7) < 0, "Not equal LongIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c7.compareTo(c6) > 0, "Not equal LongIdentity instances have wrong compareTo result");
}
}