Skip to content

Commit 56fe152

Browse files
committed
[hibernate#1819] Add tests for mapping of array of primitives fields
Vert.x SQL client 4.5.1 fixes the issue with primitives type. This commit add the missing tests and tweak a bit the existing ones.
1 parent 4b9bc6c commit 56fe152

File tree

1 file changed

+69
-8
lines changed

1 file changed

+69
-8
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JavaTypesArrayTest.java

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.hibernate.reactive.BaseReactiveTest;
2121

22-
2322
import org.junit.jupiter.api.Test;
2423
import org.junit.jupiter.api.condition.DisabledIf;
2524

@@ -41,7 +40,7 @@
4140
import static org.junit.jupiter.api.Assertions.assertNotNull;
4241

4342
@Timeout(value = 10, timeUnit = MINUTES)
44-
@DisabledIf( "isNotSupported" )
43+
@DisabledIf("isNotSupported")
4544
public class JavaTypesArrayTest extends BaseReactiveTest {
4645

4746
@Override
@@ -80,48 +79,93 @@ public void testStringArrayType(VertxTestContext context) {
8079
@Test
8180
public void testBooleanArrayType(VertxTestContext context) {
8281
Basic basic = new Basic();
83-
Boolean[] dataArray = {TRUE, FALSE, TRUE};
82+
Boolean[] dataArray = {TRUE, FALSE, null, TRUE};
8483
basic.booleanArray = dataArray;
8584

8685
testField( context, basic, found -> assertArrayEquals( dataArray, found.booleanArray ) );
8786
}
8887

88+
@Test
89+
public void testPrimitiveBooleanArrayType(VertxTestContext context) {
90+
Basic basic = new Basic();
91+
boolean[] dataArray = {true, false, true};
92+
basic.primitiveBooleanArray = dataArray;
93+
94+
testField( context, basic, found -> assertArrayEquals( dataArray, found.primitiveBooleanArray ) );
95+
}
96+
8997
@Test
9098
public void testIntegerArrayType(VertxTestContext context) {
9199
Basic basic = new Basic();
92-
Integer[] dataArray = {1, 2, 3};
100+
Integer[] dataArray = {null, Integer.MIN_VALUE, 2, Integer.MAX_VALUE};
93101
basic.integerArray = dataArray;
94102

95103
testField( context, basic, found -> assertArrayEquals( dataArray, found.integerArray ) );
96104
}
97105

106+
@Test
107+
public void testPrimitiveIntegerArrayType(VertxTestContext context) {
108+
Basic basic = new Basic();
109+
int[] dataArray = {1, 2, 3};
110+
basic.primitiveIntegerArray = dataArray;
111+
112+
testField( context, basic, found -> assertArrayEquals( dataArray, found.primitiveIntegerArray ) );
113+
}
114+
98115
@Test
99116
public void testLongArrayType(VertxTestContext context) {
100117
Basic basic = new Basic();
101-
Long[] dataArray = {Long.MIN_VALUE, Long.MAX_VALUE, 3L};
118+
Long[] dataArray = {Long.MIN_VALUE, Long.MAX_VALUE, 3L, null};
102119
basic.longArray = dataArray;
103120

104121
testField( context, basic, found -> assertArrayEquals( dataArray, found.longArray ) );
105122
}
106123

124+
@Test
125+
public void testPrimitiveLongArrayType(VertxTestContext context) {
126+
Basic basic = new Basic();
127+
long[] dataArray = {Long.MIN_VALUE, Long.MAX_VALUE, 3L};
128+
basic.primitiveLongArray = dataArray;
129+
130+
testField( context, basic, found -> assertArrayEquals( dataArray, found.primitiveLongArray ) );
131+
}
132+
107133
@Test
108134
public void testFloatArrayType(VertxTestContext context) {
109135
Basic basic = new Basic();
110-
Float[] dataArray = {12.562f, 13.562f};
136+
Float[] dataArray = {12.562f, null, 13.562f};
111137
basic.floatArray = dataArray;
112138

113139
testField( context, basic, found -> assertArrayEquals( dataArray, found.floatArray ) );
114140
}
115141

142+
@Test
143+
public void testPrimitiveFloatArrayType(VertxTestContext context) {
144+
Basic basic = new Basic();
145+
float[] dataArray = {12.562f, 13.562f};
146+
basic.primitiveFloatArray = dataArray;
147+
148+
testField( context, basic, found -> assertArrayEquals( dataArray, found.primitiveFloatArray ) );
149+
}
150+
116151
@Test
117152
public void testDoubleArrayType(VertxTestContext context) {
118153
Basic basic = new Basic();
119-
Double[] dataArray = {12.562d, 13.562d};
154+
Double[] dataArray = {12.562d, null, 13.562d};
120155
basic.doubleArray = dataArray;
121156

122157
testField( context, basic, found -> assertArrayEquals( dataArray, found.doubleArray ) );
123158
}
124159

160+
@Test
161+
public void testPrimitiveDoubleArrayType(VertxTestContext context) {
162+
Basic basic = new Basic();
163+
double[] dataArray = {12.562d, 13.562d};
164+
basic.primitiveDoubleArray = dataArray;
165+
166+
testField( context, basic, found -> assertArrayEquals( dataArray, found.primitiveDoubleArray ) );
167+
}
168+
125169
@Test
126170
public void testUUIDArrayType(VertxTestContext context) {
127171
Basic basic = new Basic();
@@ -153,6 +197,15 @@ public void testShortArrayType(VertxTestContext context) {
153197
testField( context, basic, found -> assertArrayEquals( dataArray, found.shortArray ) );
154198
}
155199

200+
@Test
201+
public void testPrimitiveShortArrayType(VertxTestContext context) {
202+
Basic basic = new Basic();
203+
short[] dataArray = {500, 32, -1};
204+
basic.primitiveShortArray = dataArray;
205+
206+
testField( context, basic, found -> assertArrayEquals( dataArray, found.primitiveShortArray ) );
207+
}
208+
156209
@Test
157210
public void testLocalDateArrayType(VertxTestContext context) {
158211
Basic basic = new Basic();
@@ -238,18 +291,26 @@ private static class Basic {
238291
Integer id;
239292
String[] stringArray;
240293
Boolean[] booleanArray;
241-
294+
boolean[] primitiveBooleanArray;
242295
Integer[] integerArray;
296+
int[] primitiveIntegerArray;
243297
Long[] longArray;
298+
long[] primitiveLongArray;
244299
Float[] floatArray;
300+
float[] primitiveFloatArray;
245301
Double[] doubleArray;
302+
double[] primitiveDoubleArray;
246303
UUID[] uuidArray;
247304
AnEnum[] enumArray;
248305
Short[] shortArray;
306+
short[] primitiveShortArray;
249307
Date[] dateArray;
250308
LocalDate[] localDateArray;
251309
LocalTime[] localTimeArray;
252310
LocalDateTime[] localDateTimeArray;
311+
312+
// We have to specify the length for BigDecimal and BigInteger because
313+
// the default column type when creating the schema is too small on some databases
253314
@Column(length = 5000)
254315
BigInteger[] bigIntegerArray;
255316
@Column(length = 5000)

0 commit comments

Comments
 (0)