18
18
19
19
import static com .mongodb .hibernate .internal .MongoConstants .ID_FIELD_NAME ;
20
20
import static org .assertj .core .api .Assertions .assertThat ;
21
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
21
22
22
23
import com .mongodb .client .MongoCollection ;
23
24
import com .mongodb .hibernate .junit .InjectMongoCollection ;
24
25
import com .mongodb .hibernate .junit .MongoExtension ;
25
26
import jakarta .persistence .Entity ;
26
27
import jakarta .persistence .Id ;
27
28
import jakarta .persistence .Table ;
29
+ import java .util .Objects ;
28
30
import org .bson .BsonDocument ;
29
31
import org .bson .BsonInt32 ;
32
+ import org .bson .BsonNull ;
30
33
import org .bson .BsonObjectId ;
31
34
import org .bson .types .ObjectId ;
32
35
import org .hibernate .testing .orm .junit .DomainModel ;
@@ -54,7 +57,8 @@ void insert() {
54
57
assertThat (mongoCollection .find ())
55
58
.containsExactly (new BsonDocument ()
56
59
.append (ID_FIELD_NAME , new BsonInt32 (1 ))
57
- .append ("v" , new BsonObjectId (item .v )));
60
+ .append ("v" , new BsonObjectId (item .v ))
61
+ .append ("vNull" , BsonNull .VALUE ));
58
62
}
59
63
60
64
@ Test
@@ -64,10 +68,7 @@ void getById() {
64
68
item .v = new ObjectId (2 , 0 );
65
69
sessionFactoryScope .inTransaction (session -> session .persist (item ));
66
70
var loadedItem = sessionFactoryScope .fromTransaction (session -> session .get (Item .class , item .id ));
67
- assertThat (loadedItem )
68
- .usingRecursiveComparison ()
69
- .withStrictTypeChecking ()
70
- .isEqualTo (item );
71
+ assertEquals (item , loadedItem );
71
72
}
72
73
73
74
@ Override
@@ -82,5 +83,20 @@ static class Item {
82
83
int id ;
83
84
84
85
ObjectId v ;
86
+ ObjectId vNull ;
87
+
88
+ @ Override
89
+ public boolean equals (Object o ) {
90
+ if (o == null || getClass () != o .getClass ()) {
91
+ return false ;
92
+ }
93
+ Item item = (Item ) o ;
94
+ return id == item .id && Objects .equals (v , item .v ) && vNull == item .vNull ;
95
+ }
96
+
97
+ @ Override
98
+ public int hashCode () {
99
+ return Objects .hash (id , v , vNull );
100
+ }
85
101
}
86
102
}
0 commit comments