DATAMONGO-2198 - Polishing.
Remove final keywords from method arguments. Typos, remove commented code. Simplify test. Original pull request: #643.
This commit is contained in:
@@ -41,7 +41,8 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
|
||||
private static final MongoClientOptions DEFAULT_MONGO_OPTIONS = MongoClientOptions.builder().build();
|
||||
|
||||
private @Nullable String description = DEFAULT_MONGO_OPTIONS.getApplicationName(); // TODO: Mongo Driver 4 - use application name insetad of desription if not available
|
||||
// TODO: Mongo Driver 4 - use application name insetad of description if not available
|
||||
private @Nullable String description = DEFAULT_MONGO_OPTIONS.getApplicationName();
|
||||
private int minConnectionsPerHost = DEFAULT_MONGO_OPTIONS.getMinConnectionsPerHost();
|
||||
private int connectionsPerHost = DEFAULT_MONGO_OPTIONS.getConnectionsPerHost();
|
||||
private int threadsAllowedToBlockForConnectionMultiplier = DEFAULT_MONGO_OPTIONS
|
||||
@@ -51,14 +52,18 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
private int maxConnectionLifeTime = DEFAULT_MONGO_OPTIONS.getMaxConnectionLifeTime();
|
||||
private int connectTimeout = DEFAULT_MONGO_OPTIONS.getConnectTimeout();
|
||||
private int socketTimeout = DEFAULT_MONGO_OPTIONS.getSocketTimeout();
|
||||
private boolean socketKeepAlive = DEFAULT_MONGO_OPTIONS.isSocketKeepAlive(); // TODO: Mongo Driver 4 - check if available
|
||||
|
||||
// TODO: Mongo Driver 4 - check if available
|
||||
private boolean socketKeepAlive = DEFAULT_MONGO_OPTIONS.isSocketKeepAlive();
|
||||
private @Nullable ReadPreference readPreference = DEFAULT_MONGO_OPTIONS.getReadPreference();
|
||||
private DBDecoderFactory dbDecoderFactory = DEFAULT_MONGO_OPTIONS.getDbDecoderFactory();
|
||||
private DBEncoderFactory dbEncoderFactory = DEFAULT_MONGO_OPTIONS.getDbEncoderFactory();
|
||||
private @Nullable WriteConcern writeConcern = DEFAULT_MONGO_OPTIONS.getWriteConcern();
|
||||
private @Nullable SocketFactory socketFactory = DEFAULT_MONGO_OPTIONS.getSocketFactory();
|
||||
private boolean cursorFinalizerEnabled = DEFAULT_MONGO_OPTIONS.isCursorFinalizerEnabled();
|
||||
private boolean alwaysUseMBeans = DEFAULT_MONGO_OPTIONS.isAlwaysUseMBeans(); // TODO: Mongo Driver 4 - remove this option
|
||||
|
||||
// TODO: Mongo Driver 4 - remove this option
|
||||
private boolean alwaysUseMBeans = DEFAULT_MONGO_OPTIONS.isAlwaysUseMBeans();
|
||||
private int heartbeatFrequency = DEFAULT_MONGO_OPTIONS.getHeartbeatFrequency();
|
||||
private int minHeartbeatFrequency = DEFAULT_MONGO_OPTIONS.getMinHeartbeatFrequency();
|
||||
private int heartbeatConnectTimeout = DEFAULT_MONGO_OPTIONS.getHeartbeatConnectTimeout();
|
||||
@@ -236,7 +241,7 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
}
|
||||
|
||||
/**
|
||||
* This controls if the driver should us an SSL connection. Defaults to |@literal false}.
|
||||
* This controls if the driver should us an SSL connection. Defaults to {@literal false}.
|
||||
*
|
||||
* @param ssl
|
||||
*/
|
||||
@@ -286,7 +291,7 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
.cursorFinalizerEnabled(cursorFinalizerEnabled) //
|
||||
.dbDecoderFactory(dbDecoderFactory) //
|
||||
.dbEncoderFactory(dbEncoderFactory) //
|
||||
.applicationName(description) // TODO: Mongo Driver 4 - use applicatoin name if description not available
|
||||
.applicationName(description) // TODO: Mongo Driver 4 - use application name if description not available
|
||||
.heartbeatConnectTimeout(heartbeatConnectTimeout) //
|
||||
.heartbeatFrequency(heartbeatFrequency) //
|
||||
.heartbeatSocketTimeout(heartbeatSocketTimeout) //
|
||||
@@ -298,6 +303,7 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
|
||||
.readPreference(readPreference) //
|
||||
.requiredReplicaSetName(requiredReplicaSetName) //
|
||||
.serverSelectionTimeout(serverSelectionTimeout) //
|
||||
.sslEnabled(ssl) //
|
||||
.socketFactory(socketFactoryToUse) // TODO: Mongo Driver 4 - remove if not available
|
||||
.socketKeepAlive(socketKeepAlive) // TODO: Mongo Driver 4 - remove if not available
|
||||
.socketTimeout(socketTimeout) //
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.stream.Collectors;
|
||||
import org.bson.BsonRegularExpression;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.Binary;
|
||||
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.geo.Circle;
|
||||
import org.springframework.data.geo.Point;
|
||||
@@ -920,7 +921,7 @@ public class Criteria implements CriteriaDefinition {
|
||||
|
||||
/**
|
||||
* Lookup the MongoDB specific flags for a given regex option string.
|
||||
*
|
||||
*
|
||||
* @param s the Regex option/flag to look up. Can be {@literal null}.
|
||||
* @return zero if given {@link String} is {@literal null} or empty.
|
||||
* @since 2.2
|
||||
@@ -945,10 +946,10 @@ public class Criteria implements CriteriaDefinition {
|
||||
*
|
||||
* @param c the Regex option/flag to look up.
|
||||
* @return
|
||||
* @throws IllegalArgumentException for unkown flags
|
||||
* @throws IllegalArgumentException for unknown flags
|
||||
* @since 2.2
|
||||
*/
|
||||
private static int regexFlag(final char c) {
|
||||
private static int regexFlag(char c) {
|
||||
|
||||
int flag = FLAG_LOOKUP[c];
|
||||
|
||||
@@ -1135,7 +1136,7 @@ public class Criteria implements CriteriaDefinition {
|
||||
|
||||
/**
|
||||
* Default implementation of {@link BitwiseCriteriaOperators}.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @currentRead Beyond the Shadows - Brent Weeks
|
||||
*/
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.json.JsonMode;
|
||||
import org.bson.json.JsonWriterSettings;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -120,8 +119,8 @@ public abstract class SerializationUtils {
|
||||
}
|
||||
|
||||
try {
|
||||
String json = value instanceof Document ? ((Document) value).toJson() : serializeValue(value);
|
||||
return json.replaceAll("\"\\:", "\" :").replaceAll("\\{\"", "{ \""); //.replaceAll("\\]\\}", "] }");
|
||||
String json = value instanceof Document ? ((Document) value).toJson() : serializeValue(value);
|
||||
return json.replaceAll("\":", "\" :").replaceAll("\\{\"", "{ \"");
|
||||
} catch (Exception e) {
|
||||
|
||||
if (value instanceof Collection) {
|
||||
@@ -130,9 +129,7 @@ public abstract class SerializationUtils {
|
||||
return toString((Map<?, ?>) value);
|
||||
} else if (ObjectUtils.isArray(value)) {
|
||||
return toString(Arrays.asList(ObjectUtils.toObjectArray(value)));
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
return String.format("{ \"$java\" : %s }", value.toString());
|
||||
}
|
||||
}
|
||||
@@ -140,7 +137,7 @@ public abstract class SerializationUtils {
|
||||
|
||||
public static String serializeValue(@Nullable Object value) {
|
||||
|
||||
if(value == null) {
|
||||
if (value == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,8 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.Description;
|
||||
@@ -32,20 +29,17 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.mongodb.test.util.CleanMongoDB.Struct;
|
||||
|
||||
import com.mongodb.Block;
|
||||
import com.mongodb.Function;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.ListCollectionsIterable;
|
||||
import com.mongodb.client.ListDatabasesIterable;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.MongoIterable;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CleanMongoDBTests {
|
||||
@@ -63,144 +57,26 @@ public class CleanMongoDBTests {
|
||||
private @Mock MongoDatabase db1mock, db2mock;
|
||||
private @Mock MongoCollection<Document> db1collection1mock, db1collection2mock, db2collection1mock;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@SuppressWarnings({ "serial", "unchecked" })
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
// DB setup
|
||||
when(mongoClientMock.listDatabaseNames()).thenReturn(new ListDatabasesIterable<String>() {
|
||||
@Override
|
||||
public ListDatabasesIterable<String> maxTime(long maxTime, TimeUnit timeUnit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDatabasesIterable<String> batchSize(int batchSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDatabasesIterable<String> filter(Bson filter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDatabasesIterable<String> nameOnly(Boolean nameOnly) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoCursor<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String first() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> MongoIterable<U> map(Function<String, U> mapper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Block<? super String> block) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A extends Collection<? super String>> A into(A target) {
|
||||
return (A) Arrays.asList("admin", "db1", "db2");
|
||||
}
|
||||
});
|
||||
ListDatabasesIterable<String> dbIterable = mock(ListDatabasesIterable.class);
|
||||
when(dbIterable.into(any(Collection.class))).thenReturn(Arrays.asList("admin", "db1", "db2"));
|
||||
when(mongoClientMock.listDatabaseNames()).thenReturn(dbIterable);
|
||||
when(mongoClientMock.getDatabase(eq("db1"))).thenReturn(db1mock);
|
||||
when(mongoClientMock.getDatabase(eq("db2"))).thenReturn(db2mock);
|
||||
|
||||
// collections have to exist
|
||||
when(db1mock.listCollectionNames()).thenReturn(new ListCollectionsIterable<String>() {
|
||||
@Override
|
||||
public ListCollectionsIterable<String> filter(Bson filter) {
|
||||
return null;
|
||||
}
|
||||
ListDatabasesIterable<String> collectionIterable = mock(ListDatabasesIterable.class);
|
||||
when(collectionIterable.into(any(Collection.class))).thenReturn(Arrays.asList("db1collection1", "db1collection2"));
|
||||
when(db1mock.listCollectionNames()).thenReturn(collectionIterable);
|
||||
|
||||
@Override
|
||||
public ListCollectionsIterable<String> maxTime(long maxTime, TimeUnit timeUnit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListCollectionsIterable<String> batchSize(int batchSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoCursor<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String first() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> MongoIterable<U> map(Function<String, U> mapper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Block<? super String> block) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A extends Collection<? super String>> A into(A target) {
|
||||
return (A) Arrays.asList("db1collection1", "db1collection2");
|
||||
}
|
||||
});
|
||||
|
||||
when(db2mock.listCollectionNames()).thenReturn(new ListCollectionsIterable<String>() {
|
||||
@Override
|
||||
public ListCollectionsIterable<String> filter(Bson filter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListCollectionsIterable<String> maxTime(long maxTime, TimeUnit timeUnit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListCollectionsIterable<String> batchSize(int batchSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoCursor<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String first() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> MongoIterable<U> map(Function<String, U> mapper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Block<? super String> block) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A extends Collection<? super String>> A into(A target) {
|
||||
return (A) Arrays.asList("db2collection1");
|
||||
}
|
||||
});
|
||||
ListDatabasesIterable<String> collectionIterable2 = mock(ListDatabasesIterable.class);
|
||||
when(collectionIterable2.into(any(Collection.class))).thenReturn(Collections.singletonList("db2collection1"));
|
||||
when(db2mock.listCollectionNames()).thenReturn(collectionIterable2);
|
||||
|
||||
// return collections according to names
|
||||
when(db1mock.getCollection(eq("db1collection1"))).thenReturn(db1collection1mock);
|
||||
|
||||
Reference in New Issue
Block a user