20
20
import com .mongodb .MongoClientSettings ;
21
21
import com .mongodb .client .model .Filters ;
22
22
import org .bson .BsonDocument ;
23
+ import org .bson .BsonInt32 ;
23
24
import org .bson .Document ;
24
25
import org .junit .After ;
25
26
import org .junit .Before ;
26
27
import org .junit .Test ;
27
28
29
+ import static com .mongodb .ClusterFixture .serverVersionAtLeast ;
28
30
import static com .mongodb .client .Fixture .getDefaultDatabaseName ;
29
31
import static org .junit .Assert .assertFalse ;
30
32
import static org .junit .Assert .assertNotNull ;
31
33
import static org .junit .Assert .assertTrue ;
34
+ import static org .junit .Assume .assumeTrue ;
32
35
33
36
public abstract class AbstractExplainTest {
34
37
@@ -48,8 +51,13 @@ public void tearDown() {
48
51
49
52
@ Test
50
53
public void testExplain () {
51
- FindIterable <BsonDocument > iterable = client .getDatabase (getDefaultDatabaseName ())
52
- .getCollection ("explainTest" , BsonDocument .class ).find ()
54
+ assumeTrue (serverVersionAtLeast (3 , 0 ));
55
+
56
+ MongoCollection <BsonDocument > collection = client .getDatabase (getDefaultDatabaseName ())
57
+ .getCollection ("explainTest" , BsonDocument .class );
58
+ collection .insertOne (new BsonDocument ("_id" , new BsonInt32 (1 )));
59
+
60
+ FindIterable <BsonDocument > iterable = collection .find ()
53
61
.filter (Filters .eq ("_id" , 1 ));
54
62
55
63
Document explainDocument = iterable .explain ();
0 commit comments