Skip to content

Commit

Permalink
JAVA-725: Removing use of deprecated methods/constructors, mostly in …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
jyemin committed Mar 5, 2013
1 parent 093a2cb commit 1d2e6fa
Show file tree
Hide file tree
Showing 47 changed files with 288 additions and 311 deletions.
1 change: 1 addition & 0 deletions src/main/com/mongodb/ConnectionStatus.java
Expand Up @@ -41,6 +41,7 @@ abstract class ConnectionStatus {

protected static int updaterIntervalMS;
protected static int updaterIntervalNoMasterMS;
@SuppressWarnings("deprecation")
protected static final MongoOptions mongoOptionsDefaults = new MongoOptions();
protected static final float latencySmoothFactor;
protected static final DBObject isMasterCmd = new BasicDBObject("ismaster", 1);
Expand Down
1 change: 1 addition & 0 deletions src/main/com/mongodb/DBPort.java
Expand Up @@ -67,6 +67,7 @@ public class DBPort {
* creates a new DBPort
* @param addr the server address
*/
@SuppressWarnings("deprecation")
public DBPort( ServerAddress addr ){
this( addr , null , new MongoOptions() );
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/com/mongodb/MongoClient.java
Expand Up @@ -163,6 +163,7 @@ public MongoClient(ServerAddress addr, MongoClientOptions options) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
@SuppressWarnings("deprecation")
public MongoClient(ServerAddress addr, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.direct(addr, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
this.options = options;
Expand Down Expand Up @@ -247,6 +248,7 @@ public MongoClient(List<ServerAddress> seeds, MongoClientOptions options) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
@SuppressWarnings("deprecation")
public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.dynamicSet(seeds, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
this.options = options;
Expand All @@ -262,6 +264,7 @@ public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsL
* @see MongoURI
* @dochub connections
*/
@SuppressWarnings("deprecation")
public MongoClient(MongoClientURI uri) throws UnknownHostException {
super(new MongoURI(uri));
this.options = uri.getOptions();
Expand Down
1 change: 1 addition & 0 deletions src/main/com/mongodb/MongoURI.java
Expand Up @@ -215,6 +215,7 @@ public MongoOptions getOptions(){
* @throws MongoException
* @throws UnknownHostException
*/
@SuppressWarnings("deprecation")
public Mongo connect()
throws UnknownHostException {
// TODO caching?
Expand Down
13 changes: 8 additions & 5 deletions src/main/com/mongodb/gridfs/CLI.java
Expand Up @@ -18,14 +18,15 @@

package com.mongodb.gridfs;

import java.io.File;
import java.security.DigestInputStream;
import java.security.MessageDigest;

import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.util.Util;

import java.io.File;
import java.security.DigestInputStream;
import java.security.MessageDigest;


/**
* a simple CLI for Gridfs
Expand All @@ -48,10 +49,12 @@ private static void printUsage() {
private static String db = "test";

private static Mongo _mongo = null;

@SuppressWarnings("deprecation")
private static Mongo getMongo()
throws Exception {
if ( _mongo == null )
_mongo = new Mongo( host );
_mongo = new MongoClient( host );
return _mongo;
}

Expand Down
18 changes: 8 additions & 10 deletions src/test/com/mongodb/ByteTest.java
Expand Up @@ -16,6 +16,14 @@

package com.mongodb;

import com.mongodb.util.TestCase;
import org.bson.BSON;
import org.bson.BSONDecoder;
import org.bson.BSONObject;
import org.bson.BasicBSONDecoder;
import org.bson.types.ObjectId;
import org.testng.annotations.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -28,22 +36,12 @@
import java.util.Set;
import java.util.regex.Pattern;

import org.bson.BSON;
import org.bson.BSONDecoder;
import org.bson.BSONObject;
import org.bson.BasicBSONDecoder;
import org.bson.types.ObjectId;
import org.testng.annotations.Test;

import com.mongodb.util.TestCase;


@SuppressWarnings({"unchecked", "rawtypes"})
public class ByteTest extends TestCase {

public ByteTest() throws IOException , MongoException {
super();
cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_mongodb_unittest_ByteTest";
_db = cleanupMongo.getDB( cleanupDB );
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/com/mongodb/DBCollectionTest.java
Expand Up @@ -30,7 +30,6 @@ public class DBCollectionTest extends TestCase {
public DBCollectionTest()
throws IOException , MongoException {
super();
cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_mongodb_unittest_DBCollectionTest";
_db = cleanupMongo.getDB( cleanupDB );
}
Expand Down Expand Up @@ -166,7 +165,7 @@ public void testFindOneSort(){
*/
@Test
public void testDropDatabase() throws Exception {
final Mongo mongo = new Mongo( "127.0.0.1" );
final Mongo mongo = new MongoClient( "127.0.0.1" );
mongo.getDB("com_mongodb_unittest_dropDatabaseTest").dropDatabase();
mongo.close();
}
Expand Down
10 changes: 4 additions & 6 deletions src/test/com/mongodb/DBCursorTest.java
Expand Up @@ -35,9 +35,8 @@ public class DBCursorTest extends TestCase {

public DBCursorTest() throws IOException , MongoException {
super();
cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_mongodb_unittest_DBCursorTest";
_db = cleanupMongo.getDB( cleanupDB );
cleanupDB = "com_mongodb_unittest_DBCursorTest";
_db = cleanupMongo.getDB(cleanupDB);
}

@Test(groups = {"basic"})
Expand Down Expand Up @@ -502,9 +501,8 @@ public void testHasFinalizer() throws UnknownHostException {
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);
MongoClientOptions mongoOptions = new MongoClientOptions.Builder().cursorFinalizerEnabled(false).build();
Mongo m = new MongoClient("127.0.0.1", mongoOptions);
try {
c = m.getDB(cleanupDB).getCollection("HasFinalizerTest");
cursor = c.find();
Expand Down
25 changes: 9 additions & 16 deletions src/test/com/mongodb/DBObjectTest.java
Expand Up @@ -16,30 +16,23 @@

package com.mongodb;

import java.net.*;
import java.util.*;


import com.mongodb.util.TestCase;
import org.bson.types.BasicBSONList;
import org.bson.types.ObjectId;
import org.testng.annotations.Test;

import com.mongodb.util.*;

import org.bson.*;
import org.bson.types.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings({"unchecked", "deprecation"})
public class DBObjectTest extends TestCase {

public DBObjectTest() {
super();
try {
cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_monogodb_unittest_DBObjectTest";
_db = cleanupMongo.getDB( cleanupDB );
}
catch(UnknownHostException e) {
throw new MongoException("couldn't connect");
}
cleanupDB = "com_monogodb_unittest_DBObjectTest";
_db = cleanupMongo.getDB(cleanupDB);
}

@Test(groups = {"basic"})
Expand Down
2 changes: 2 additions & 0 deletions src/test/com/mongodb/DBPortPoolTest.java
Expand Up @@ -33,6 +33,7 @@
public class DBPortPoolTest extends com.mongodb.util.TestCase {

@Test
@SuppressWarnings("deprecation")
public void testReuse() throws Exception {
MongoOptions options = new MongoOptions();
options.connectionsPerHost = 10;
Expand Down Expand Up @@ -85,6 +86,7 @@ public void run(){
}

@Test
@SuppressWarnings("deprecation")
public void testInterruptedException() throws UnknownHostException, InterruptedException {
MongoOptions options = new MongoOptions();
options.connectionsPerHost = 1;
Expand Down
3 changes: 2 additions & 1 deletion src/test/com/mongodb/DBPortTest.java
Expand Up @@ -26,8 +26,9 @@

public class DBPortTest extends TestCase {
@Test
@SuppressWarnings("deprecation")
public void testAuthentication() throws IOException {
Mongo m = new Mongo();
Mongo m = new MongoClient();
DB db1 = m.getDB("DBPortTest1");
DB db2 = m.getDB("DBPortTest2");
db1.dropDatabase();
Expand Down
11 changes: 2 additions & 9 deletions src/test/com/mongodb/DBRefTest.java
Expand Up @@ -24,21 +24,14 @@
import org.bson.types.ObjectId;
import org.testng.annotations.Test;

import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

public class DBRefTest extends TestCase {

public DBRefTest() {
try {
cleanupMongo = new Mongo( "127.0.0.1" );
cleanupDB = "com_monogodb_unittest_DBRefTest";
_db = cleanupMongo.getDB( cleanupDB );
}
catch(UnknownHostException e) {
throw new MongoException("couldn't connect");
}
cleanupDB = "com_monogodb_unittest_DBRefTest";
_db = cleanupMongo.getDB(cleanupDB);
}

@Test(groups = {"basic"})
Expand Down

0 comments on commit 1d2e6fa

Please sign in to comment.