@Test
  @SuppressWarnings("deprecation")
  public void testToClientOptions() throws UnknownHostException {
    MongoOptions options = new MongoOptions();
    options.description = "my client";
    options.fsync = true;
    options.readPreference = ReadPreference.secondary();
    options.requiredReplicaSetName = "test";
    options.cursorFinalizerEnabled = false;
    options.alwaysUseMBeans = true;
    options.connectTimeout = 100;
    options.maxWaitTime = 500;
    options.socketKeepAlive = true;
    options.threadsAllowedToBlockForConnectionMultiplier = 10;

    MongoClientOptions clientOptions = options.toClientOptions();

    assertEquals(options.requiredReplicaSetName, clientOptions.getRequiredReplicaSetName());
    assertEquals(options.description, clientOptions.getDescription());
    assertEquals(WriteConcern.ACKNOWLEDGED.withFsync(true), clientOptions.getWriteConcern());
    assertEquals(0, clientOptions.getMinConnectionsPerHost());
    assertEquals(10, clientOptions.getConnectionsPerHost());
    assertEquals(100, clientOptions.getConnectTimeout());
    assertEquals(500, clientOptions.getMaxWaitTime());
    assertEquals(ReadPreference.secondary(), clientOptions.getReadPreference());
    assertEquals(10, clientOptions.getThreadsAllowedToBlockForConnectionMultiplier());
    assertTrue(clientOptions.isSocketKeepAlive());
    assertFalse(clientOptions.isSslEnabled());
    assertEquals(options.dbDecoderFactory, clientOptions.getDbDecoderFactory());
    assertEquals(options.dbEncoderFactory, clientOptions.getDbEncoderFactory());
    assertEquals(15, clientOptions.getLocalThreshold());
    assertTrue(clientOptions.isAlwaysUseMBeans());
    assertFalse(clientOptions.isCursorFinalizerEnabled());
  }
  @Test
  @SuppressWarnings("deprecation")
  public void testCopy() throws Exception {

    MongoOptions options = new MongoOptions();

    options.connectionsPerHost = 100;
    options.threadsAllowedToBlockForConnectionMultiplier = 101;
    options.maxWaitTime = 102;
    options.connectTimeout = 103;
    options.socketTimeout = 104;
    options.socketKeepAlive = true;
    options.safe = true;
    options.w = 106;
    options.wtimeout = 107;
    options.fsync = true;
    options.j = false;
    options.dbDecoderFactory = null;
    options.dbEncoderFactory = null;
    options.description = "cool";
    options.readPreference = ReadPreference.secondary();
    options.cursorFinalizerEnabled = true;
    options.socketFactory = SSLSocketFactory.getDefault();
    options.alwaysUseMBeans = true;
    options.requiredReplicaSetName = "set1";

    MongoOptions copy = options.copy();
    assertEquals(options.connectionsPerHost, copy.connectionsPerHost);
    assertEquals(
        options.threadsAllowedToBlockForConnectionMultiplier,
        copy.threadsAllowedToBlockForConnectionMultiplier);
    assertEquals(options.maxWaitTime, copy.maxWaitTime);
    assertEquals(options.connectTimeout, copy.connectTimeout);
    assertEquals(options.socketTimeout, copy.socketTimeout);
    assertEquals(options.socketKeepAlive, copy.socketKeepAlive);
    assertEquals(options.safe, copy.safe);
    assertEquals(options.w, copy.w);
    assertEquals(options.wtimeout, copy.wtimeout);
    assertEquals(options.fsync, copy.fsync);
    assertEquals(options.j, copy.j);
    assertEquals(options.dbDecoderFactory, copy.dbDecoderFactory);
    assertEquals(options.dbEncoderFactory, copy.dbEncoderFactory);
    assertEquals(options.description, copy.description);
    assertEquals(options.readPreference, copy.readPreference);
    assertEquals(options.alwaysUseMBeans, copy.alwaysUseMBeans);
    assertEquals(options.socketFactory, copy.socketFactory);
    assertEquals(options.requiredReplicaSetName, copy.requiredReplicaSetName);
  }
  @Test
  public void testHasFinalizer() throws UnknownHostException {
    DBCollection c = _db.getCollection("HasFinalizerTest");
    c.drop();

    for (int i = 0; i < 1000; i++) c.save(new BasicDBObject("_id", i), WriteConcern.SAFE);

    // finalizer is on by default so after calling hasNext should report that it has one
    DBCursor cursor = c.find();
    assertFalse(cursor.hasFinalizer());
    cursor.hasNext();
    assertTrue(cursor.hasFinalizer());
    cursor.close();

    // no finalizer if there is no cursor, as there should not be for a query with only one result
    cursor = c.find(new BasicDBObject("_id", 1));
    cursor.hasNext();
    assertFalse(cursor.hasFinalizer());
    cursor.close();

    // no finalizer if there is no cursor, as there should not be for a query with negative batch
    // size
    cursor = c.find();
    cursor.batchSize(-1);
    cursor.hasNext();
    assertFalse(cursor.hasFinalizer());
    cursor.close();

    // finally, no finalizer if disabled in mongo options
    MongoOptions mongoOptions = new MongoOptions();
    mongoOptions.cursorFinalizerEnabled = false;
    Mongo m = new Mongo("127.0.0.1", mongoOptions);
    try {
      c = m.getDB(cleanupDB).getCollection("HasFinalizerTest");
      cursor = c.find();
      cursor.hasNext();
      assertFalse(cursor.hasFinalizer());
      cursor.close();
    } finally {
      m.close();
    }
  }