DATAMONGO-2385 - Remove unnecessary null checks in MongoConverters.
Original pull request: #802.
This commit is contained in:
committed by
Mark Paluch
parent
f7a010827d
commit
ff60149166
@@ -110,7 +110,7 @@ abstract class MongoConverters {
|
||||
INSTANCE;
|
||||
|
||||
public String convert(ObjectId id) {
|
||||
return id == null ? null : id.toString();
|
||||
return id.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ abstract class MongoConverters {
|
||||
INSTANCE;
|
||||
|
||||
public BigInteger convert(ObjectId source) {
|
||||
return source == null ? null : new BigInteger(source.toString(), 16);
|
||||
return new BigInteger(source.toString(), 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ abstract class MongoConverters {
|
||||
INSTANCE;
|
||||
|
||||
public ObjectId convert(BigInteger source) {
|
||||
return source == null ? null : new ObjectId(source.toString(16));
|
||||
return new ObjectId(source.toString(16));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ abstract class MongoConverters {
|
||||
INSTANCE;
|
||||
|
||||
public String convert(BigDecimal source) {
|
||||
return source == null ? null : source.toString();
|
||||
return source.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ abstract class MongoConverters {
|
||||
INSTANCE;
|
||||
|
||||
public Decimal128 convert(BigDecimal source) {
|
||||
return source == null ? null : new Decimal128(source);
|
||||
return new Decimal128(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ abstract class MongoConverters {
|
||||
INSTANCE;
|
||||
|
||||
public String convert(BigInteger source) {
|
||||
return source == null ? null : source.toString();
|
||||
return source.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,11 +238,6 @@ abstract class MongoConverters {
|
||||
|
||||
@Override
|
||||
public String convert(Document source) {
|
||||
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.toJson();
|
||||
}
|
||||
}
|
||||
@@ -258,7 +253,7 @@ abstract class MongoConverters {
|
||||
|
||||
@Override
|
||||
public String convert(Term source) {
|
||||
return source == null ? null : source.getFormatted();
|
||||
return source.getFormatted();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +268,7 @@ abstract class MongoConverters {
|
||||
@Override
|
||||
public NamedMongoScript convert(Document source) {
|
||||
|
||||
if (source == null) {
|
||||
if(source.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -295,10 +290,6 @@ abstract class MongoConverters {
|
||||
@Override
|
||||
public Document convert(NamedMongoScript source) {
|
||||
|
||||
if (source == null) {
|
||||
return new Document();
|
||||
}
|
||||
|
||||
Document document = new Document();
|
||||
|
||||
document.put("_id", source.getName());
|
||||
@@ -325,7 +316,7 @@ abstract class MongoConverters {
|
||||
*/
|
||||
@Override
|
||||
public String convert(Currency source) {
|
||||
return source == null ? null : source.getCurrencyCode();
|
||||
return source.getCurrencyCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +452,7 @@ abstract class MongoConverters {
|
||||
|
||||
@Override
|
||||
public AtomicLong convert(Long source) {
|
||||
return source != null ? new AtomicLong(source) : null;
|
||||
return new AtomicLong(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +468,7 @@ abstract class MongoConverters {
|
||||
|
||||
@Override
|
||||
public AtomicInteger convert(Integer source) {
|
||||
return source != null ? new AtomicInteger(source) : null;
|
||||
return new AtomicInteger(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,6 @@ public class NamedMongoScriptConvertsUnitTests {
|
||||
|
||||
NamedMongoScriptToDocumentConverter converter = NamedMongoScriptToDocumentConverter.INSTANCE;
|
||||
|
||||
@Test // DATAMONGO-479
|
||||
public void convertShouldReturnEmptyDocWhenScriptIsNull() {
|
||||
assertThat(converter.convert(null)).isEqualTo(new Document());
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-479
|
||||
public void convertShouldConvertScriptNameCorreclty() {
|
||||
|
||||
@@ -87,9 +82,9 @@ public class NamedMongoScriptConvertsUnitTests {
|
||||
|
||||
DocumentToNamedMongoScriptConverter converter = DocumentToNamedMongoScriptConverter.INSTANCE;
|
||||
|
||||
@Test // DATAMONGO-479
|
||||
public void convertShouldReturnNullIfSourceIsNull() {
|
||||
assertThat(converter.convert(null)).isNull();
|
||||
@Test // DATAMONGO-479, DATAMONGO-2385
|
||||
public void convertShouldReturnNullIfSourceIsEmpty() {
|
||||
assertThat(converter.convert(new Document())).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-479
|
||||
|
||||
@@ -15,11 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.convert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverters.TermToStringConverter;
|
||||
import org.springframework.data.mongodb.core.query.Term;
|
||||
import org.springframework.data.mongodb.core.query.Term.Type;
|
||||
@@ -29,11 +27,6 @@ import org.springframework.data.mongodb.core.query.Term.Type;
|
||||
*/
|
||||
public class TermToStringConverterUnitTests {
|
||||
|
||||
@Test // DATAMONGO-973
|
||||
public void shouldNotConvertNull() {
|
||||
assertThat(TermToStringConverter.INSTANCE.convert(null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-973
|
||||
public void shouldUseFormattedRepresentationForConversion() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user