File tree 2 files changed +7
-10
lines changed
main/java/org/springframework/data/jpa/domain
test/java/org/springframework/data/jpa/domain
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) {
57
57
return spec == null //
58
58
? (root , query , builder ) -> null //
59
59
: (root , query , builder ) -> {
60
+
60
61
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 ();
65
63
};
66
64
}
67
65
Original file line number Diff line number Diff line change @@ -206,22 +206,21 @@ void orCombinesSpecificationsInOrder() {
206
206
Predicate secondPredicate = mock (Predicate .class );
207
207
208
208
Specification <Object > first = ((root1 , query1 , criteriaBuilder ) -> firstPredicate );
209
-
210
209
Specification <Object > second = ((root1 , query1 , criteriaBuilder ) -> secondPredicate );
211
210
212
211
first .or (second ).toPredicate (root , query , builder );
213
212
214
213
verify (builder ).or (firstPredicate , secondPredicate );
215
214
}
216
215
217
- @ Test // # 3849
216
+ @ Test // GH- 3849
218
217
void notWithNullPredicate () {
219
- Specification <Object > spec = (r , q , cb ) -> null ;
220
218
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 );
222
222
223
- notSpec .toPredicate (root , query , builder );
224
-
223
+ assertThat (notSpec .toPredicate (root , query , builder )).isNotNull ();
225
224
verify (builder ).disjunction ();
226
225
}
227
226
You can’t perform that action at this time.
0 commit comments