Refine QuerydslRepositoryInvokerAdapter nullability assertions.

QuerydslRepositoryInvokerAdapter now rejects null predicates to enforce nullability constraints.

Closes #1501
This commit is contained in:
Mark Paluch
2023-02-24 11:04:01 +01:00
parent 34f212ff61
commit 83655663ea
2 changed files with 11 additions and 2 deletions

View File

@@ -44,13 +44,14 @@ public class QuerydslRepositoryInvokerAdapter implements RepositoryInvoker {
*
* @param delegate must not be {@literal null}.
* @param executor must not be {@literal null}.
* @param predicate can be {@literal null}.
* @param predicate must not be {@literal null}.
*/
public QuerydslRepositoryInvokerAdapter(RepositoryInvoker delegate, QuerydslPredicateExecutor<Object> executor,
Predicate predicate) {
Assert.notNull(delegate, "Delegate RepositoryInvoker must not be null");
Assert.notNull(executor, "QuerydslPredicateExecutor must not be null");
Assert.notNull(predicate, "Predicate must not be null");
this.delegate = delegate;
this.executor = executor;

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.querydsl;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;
@@ -24,7 +25,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.support.RepositoryInvoker;
@@ -35,6 +35,7 @@ import com.querydsl.core.types.Predicate;
* Unit tests for {@link QuerydslRepositoryInvokerAdapter}.
*
* @author Oliver Gierke
* @author Mark Paluch
* @soundtrack Emilie Nicolas - Grown Up
*/
@ExtendWith(MockitoExtension.class)
@@ -51,6 +52,13 @@ class QuerydslRepositoryInvokerAdapterUnitTests {
this.adapter = new QuerydslRepositoryInvokerAdapter(delegate, executor, predicate);
}
@Test // GH-1501
void rejectsNullPredicate() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new QuerydslRepositoryInvokerAdapter(delegate, executor, null));
}
@Test // DATACMNS-669
void forwardsFindAllToExecutorWithPredicate() {