Skip to content

Commit 4bbc443

Browse files
committed
Polishing.
Refine assertions. See #4132 Original pull request: #4147.
1 parent 655dbc9 commit 4bbc443

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import java.util.*;
2424
import java.util.concurrent.TimeUnit;
2525
import java.util.function.BiPredicate;
26-
import java.util.function.Supplier;
2726
import java.util.stream.Collectors;
2827
import java.util.stream.Stream;
2928

3029
import org.apache.commons.logging.Log;
3130
import org.apache.commons.logging.LogFactory;
3231
import org.bson.Document;
3332
import org.bson.conversions.Bson;
33+
3434
import org.springframework.beans.BeansException;
3535
import org.springframework.context.ApplicationContext;
3636
import org.springframework.context.ApplicationContextAware;
@@ -1870,21 +1870,21 @@ public <T> List<T> mapReduce(Query query, Class<?> domainType, String inputColle
18701870

18711871
@Override
18721872
public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) {
1873+
1874+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
18731875
return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType);
18741876
}
18751877

18761878
@Override
18771879
public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName,
18781880
Class<O> outputType) {
1879-
1880-
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
1881-
18821881
return aggregate(aggregation, inputCollectionName, outputType, null);
18831882
}
18841883

18851884
@Override
18861885
public <O> AggregationResults<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
18871886

1887+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
18881888
return aggregate(aggregation, getCollectionName(inputType), outputType,
18891889
queryOperations.createAggregation(aggregation, inputType).getAggregationOperationContext());
18901890
}
@@ -1897,19 +1897,20 @@ public <O> AggregationResults<O> aggregate(Aggregation aggregation, String colle
18971897
@Override
18981898
public <O> Stream<O> aggregateStream(TypedAggregation<?> aggregation, String inputCollectionName,
18991899
Class<O> outputType) {
1900-
1901-
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
19021900
return aggregateStream(aggregation, inputCollectionName, outputType, null);
19031901
}
19041902

19051903
@Override
19061904
public <O> Stream<O> aggregateStream(TypedAggregation<?> aggregation, Class<O> outputType) {
1905+
1906+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
19071907
return aggregateStream(aggregation, getCollectionName(aggregation.getInputType()), outputType);
19081908
}
19091909

19101910
@Override
19111911
public <O> Stream<O> aggregateStream(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
19121912

1913+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
19131914
return aggregateStream(aggregation, getCollectionName(inputType), outputType,
19141915
queryOperations.createAggregation(aggregation, inputType).getAggregationOperationContext());
19151916
}
@@ -2056,8 +2057,8 @@ protected <O> AggregationResults<O> doAggregate(Aggregation aggregation, String
20562057
protected <O> Stream<O> aggregateStream(Aggregation aggregation, String collectionName, Class<O> outputType,
20572058
@Nullable AggregationOperationContext context) {
20582059

2059-
Assert.hasText(collectionName, "Collection name must not be null or empty");
20602060
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
2061+
Assert.hasText(collectionName, "Collection name must not be null or empty");
20612062
Assert.notNull(outputType, "Output type must not be null");
20622063
Assert.isTrue(!aggregation.getOptions().isExplain(), "Can't use explain option with streaming");
20632064

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,13 @@ public <T> Flux<T> findDistinct(Query query, String field, String collectionName
856856
public <O> Flux<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) {
857857

858858
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
859-
860859
return doAggregate(aggregation, inputCollectionName, aggregation.getInputType(), outputType);
861860
}
862861

863862
@Override
864863
public <O> Flux<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) {
864+
865+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
865866
return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType);
866867
}
867868

0 commit comments

Comments
 (0)