Skip to content

Commit 6ffc4a5

Browse files
resolve conflict with latest main branch; make use of @builder lombok feature
1 parent b323910 commit 6ffc4a5

File tree

3 files changed

+191
-424
lines changed

3 files changed

+191
-424
lines changed

src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java

Lines changed: 97 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
import java.util.Collection;
3838
import java.util.LinkedHashSet;
3939
import java.util.List;
40+
import lombok.AllArgsConstructor;
41+
import lombok.Builder;
42+
import lombok.NoArgsConstructor;
4043
import org.bson.BsonDocument;
4144
import org.bson.types.ObjectId;
4245
import org.hibernate.MappingException;
@@ -76,35 +79,37 @@ public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
7679

7780
@Test
7881
void testArrayAndCollectionValues() {
79-
var item = new ItemWithArrayAndCollectionValues(
80-
1,
82+
var item = ItemWithArrayAndCollectionValues.builder()
83+
.id(1)
8184
// TODO-HIBERNATE-48 sprinkle on `null` array/collection elements
82-
new byte[] {2, 3},
83-
new char[] {'s', 't', 'r'},
84-
new int[] {5},
85-
new long[] {Long.MAX_VALUE, 6},
86-
new double[] {Double.MAX_VALUE},
87-
new boolean[] {true},
88-
new Character[] {'s', 't', 'r'},
89-
new Integer[] {7},
90-
new Long[] {8L},
91-
new Double[] {9.1d},
92-
new Boolean[] {true},
93-
new String[] {"str"},
94-
new BigDecimal[] {BigDecimal.valueOf(10.1)},
95-
new ObjectId[] {new ObjectId("000000000000000000000001")},
96-
new StructAggregateEmbeddableIntegrationTests.Single[] {
85+
.bytes(new byte[] {2, 3})
86+
.chars(new char[] {'s', 't', 'r'})
87+
.ints(new int[] {5})
88+
.longs(new long[] {Long.MAX_VALUE, 6})
89+
.doubles(new double[] {Double.MAX_VALUE})
90+
.booleans(new boolean[] {true})
91+
.boxedChars(new Character[] {'s', 't', 'r'})
92+
.boxedInts(new Integer[] {7})
93+
.boxedLongs(new Long[] {8L})
94+
.boxedDoubles(new Double[] {9.1d})
95+
.boxedBooleans(new Boolean[] {true})
96+
.strings(new String[] {"str"})
97+
.bigDecimals(new BigDecimal[] {BigDecimal.valueOf(10.1)})
98+
.objectIds(new ObjectId[] {new ObjectId("000000000000000000000001")})
99+
.structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[] {
97100
new StructAggregateEmbeddableIntegrationTests.Single(1)
98-
},
99-
List.of('s', 't', 'r'),
100-
List.of(5),
101-
List.of(Long.MAX_VALUE, 6L),
102-
List.of(Double.MAX_VALUE),
103-
List.of(true),
104-
List.of("str"),
105-
List.of(BigDecimal.valueOf(10.1)),
106-
List.of(new ObjectId("000000000000000000000001")),
107-
List.of(new StructAggregateEmbeddableIntegrationTests.Single(1)));
101+
})
102+
.charsCollection(List.of('s', 't', 'r'))
103+
.intsCollection(List.of(5))
104+
.longsCollection(List.of(Long.MAX_VALUE, 6L))
105+
.doublesCollection(List.of(Double.MAX_VALUE))
106+
.booleansCollection(List.of(true))
107+
.stringsCollection(List.of("str"))
108+
.bigDecimalsCollection(List.of(BigDecimal.valueOf(10.1)))
109+
.objectIdsCollection(List.of(new ObjectId("000000000000000000000001")))
110+
.structAggregateEmbeddablesCollection(List.of(new StructAggregateEmbeddableIntegrationTests.Single(1)))
111+
.build();
112+
108113
sessionFactoryScope.inTransaction(session -> session.persist(item));
109114
assertCollectionContainsExactly(
110115
"""
@@ -185,32 +190,34 @@ void testArrayAndCollectionValues() {
185190

186191
@Test
187192
void testArrayAndCollectionEmptyValues() {
188-
var item = new ItemWithArrayAndCollectionValues(
189-
1,
190-
new byte[0],
191-
new char[0],
192-
new int[0],
193-
new long[0],
194-
new double[0],
195-
new boolean[0],
196-
new Character[0],
197-
new Integer[0],
198-
new Long[0],
199-
new Double[0],
200-
new Boolean[0],
201-
new String[0],
202-
new BigDecimal[0],
203-
new ObjectId[0],
204-
new StructAggregateEmbeddableIntegrationTests.Single[0],
205-
List.of(),
206-
List.of(),
207-
List.of(),
208-
List.of(),
209-
List.of(),
210-
List.of(),
211-
List.of(),
212-
List.of(),
213-
List.of());
193+
var item = ItemWithArrayAndCollectionValues.builder()
194+
.id(1)
195+
.bytes(new byte[0])
196+
.chars(new char[0])
197+
.ints(new int[0])
198+
.longs(new long[0])
199+
.doubles(new double[0])
200+
.booleans(new boolean[0])
201+
.boxedChars(new Character[0])
202+
.boxedInts(new Integer[0])
203+
.boxedLongs(new Long[0])
204+
.boxedDoubles(new Double[0])
205+
.boxedBooleans(new Boolean[0])
206+
.strings(new String[0])
207+
.bigDecimals(new BigDecimal[0])
208+
.objectIds(new ObjectId[0])
209+
.structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[0])
210+
.charsCollection(List.of())
211+
.intsCollection(List.of())
212+
.longsCollection(List.of())
213+
.doublesCollection(List.of())
214+
.booleansCollection(List.of())
215+
.stringsCollection(List.of())
216+
.bigDecimalsCollection(List.of())
217+
.objectIdsCollection(List.of())
218+
.structAggregateEmbeddablesCollection(List.of())
219+
.build();
220+
214221
sessionFactoryScope.inTransaction(session -> session.persist(item));
215222
assertCollectionContainsExactly(
216223
"""
@@ -291,34 +298,36 @@ void testArrayAndCollectionNullValues() {
291298

292299
@Test
293300
void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections() {
294-
var arraysAndCollections = new ArraysAndCollections(
295-
new byte[] {2, 3},
296-
new char[] {'s', 't', 'r'},
297-
new int[] {5},
298-
new long[] {Long.MAX_VALUE, 6},
299-
new double[] {Double.MAX_VALUE},
300-
new boolean[] {true},
301-
new Character[] {'s', 't', 'r'},
302-
new Integer[] {7},
303-
new Long[] {8L},
304-
new Double[] {9.1d},
305-
new Boolean[] {true},
306-
new String[] {"str"},
307-
new BigDecimal[] {BigDecimal.valueOf(10.1)},
308-
new ObjectId[] {new ObjectId("000000000000000000000001")},
309-
new StructAggregateEmbeddableIntegrationTests.Single[] {
301+
var arraysAndCollections = ArraysAndCollections.builder()
302+
.bytes(new byte[] {2, 3})
303+
.chars(new char[] {'s', 't', 'r'})
304+
.ints(new int[] {5})
305+
.longs(new long[] {Long.MAX_VALUE, 6})
306+
.doubles(new double[] {Double.MAX_VALUE})
307+
.booleans(new boolean[] {true})
308+
.boxedChars(new Character[] {'s', 't', 'r'})
309+
.boxedInts(new Integer[] {7})
310+
.boxedLongs(new Long[] {8L})
311+
.boxedDoubles(new Double[] {9.1d})
312+
.boxedBooleans(new Boolean[] {true})
313+
.strings(new String[] {"str"})
314+
.bigDecimals(new BigDecimal[] {BigDecimal.valueOf(10.1)})
315+
.objectIds(new ObjectId[] {new ObjectId("000000000000000000000001")})
316+
.structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[] {
310317
new StructAggregateEmbeddableIntegrationTests.Single(1)
311-
},
312-
List.of('s', 't', 'r'),
318+
})
319+
.charsCollection(List.of('s', 't', 'r'))
313320
// Hibernate ORM uses `LinkedHashSet`, forcing us to also use it, but messing up the order anyway
314-
new LinkedHashSet<>(List.of(5)),
315-
List.of(Long.MAX_VALUE, 6L),
316-
List.of(Double.MAX_VALUE),
317-
List.of(true),
318-
List.of("str"),
319-
List.of(BigDecimal.valueOf(10.1)),
320-
List.of(new ObjectId("000000000000000000000001")),
321-
List.of(new StructAggregateEmbeddableIntegrationTests.Single(1)));
321+
.intsCollection(new LinkedHashSet<>(List.of(5)))
322+
.longsCollection(List.of(Long.MAX_VALUE, 6L))
323+
.doublesCollection(List.of(Double.MAX_VALUE))
324+
.booleansCollection(List.of(true))
325+
.stringsCollection(List.of("str"))
326+
.bigDecimalsCollection(List.of(BigDecimal.valueOf(10.1)))
327+
.objectIdsCollection(List.of(new ObjectId("000000000000000000000001")))
328+
.structAggregateEmbeddablesCollection(List.of(new StructAggregateEmbeddableIntegrationTests.Single(1)))
329+
.build();
330+
322331
var item = new ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections(
323332
1, new ArraysAndCollections[] {arraysAndCollections}, List.of());
324333
sessionFactoryScope.inTransaction(session -> session.persist(item));
@@ -489,6 +498,9 @@ private static void assertCollectionContainsExactly(String documentAsJsonObject)
489498

490499
@Entity
491500
@Table(name = "items")
501+
@NoArgsConstructor
502+
@AllArgsConstructor
503+
@Builder
492504
static class ItemWithArrayAndCollectionValues {
493505
@Id
494506
int id;
@@ -517,82 +529,18 @@ static class ItemWithArrayAndCollectionValues {
517529
Collection<BigDecimal> bigDecimalsCollection;
518530
Collection<ObjectId> objectIdsCollection;
519531
Collection<StructAggregateEmbeddableIntegrationTests.Single> structAggregateEmbeddablesCollection;
520-
521-
ItemWithArrayAndCollectionValues() {}
522-
523-
ItemWithArrayAndCollectionValues(
524-
int id,
525-
byte[] bytes,
526-
char[] chars,
527-
int[] ints,
528-
long[] longs,
529-
double[] doubles,
530-
boolean[] booleans,
531-
Character[] boxedChars,
532-
Integer[] boxedInts,
533-
Long[] boxedLongs,
534-
Double[] boxedDoubles,
535-
Boolean[] boxedBooleans,
536-
String[] strings,
537-
BigDecimal[] bigDecimals,
538-
ObjectId[] objectIds,
539-
StructAggregateEmbeddableIntegrationTests.Single[] structAggregateEmbeddables,
540-
Collection<Character> charsCollection,
541-
Collection<Integer> intsCollection,
542-
Collection<Long> longsCollection,
543-
Collection<Double> doublesCollection,
544-
Collection<Boolean> booleansCollection,
545-
Collection<String> stringsCollection,
546-
Collection<BigDecimal> bigDecimalsCollection,
547-
Collection<ObjectId> objectIdsCollection,
548-
Collection<StructAggregateEmbeddableIntegrationTests.Single> structAggregateEmbeddablesCollection) {
549-
this.id = id;
550-
this.bytes = bytes;
551-
this.chars = chars;
552-
this.ints = ints;
553-
this.longs = longs;
554-
this.doubles = doubles;
555-
this.booleans = booleans;
556-
this.boxedChars = boxedChars;
557-
this.boxedInts = boxedInts;
558-
this.boxedLongs = boxedLongs;
559-
this.boxedDoubles = boxedDoubles;
560-
this.boxedBooleans = boxedBooleans;
561-
this.strings = strings;
562-
this.bigDecimals = bigDecimals;
563-
this.objectIds = objectIds;
564-
this.structAggregateEmbeddables = structAggregateEmbeddables;
565-
this.charsCollection = charsCollection;
566-
this.intsCollection = intsCollection;
567-
this.longsCollection = longsCollection;
568-
this.doublesCollection = doublesCollection;
569-
this.booleansCollection = booleansCollection;
570-
this.stringsCollection = stringsCollection;
571-
this.bigDecimalsCollection = bigDecimalsCollection;
572-
this.objectIdsCollection = objectIdsCollection;
573-
this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection;
574-
}
575532
}
576533

577534
@Entity
578535
@Table(name = "items")
536+
@NoArgsConstructor
537+
@AllArgsConstructor
579538
static class ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections {
580539
@Id
581540
int id;
582541

583542
ArraysAndCollections[] structAggregateEmbeddables;
584543
Collection<ArraysAndCollections> structAggregateEmbeddablesCollection;
585-
586-
ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections() {}
587-
588-
ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections(
589-
int id,
590-
ArraysAndCollections[] structAggregateEmbeddables,
591-
Collection<ArraysAndCollections> structAggregateEmbeddablesCollection) {
592-
this.id = id;
593-
this.structAggregateEmbeddables = structAggregateEmbeddables;
594-
this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection;
595-
}
596544
}
597545

598546
@Nested
@@ -670,36 +618,25 @@ void testCollectionOfEmbeddablesElementCollectionValue() {
670618

671619
@Entity
672620
@Table(name = "items")
621+
@NoArgsConstructor
622+
@AllArgsConstructor
673623
static class ItemWithBoxedBytesArrayValue {
674624
@Id
675625
int id;
676626

677627
byte[] bytes;
678628
Byte[] boxedBytes;
679-
680-
ItemWithBoxedBytesArrayValue() {}
681-
682-
ItemWithBoxedBytesArrayValue(int id, byte[] bytes, Byte[] boxedBytes) {
683-
this.id = id;
684-
this.bytes = bytes;
685-
this.boxedBytes = boxedBytes;
686-
}
687629
}
688630

689631
@Entity
690632
@Table(name = "items")
633+
@NoArgsConstructor
634+
@AllArgsConstructor
691635
static class ItemWithBytesCollectionValue {
692636
@Id
693637
int id;
694638

695639
Collection<Byte> bytes;
696-
697-
ItemWithBytesCollectionValue() {}
698-
699-
ItemWithBytesCollectionValue(int id, Collection<Byte> bytes) {
700-
this.id = id;
701-
this.bytes = bytes;
702-
}
703640
}
704641

705642
/**

0 commit comments

Comments
 (0)