58
58
@ RunWith (SpringJUnit4ClassRunner .class )
59
59
@ ContextConfiguration ({ "classpath:infrastructure.xml" })
60
60
@ Transactional
61
- public class QueryDslJpaRepositoryTests {
61
+ public class QuerydslJpaRepositoryTests {
62
62
63
63
@ PersistenceContext EntityManager em ;
64
64
@@ -111,12 +111,12 @@ public void considersSortingProvidedThroughPageable() {
111
111
112
112
Predicate lastnameContainsE = user .lastname .contains ("e" );
113
113
114
- Page <User > result = repository .findAll (lastnameContainsE , new PageRequest (0 , 1 , Direction .ASC , "lastname" ));
114
+ Page <User > result = repository .findAll (lastnameContainsE , PageRequest . of (0 , 1 , Direction .ASC , "lastname" ));
115
115
116
116
assertThat (result .getContent (), hasSize (1 ));
117
117
assertThat (result .getContent ().get (0 ), is (carter ));
118
118
119
- result = repository .findAll (lastnameContainsE , new PageRequest (0 , 2 , Direction .DESC , "lastname" ));
119
+ result = repository .findAll (lastnameContainsE , PageRequest . of (0 , 2 , Direction .DESC , "lastname" ));
120
120
121
121
assertThat (result .getContent (), hasSize (2 ));
122
122
assertThat (result .getContent ().get (0 ), is (oliver ));
@@ -126,9 +126,9 @@ public void considersSortingProvidedThroughPageable() {
126
126
@ Test // DATAJPA-296
127
127
public void appliesIgnoreCaseOrdering () {
128
128
129
- Sort sort = new Sort (new Order (Direction .DESC , "lastname" ).ignoreCase (), new Order (Direction .ASC , "firstname" ));
129
+ Sort sort = Sort . by (new Order (Direction .DESC , "lastname" ).ignoreCase (), new Order (Direction .ASC , "firstname" ));
130
130
131
- Page <User > result = repository .findAll (user .lastname .contains ("e" ), new PageRequest (0 , 2 , sort ));
131
+ Page <User > result = repository .findAll (user .lastname .contains ("e" ), PageRequest . of (0 , 2 , sort ));
132
132
133
133
assertThat (result .getContent (), hasSize (2 ));
134
134
assertThat (result .getContent ().get (0 ), is (dave ));
@@ -144,7 +144,7 @@ public void findBySpecificationWithSortByPluralAssociationPropertyInPageableShou
144
144
QUser user = QUser .user ;
145
145
146
146
Page <User > page = repository .findAll (user .firstname .isNotNull (),
147
- new PageRequest (0 , 10 , new Sort (Sort .Direction .ASC , "colleagues.firstname" )));
147
+ PageRequest . of (0 , 10 , Sort . by (Sort .Direction .ASC , "colleagues.firstname" )));
148
148
149
149
assertThat (page .getContent (), hasSize (3 ));
150
150
assertThat (page .getContent (), hasItems (oliver , dave , carter ));
@@ -159,7 +159,7 @@ public void findBySpecificationWithSortBySingularAssociationPropertyInPageableSh
159
159
QUser user = QUser .user ;
160
160
161
161
Page <User > page = repository .findAll (user .firstname .isNotNull (),
162
- new PageRequest (0 , 10 , new Sort (Sort .Direction .ASC , "manager.firstname" )));
162
+ PageRequest . of (0 , 10 , Sort . by (Sort .Direction .ASC , "manager.firstname" )));
163
163
164
164
assertThat (page .getContent (), hasSize (3 ));
165
165
assertThat (page .getContent (), hasItems (dave , oliver , carter ));
@@ -171,7 +171,7 @@ public void findBySpecificationWithSortBySingularPropertyInPageableShouldUseSort
171
171
QUser user = QUser .user ;
172
172
173
173
Page <User > page = repository .findAll (user .firstname .isNotNull (),
174
- new PageRequest (0 , 10 , new Sort (Sort .Direction .ASC , "firstname" )));
174
+ PageRequest . of (0 , 10 , Sort . by (Sort .Direction .ASC , "firstname" )));
175
175
176
176
assertThat (page .getContent (), hasSize (3 ));
177
177
assertThat (page .getContent (), hasItems (carter , dave , oliver ));
@@ -183,7 +183,7 @@ public void findBySpecificationWithSortByOrderIgnoreCaseBySingularPropertyInPage
183
183
QUser user = QUser .user ;
184
184
185
185
Page <User > page = repository .findAll (user .firstname .isNotNull (),
186
- new PageRequest (0 , 10 , new Sort (new Order (Sort .Direction .ASC , "firstname" ).ignoreCase ())));
186
+ PageRequest . of (0 , 10 , Sort . by (new Order (Sort .Direction .ASC , "firstname" ).ignoreCase ())));
187
187
188
188
assertThat (page .getContent (), hasSize (3 ));
189
189
assertThat (page .getContent (), hasItems (carter , dave , oliver ));
@@ -197,7 +197,7 @@ public void findBySpecificationWithSortByNestedEmbeddedPropertyInPageableShouldU
197
197
QUser user = QUser .user ;
198
198
199
199
Page <User > page = repository .findAll (user .firstname .isNotNull (),
200
- new PageRequest (0 , 10 , new Sort (Sort .Direction .ASC , "address.streetName" )));
200
+ PageRequest . of (0 , 10 , Sort . by (Sort .Direction .ASC , "address.streetName" )));
201
201
202
202
assertThat (page .getContent (), hasSize (3 ));
203
203
assertThat (page .getContent (), hasItems (dave , carter , oliver ));
@@ -257,7 +257,7 @@ public void sortByNestedAssociationPropertyWithSpecificationAndSortInPageable()
257
257
oliver .setManager (dave );
258
258
dave .getRoles ().add (adminRole );
259
259
260
- Page <User > page = repository .findAll (new PageRequest (0 , 10 , new Sort ( Sort . Direction .ASC , "manager.roles.name" )));
260
+ Page <User > page = repository .findAll (PageRequest . of (0 , 10 , Sort . by ( Direction .ASC , "manager.roles.name" )));
261
261
262
262
assertThat (page .getContent (), hasSize (3 ));
263
263
assertThat (page .getContent ().get (0 ), is (dave ));
@@ -300,7 +300,7 @@ public void shouldSupportExistsWithPredicate() throws Exception {
300
300
@ Test // DATAJPA-679
301
301
public void shouldSupportFindAllWithPredicateAndSort () {
302
302
303
- List <User > users = repository .findAll (user .dateOfBirth .isNull (), new Sort (Direction .ASC , "firstname" ));
303
+ List <User > users = repository .findAll (user .dateOfBirth .isNull (), Sort . by (Direction .ASC , "firstname" ));
304
304
305
305
assertThat (users , hasSize (3 ));
306
306
assertThat (users .get (0 ).getFirstname (), is (carter .getFirstname ()));
@@ -309,30 +309,30 @@ public void shouldSupportFindAllWithPredicateAndSort() {
309
309
}
310
310
311
311
@ Test // DATAJPA-585
312
- public void worksWithNullPageable () {
313
- assertThat (repository .findAll (user .dateOfBirth .isNull (), ( Pageable ) null ).getContent (), hasSize (3 ));
312
+ public void worksWithUnpagedPageable () {
313
+ assertThat (repository .findAll (user .dateOfBirth .isNull (), Pageable . unpaged () ).getContent (), hasSize (3 ));
314
314
}
315
315
316
316
@ Test // DATAJPA-912
317
317
public void pageableQueryReportsTotalFromResult () {
318
318
319
- Page <User > firstPage = repository .findAll (user .dateOfBirth .isNull (), new PageRequest (0 , 10 ));
319
+ Page <User > firstPage = repository .findAll (user .dateOfBirth .isNull (), PageRequest . of (0 , 10 ));
320
320
assertThat (firstPage .getContent (), hasSize (3 ));
321
321
assertThat (firstPage .getTotalElements (), is (3L ));
322
322
323
- Page <User > secondPage = repository .findAll (user .dateOfBirth .isNull (), new PageRequest (1 , 2 ));
323
+ Page <User > secondPage = repository .findAll (user .dateOfBirth .isNull (), PageRequest . of (1 , 2 ));
324
324
assertThat (secondPage .getContent (), hasSize (1 ));
325
325
assertThat (secondPage .getTotalElements (), is (3L ));
326
326
}
327
327
328
328
@ Test // DATAJPA-912
329
329
public void pageableQueryReportsTotalFromCount () {
330
330
331
- Page <User > firstPage = repository .findAll (user .dateOfBirth .isNull (), new PageRequest (0 , 3 ));
331
+ Page <User > firstPage = repository .findAll (user .dateOfBirth .isNull (), PageRequest . of (0 , 3 ));
332
332
assertThat (firstPage .getContent (), hasSize (3 ));
333
333
assertThat (firstPage .getTotalElements (), is (3L ));
334
334
335
- Page <User > secondPage = repository .findAll (user .dateOfBirth .isNull (), new PageRequest (10 , 10 ));
335
+ Page <User > secondPage = repository .findAll (user .dateOfBirth .isNull (), PageRequest . of (10 , 10 ));
336
336
assertThat (secondPage .getContent (), hasSize (0 ));
337
337
assertThat (secondPage .getTotalElements (), is (3L ));
338
338
}
0 commit comments