Polishing.
Reformat code. Refine tests. See #3849 Original pull request: #3856
This commit is contained in:
@@ -56,11 +56,9 @@ public interface Specification<T> extends Serializable {
|
||||
return spec == null //
|
||||
? (root, query, builder) -> null //
|
||||
: (root, query, builder) -> {
|
||||
|
||||
Predicate predicate = spec.toPredicate(root, query, builder);
|
||||
if(predicate != null) {
|
||||
return builder.not(predicate);
|
||||
}
|
||||
return builder.disjunction();
|
||||
return predicate != null ? builder.not(predicate) : builder.disjunction();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,6 @@ class SpecificationUnitTests implements Serializable {
|
||||
Predicate secondPredicate = mock(Predicate.class);
|
||||
|
||||
Specification<Object> first = ((root1, query1, criteriaBuilder) -> firstPredicate);
|
||||
|
||||
Specification<Object> second = ((root1, query1, criteriaBuilder) -> secondPredicate);
|
||||
|
||||
first.or(second).toPredicate(root, query, builder);
|
||||
@@ -214,14 +213,14 @@ class SpecificationUnitTests implements Serializable {
|
||||
verify(builder).or(firstPredicate, secondPredicate);
|
||||
}
|
||||
|
||||
@Test // #3849
|
||||
@Test // GH-3849
|
||||
void notWithNullPredicate() {
|
||||
Specification<Object> spec = (r, q, cb) -> null;
|
||||
|
||||
Specification<Object> notSpec = Specification.not(spec);
|
||||
when(builder.disjunction()).thenReturn(mock(Predicate.class));
|
||||
|
||||
notSpec.toPredicate(root, query, builder);
|
||||
|
||||
Specification<Object> notSpec = Specification.not((r, q, cb) -> null);
|
||||
|
||||
assertThat(notSpec.toPredicate(root, query, builder)).isNotNull();
|
||||
verify(builder).disjunction();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user