Skip to content

Commit 8db7458

Browse files
committed
Polishing.
Reformat code. Refine tests. See #3849 Original pull request: #3856
1 parent 2f47f22 commit 8db7458

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java

+2-4
Original file line numberDiff line numberDiff 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

spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/SpecificationUnitTests.java

+5-6
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)