Skip to content

Commit f5c4de9

Browse files
committed
Added tests of WriteResult returned from DBCollection insert methods
1 parent 8f3fe06 commit f5c4de9

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/test/com/mongodb/JavaClientTest.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.concurrent.TimeUnit;
4545
import java.util.regex.Pattern;
4646

47+
import static java.util.Arrays.asList;
4748
import static org.junit.Assert.assertEquals;
4849
import static org.junit.Assert.assertFalse;
4950
import static org.junit.Assert.assertNotNull;
@@ -491,7 +492,7 @@ public void testMapReduceInlineSecondary() throws Exception {
491492
return;
492493
}
493494

494-
Mongo mongo = new MongoClient(Arrays.asList(new ServerAddress("127.0.0.1", 27017), new ServerAddress("127.0.0.1", 27018)),
495+
Mongo mongo = new MongoClient(asList(new ServerAddress("127.0.0.1", 27017), new ServerAddress("127.0.0.1", 27018)),
495496
MongoClientOptions.builder().writeConcern(WriteConcern.UNACKNOWLEDGED).build());
496497

497498
int size = getReplicaSetSize(mongo);
@@ -914,6 +915,24 @@ public void testWriteResultOnUnacknowledgedUpdate(){
914915
assertTrue(res.isLazy());
915916
}
916917

918+
@Test
919+
public void testWriteResultOnInsert(){
920+
WriteResult res = collection.insert(new BasicDBObject());
921+
assertEquals(0, res.getN());
922+
assertFalse(res.isUpdateOfExisting());
923+
assertNull(res.getUpsertedId());
924+
assertFalse(res.isLazy());
925+
}
926+
927+
@Test
928+
public void testWriteResultOnInsertList(){
929+
WriteResult res = collection.insert(Arrays.<DBObject>asList(new BasicDBObject(), new BasicDBObject()));
930+
assertEquals(0, res.getN());
931+
assertFalse(res.isUpdateOfExisting());
932+
assertNull(res.getUpsertedId());
933+
assertFalse(res.isLazy());
934+
}
935+
917936
@Test
918937
public void testWriteResultOnUpdate(){
919938
collection.insert(new BasicDBObject("_id", 1));
@@ -1101,7 +1120,7 @@ public void testBadKey(){
11011120
} catch (IllegalArgumentException e) {}
11021121

11031122
try {
1104-
final List<BasicDBObject> list = Arrays.asList(new BasicDBObject("$a", 1));
1123+
final List<BasicDBObject> list = asList(new BasicDBObject("$a", 1));
11051124
c.save(new BasicDBObject("a", list));
11061125
fail("Bad key was accepted");
11071126
} catch (IllegalArgumentException e) {}

0 commit comments

Comments
 (0)