41
41
import org .bson .BsonInt32 ;
42
42
import org .bson .BsonInt64 ;
43
43
import org .bson .BsonNull ;
44
+ import org .bson .BsonObjectId ;
44
45
import org .bson .BsonString ;
45
46
import org .bson .BsonValue ;
46
47
import org .bson .types .Decimal128 ;
48
+ import org .bson .types .ObjectId ;
47
49
import org .junit .jupiter .api .AutoClose ;
48
50
import org .junit .jupiter .api .BeforeEach ;
49
51
import org .junit .jupiter .api .Nested ;
@@ -106,7 +108,10 @@ void testGettersForNull() throws SQLException {
106
108
() -> assertEquals (0 , mongoResultSet .getInt (1 )),
107
109
() -> assertEquals (0L , mongoResultSet .getLong (1 )),
108
110
() -> assertEquals (0D , mongoResultSet .getDouble (1 )),
109
- () -> assertNull (mongoResultSet .getBigDecimal (1 )));
111
+ () -> assertNull (mongoResultSet .getBytes (1 )),
112
+ () -> assertNull (mongoResultSet .getBigDecimal (1 )),
113
+ () -> assertNull (mongoResultSet .getObject (1 , ObjectId .class )),
114
+ () -> assertTrue (mongoResultSet .wasNull ()));
110
115
}
111
116
112
117
@ Test
@@ -118,7 +123,10 @@ void testGettersForBoolean() throws SQLException {
118
123
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
119
124
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
120
125
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getDouble (1 )),
121
- () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )));
126
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBytes (1 )),
127
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
128
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getObject (1 , ObjectId .class )),
129
+ () -> assertFalse (mongoResultSet .wasNull ()));
122
130
}
123
131
124
132
@ Test
@@ -130,7 +138,10 @@ void testGettersForDouble() throws SQLException {
130
138
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
131
139
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
132
140
() -> assertEquals (3.1415 , mongoResultSet .getDouble (1 )),
133
- () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )));
141
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBytes (1 )),
142
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
143
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getObject (1 , ObjectId .class )),
144
+ () -> assertFalse (mongoResultSet .wasNull ()));
134
145
}
135
146
136
147
@ Test
@@ -142,7 +153,10 @@ void testGettersForInt() throws SQLException {
142
153
() -> assertEquals (120 , mongoResultSet .getInt (1 )),
143
154
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
144
155
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getDouble (1 )),
145
- () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )));
156
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBytes (1 )),
157
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
158
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getObject (1 , ObjectId .class )),
159
+ () -> assertFalse (mongoResultSet .wasNull ()));
146
160
}
147
161
148
162
@ Test
@@ -154,7 +168,10 @@ void testGettersForLong() throws SQLException {
154
168
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
155
169
() -> assertEquals (12345678L , mongoResultSet .getLong (1 )),
156
170
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getDouble (1 )),
157
- () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )));
171
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBytes (1 )),
172
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
173
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getObject (1 , ObjectId .class )),
174
+ () -> assertFalse (mongoResultSet .wasNull ()));
158
175
}
159
176
160
177
@ Test
@@ -166,7 +183,10 @@ void testGettersForString() throws SQLException {
166
183
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
167
184
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
168
185
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getDouble (1 )),
169
- () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )));
186
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBytes (1 )),
187
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
188
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getObject (1 , ObjectId .class )),
189
+ () -> assertFalse (mongoResultSet .wasNull ()));
170
190
}
171
191
172
192
@ Test
@@ -180,7 +200,10 @@ void testGettersForBigDecimal() throws SQLException {
180
200
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
181
201
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
182
202
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getDouble (1 )),
183
- () -> assertEquals (bigDecimalValue , mongoResultSet .getBigDecimal (1 )));
203
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBytes (1 )),
204
+ () -> assertEquals (bigDecimalValue , mongoResultSet .getBigDecimal (1 )),
205
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getObject (1 , ObjectId .class )),
206
+ () -> assertFalse (mongoResultSet .wasNull ()));
184
207
}
185
208
186
209
@ Test
@@ -194,8 +217,27 @@ void testGettersForBinary() throws SQLException {
194
217
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
195
218
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
196
219
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getDouble (1 )),
220
+ () -> assertEquals (bytes , mongoResultSet .getBytes (1 )),
221
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
222
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getObject (1 , ObjectId .class )),
223
+ () -> assertFalse (mongoResultSet .wasNull ()));
224
+ }
225
+
226
+ @ Test
227
+ void testGettersForObject () throws SQLException {
228
+ var objectId = new ObjectId (1 , 0 );
229
+ var value = new BsonObjectId (objectId );
230
+ createResultSetWith (value );
231
+ assertAll (
232
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getString (1 )),
233
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBoolean (1 )),
234
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
235
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
236
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getDouble (1 )),
237
+ () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBytes (1 )),
197
238
() -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
198
- () -> assertEquals (bytes , mongoResultSet .getBytes (1 )));
239
+ () -> assertEquals (objectId , mongoResultSet .getObject (1 , ObjectId .class )),
240
+ () -> assertFalse (mongoResultSet .wasNull ()));
199
241
}
200
242
}
201
243
0 commit comments