File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed
main/java/org/springframework/data/jpa/domain
test/java/org/springframework/data/jpa/domain Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,9 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
5757 return spec == null //
5858 ? (root , query , builder ) -> null //
5959 : (root , query , builder ) -> {
60+
6061 Predicate predicate = spec .toPredicate (root , query , builder );
61- if (predicate != null ) {
62- return builder .not (predicate );
63- }
64- return builder .disjunction ();
62+ return predicate != null ? builder .not (predicate ) : builder .disjunction ();
6563 };
6664 }
6765
Original file line number Diff line number Diff line change @@ -206,22 +206,21 @@ void orCombinesSpecificationsInOrder() {
206206 Predicate secondPredicate = mock (Predicate .class );
207207
208208 Specification <Object > first = ((root1 , query1 , criteriaBuilder ) -> firstPredicate );
209-
210209 Specification <Object > second = ((root1 , query1 , criteriaBuilder ) -> secondPredicate );
211210
212211 first .or (second ).toPredicate (root , query , builder );
213212
214213 verify (builder ).or (firstPredicate , secondPredicate );
215214 }
216215
217- @ Test // # 3849
216+ @ Test // GH- 3849
218217 void notWithNullPredicate () {
219- Specification <Object > spec = (r , q , cb ) -> null ;
220218
221- Specification <Object > notSpec = Specification .not (spec );
219+ when (builder .disjunction ()).thenReturn (mock (Predicate .class ));
220+
221+ Specification <Object > notSpec = Specification .not ((r , q , cb ) -> null );
222222
223- notSpec .toPredicate (root , query , builder );
224-
223+ assertThat (notSpec .toPredicate (root , query , builder )).isNotNull ();
225224 verify (builder ).disjunction ();
226225 }
227226
You can’t perform that action at this time.
0 commit comments