Fix NPE in MongoItemReader when sorting is not specified through the builder
Resolves #4082
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2020 the original author or authors.
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -284,7 +284,7 @@ public class MongoItemReaderBuilder<T> {
|
||||
Assert.notNull(this.targetType, "targetType is required.");
|
||||
Assert.state(StringUtils.hasText(this.jsonQuery) || this.query != null, "A query is required");
|
||||
|
||||
if(StringUtils.hasText(this.jsonQuery)) {
|
||||
if (StringUtils.hasText(this.jsonQuery) || this.query != null) {
|
||||
Assert.notNull(this.sorts, "sorts map is required.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2020 the original author or authors.
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,11 +37,14 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.where;
|
||||
import static org.springframework.data.mongodb.core.query.Query.query;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
* @author Drummond Dawson
|
||||
* @author Parikshit Dutta
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class MongoItemReaderBuilderTests {
|
||||
@Mock
|
||||
@@ -209,7 +212,7 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullSorts() {
|
||||
public void testNullSortsWithQueryString() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().template(this.template)
|
||||
.targetType(String.class)
|
||||
.jsonQuery("{ }")
|
||||
@@ -217,6 +220,15 @@ public class MongoItemReaderBuilderTests {
|
||||
.pageSize(50), "sorts map is required.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullSortsWithQuery() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().template(this.template)
|
||||
.targetType(String.class)
|
||||
.query(query(where("_id").is("10")))
|
||||
.name("mongoReaderTest")
|
||||
.pageSize(50), "sorts map is required.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullName() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().template(this.template)
|
||||
|
||||
Reference in New Issue
Block a user