|
16 | 16 | package org.springframework.data.jpa.domain;
|
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.*;
|
| 19 | +import static org.mockito.Mockito.*; |
19 | 20 | import static org.springframework.data.jpa.domain.Specification.*;
|
20 | 21 | import static org.springframework.data.jpa.domain.Specification.not;
|
21 | 22 | import static org.springframework.util.SerializationUtils.*;
|
|
42 | 43 | * @author Thomas Darimont
|
43 | 44 | * @author Sebastian Staudt
|
44 | 45 | * @author Jens Schauder
|
| 46 | + * @author Mark Paluch |
45 | 47 | */
|
46 | 48 | @SuppressWarnings("serial")
|
47 | 49 | @ExtendWith(MockitoExtension.class)
|
@@ -145,6 +147,36 @@ void complexSpecificationsShouldBeSerializable() {
|
145 | 147 | assertThat(transferredSpecification).isNotNull();
|
146 | 148 | }
|
147 | 149 |
|
| 150 | + @Test // #2146 |
| 151 | + void andCombinesSpecificationsInOrder() { |
| 152 | + |
| 153 | + Predicate firstPredicate = mock(Predicate.class); |
| 154 | + Predicate secondPredicate = mock(Predicate.class); |
| 155 | + |
| 156 | + Specification<Object> first = ((root1, query1, criteriaBuilder) -> firstPredicate); |
| 157 | + |
| 158 | + Specification<Object> second = ((root1, query1, criteriaBuilder) -> secondPredicate); |
| 159 | + |
| 160 | + first.and(second).toPredicate(root, query, builder); |
| 161 | + |
| 162 | + verify(builder).and(firstPredicate, secondPredicate); |
| 163 | + } |
| 164 | + |
| 165 | + @Test // #2146 |
| 166 | + void orCombinesSpecificationsInOrder() { |
| 167 | + |
| 168 | + Predicate firstPredicate = mock(Predicate.class); |
| 169 | + Predicate secondPredicate = mock(Predicate.class); |
| 170 | + |
| 171 | + Specification<Object> first = ((root1, query1, criteriaBuilder) -> firstPredicate); |
| 172 | + |
| 173 | + Specification<Object> second = ((root1, query1, criteriaBuilder) -> secondPredicate); |
| 174 | + |
| 175 | + first.or(second).toPredicate(root, query, builder); |
| 176 | + |
| 177 | + verify(builder).or(firstPredicate, secondPredicate); |
| 178 | + } |
| 179 | + |
148 | 180 | static class SerializableSpecification implements Serializable, Specification<Object> {
|
149 | 181 |
|
150 | 182 | @Override
|
|
0 commit comments