Skip to content

Commit 82195ae

Browse files
small cleanup and test from user contribution/question
1 parent 470d891 commit 82195ae

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/main/com/mongodb/DBCollection.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
package com.mongodb;
2020

2121
// Mongo
22-
import org.bson.types.*;
23-
import com.mongodb.util.*;
24-
25-
// Java
2622
import java.util.*;
2723

24+
import org.bson.types.ObjectId;
25+
2826
/** This class provides a skeleton implementation of a database collection.
2927
* <p>A typical invocation sequence is thus
3028
* <blockquote><pre>
@@ -556,9 +554,7 @@ public final DBObject findOne( DBObject o )
556554
*/
557555
public final DBObject findOne( DBObject o, DBObject fields ) {
558556
Iterator<DBObject> i = __find( o , fields , 0 , -1 , 0, getOptions() );
559-
if ( i == null || ! i.hasNext() )
560-
return null;
561-
return i.next();
557+
return i == null ? null : i.next();
562558
}
563559

564560
/**

src/test/com/mongodb/DBCollectionTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package com.mongodb;
1818

19-
import java.io.*;
20-
import java.util.*;
19+
import java.io.IOException;
20+
import java.util.List;
2121

22-
import org.testng.annotations.*;
22+
import org.testng.annotations.Test;
2323

24-
import com.mongodb.util.*;
24+
import com.mongodb.util.TestCase;
2525

2626
public class DBCollectionTest extends TestCase {
2727

@@ -53,6 +53,12 @@ public void testFindOne() {
5353
DBObject obj = c.findOne();
5454
assertEquals(obj, null);
5555

56+
obj = c.findOne(null);
57+
assertEquals(obj, null);
58+
59+
obj = c.findOne(null, null);
60+
assertEquals(obj, null);
61+
5662
DBObject inserted = BasicDBObjectBuilder.start().add("x",1).add("y",2).get();
5763
c.insert(inserted);
5864
c.insert(BasicDBObjectBuilder.start().add("_id", 123).add("x",2).add("z",2).get());

0 commit comments

Comments
 (0)