File tree Expand file tree Collapse file tree 3 files changed +24
-12
lines changed
driver/src/test/org/mongodb
driver-compat/src/main/com/mongodb Expand file tree Collapse file tree 3 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -233,16 +233,15 @@ public static byte getType(final Object o) {
233
233
return OBJECT ;
234
234
}
235
235
236
- if (o instanceof Code ) {
237
- return CODE ;
238
- }
239
-
240
236
if (o instanceof CodeWScope ) {
241
237
return CODE_W_SCOPE ;
242
238
}
243
239
240
+ if (o instanceof Code ) {
241
+ return CODE ;
242
+ }
243
+
244
244
return -1 ;
245
245
}
246
246
247
- static final ObjectId COLLECTION_REF_ID = new ObjectId (-1 , -1 , -1 );
248
247
}
Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ public void setUp() {
40
40
}
41
41
}
42
42
43
+ @ After
44
+ public void tearDown () {
45
+ super .tearDown ();
46
+ if (cursor != null ) {
47
+ cursor .close ();
48
+ }
49
+ }
50
+
43
51
@ Test
44
52
public void testNormalLoopWithGetMore () {
45
53
cursor = collection .sort (new SortCriteriaDocument ("_id" , 1 )).batchSize (2 ).all ();
@@ -92,11 +100,4 @@ public void shouldNotBeAbleToCallHasNextAfterClose() {
92
100
cursor .close ();
93
101
cursor .hasNext ();
94
102
}
95
-
96
- @ After
97
- public void tearDown () {
98
- if (cursor != null ) {
99
- cursor .close ();
100
- }
101
- }
102
103
}
Original file line number Diff line number Diff line change 17
17
package org .mongodb ;
18
18
19
19
import org .bson .types .Document ;
20
+ import org .bson .types .ObjectId ;
20
21
import org .junit .Test ;
21
22
22
23
import static org .hamcrest .core .Is .is ;
@@ -45,4 +46,15 @@ public void shouldUpsertIfAbsent() {
45
46
collection .save (document );
46
47
assertThat ("Did not upsert the document" , collection .one (), is (document ));
47
48
}
49
+
50
+ @ Test
51
+ public void shouldUpsertWithNewObjectId () {
52
+ final Document document = new Document ("_id" , new ObjectId ()).append ("x" , 1 );
53
+ collection .save (document );
54
+ assertThat ("Did not replace the document" , collection .one (), is (document ));
55
+
56
+ document .put ("y" , 2 );
57
+ collection .save (document );
58
+ assertThat ("Did not replace the document" , collection .one (), is (document ));
59
+ }
48
60
}
You can’t perform that action at this time.
0 commit comments