4141import org .bson .BsonInt32 ;
4242import org .bson .BsonInt64 ;
4343import org .bson .BsonNull ;
44+ import org .bson .BsonObjectId ;
4445import org .bson .BsonString ;
4546import org .bson .BsonValue ;
4647import org .bson .types .Decimal128 ;
48+ import org .bson .types .ObjectId ;
4749import org .junit .jupiter .api .AutoClose ;
4850import org .junit .jupiter .api .BeforeEach ;
4951import org .junit .jupiter .api .Nested ;
@@ -106,7 +108,10 @@ void testGettersForNull() throws SQLException {
106108 () -> assertEquals (0 , mongoResultSet .getInt (1 )),
107109 () -> assertEquals (0L , mongoResultSet .getLong (1 )),
108110 () -> 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 ()));
110115 }
111116
112117 @ Test
@@ -118,7 +123,10 @@ void testGettersForBoolean() throws SQLException {
118123 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
119124 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
120125 () -> 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 ()));
122130 }
123131
124132 @ Test
@@ -130,7 +138,10 @@ void testGettersForDouble() throws SQLException {
130138 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
131139 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
132140 () -> 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 ()));
134145 }
135146
136147 @ Test
@@ -142,7 +153,10 @@ void testGettersForInt() throws SQLException {
142153 () -> assertEquals (120 , mongoResultSet .getInt (1 )),
143154 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
144155 () -> 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 ()));
146160 }
147161
148162 @ Test
@@ -154,7 +168,10 @@ void testGettersForLong() throws SQLException {
154168 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
155169 () -> assertEquals (12345678L , mongoResultSet .getLong (1 )),
156170 () -> 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 ()));
158175 }
159176
160177 @ Test
@@ -166,7 +183,10 @@ void testGettersForString() throws SQLException {
166183 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
167184 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
168185 () -> 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 ()));
170190 }
171191
172192 @ Test
@@ -180,7 +200,10 @@ void testGettersForBigDecimal() throws SQLException {
180200 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
181201 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
182202 () -> 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 ()));
184207 }
185208
186209 @ Test
@@ -194,8 +217,27 @@ void testGettersForBinary() throws SQLException {
194217 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getInt (1 )),
195218 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getLong (1 )),
196219 () -> 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 )),
197238 () -> assertThrowsTypeMismatchException (() -> mongoResultSet .getBigDecimal (1 )),
198- () -> assertEquals (bytes , mongoResultSet .getBytes (1 )));
239+ () -> assertEquals (objectId , mongoResultSet .getObject (1 , ObjectId .class )),
240+ () -> assertFalse (mongoResultSet .wasNull ()));
199241 }
200242 }
201243
0 commit comments