|
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.*;
|
|
40 | 41 | * @author Thomas Darimont
|
41 | 42 | * @author Sebastian Staudt
|
42 | 43 | * @author Jens Schauder
|
| 44 | + * @author Mark Paluch |
43 | 45 | */
|
44 | 46 | @SuppressWarnings("serial")
|
45 | 47 | @RunWith(MockitoJUnitRunner.class)
|
@@ -142,6 +144,36 @@ public void complexSpecificationsShouldBeSerializable() {
|
142 | 144 | assertThat(transferredSpecification).isNotNull();
|
143 | 145 | }
|
144 | 146 |
|
| 147 | + @Test // #2146 |
| 148 | + public void andCombinesSpecificationsInOrder() { |
| 149 | + |
| 150 | + Predicate firstPredicate = mock(Predicate.class); |
| 151 | + Predicate secondPredicate = mock(Predicate.class); |
| 152 | + |
| 153 | + Specification<Object> first = ((root1, query1, criteriaBuilder) -> firstPredicate); |
| 154 | + |
| 155 | + Specification<Object> second = ((root1, query1, criteriaBuilder) -> secondPredicate); |
| 156 | + |
| 157 | + first.and(second).toPredicate(root, query, builder); |
| 158 | + |
| 159 | + verify(builder).and(firstPredicate, secondPredicate); |
| 160 | + } |
| 161 | + |
| 162 | + @Test // #2146 |
| 163 | + void orCombinesSpecificationsInOrder() { |
| 164 | + |
| 165 | + Predicate firstPredicate = mock(Predicate.class); |
| 166 | + Predicate secondPredicate = mock(Predicate.class); |
| 167 | + |
| 168 | + Specification<Object> first = ((root1, query1, criteriaBuilder) -> firstPredicate); |
| 169 | + |
| 170 | + Specification<Object> second = ((root1, query1, criteriaBuilder) -> secondPredicate); |
| 171 | + |
| 172 | + first.or(second).toPredicate(root, query, builder); |
| 173 | + |
| 174 | + verify(builder).or(firstPredicate, secondPredicate); |
| 175 | + } |
| 176 | + |
145 | 177 | public class SerializableSpecification implements Serializable, Specification<Object> {
|
146 | 178 |
|
147 | 179 | @Override
|
|
0 commit comments