Skip to content

Commit a2c27c6

Browse files
committed
DATAJPA-1064 - Fixed spelling of Querydsl test.
Moved to new Pageable and Sort factory methods.
1 parent 6ad95ae commit a2c27c6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/test/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepositoryTests.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
@RunWith(SpringJUnit4ClassRunner.class)
5959
@ContextConfiguration({ "classpath:infrastructure.xml" })
6060
@Transactional
61-
public class QueryDslJpaRepositoryTests {
61+
public class QuerydslJpaRepositoryTests {
6262

6363
@PersistenceContext EntityManager em;
6464

@@ -111,12 +111,12 @@ public void considersSortingProvidedThroughPageable() {
111111

112112
Predicate lastnameContainsE = user.lastname.contains("e");
113113

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"));
115115

116116
assertThat(result.getContent(), hasSize(1));
117117
assertThat(result.getContent().get(0), is(carter));
118118

119-
result = repository.findAll(lastnameContainsE, new PageRequest(0, 2, Direction.DESC, "lastname"));
119+
result = repository.findAll(lastnameContainsE, PageRequest.of(0, 2, Direction.DESC, "lastname"));
120120

121121
assertThat(result.getContent(), hasSize(2));
122122
assertThat(result.getContent().get(0), is(oliver));
@@ -126,9 +126,9 @@ public void considersSortingProvidedThroughPageable() {
126126
@Test // DATAJPA-296
127127
public void appliesIgnoreCaseOrdering() {
128128

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"));
130130

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));
132132

133133
assertThat(result.getContent(), hasSize(2));
134134
assertThat(result.getContent().get(0), is(dave));
@@ -144,7 +144,7 @@ public void findBySpecificationWithSortByPluralAssociationPropertyInPageableShou
144144
QUser user = QUser.user;
145145

146146
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")));
148148

149149
assertThat(page.getContent(), hasSize(3));
150150
assertThat(page.getContent(), hasItems(oliver, dave, carter));
@@ -159,7 +159,7 @@ public void findBySpecificationWithSortBySingularAssociationPropertyInPageableSh
159159
QUser user = QUser.user;
160160

161161
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")));
163163

164164
assertThat(page.getContent(), hasSize(3));
165165
assertThat(page.getContent(), hasItems(dave, oliver, carter));
@@ -171,7 +171,7 @@ public void findBySpecificationWithSortBySingularPropertyInPageableShouldUseSort
171171
QUser user = QUser.user;
172172

173173
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")));
175175

176176
assertThat(page.getContent(), hasSize(3));
177177
assertThat(page.getContent(), hasItems(carter, dave, oliver));
@@ -183,7 +183,7 @@ public void findBySpecificationWithSortByOrderIgnoreCaseBySingularPropertyInPage
183183
QUser user = QUser.user;
184184

185185
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())));
187187

188188
assertThat(page.getContent(), hasSize(3));
189189
assertThat(page.getContent(), hasItems(carter, dave, oliver));
@@ -197,7 +197,7 @@ public void findBySpecificationWithSortByNestedEmbeddedPropertyInPageableShouldU
197197
QUser user = QUser.user;
198198

199199
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")));
201201

202202
assertThat(page.getContent(), hasSize(3));
203203
assertThat(page.getContent(), hasItems(dave, carter, oliver));
@@ -257,7 +257,7 @@ public void sortByNestedAssociationPropertyWithSpecificationAndSortInPageable()
257257
oliver.setManager(dave);
258258
dave.getRoles().add(adminRole);
259259

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")));
261261

262262
assertThat(page.getContent(), hasSize(3));
263263
assertThat(page.getContent().get(0), is(dave));
@@ -300,7 +300,7 @@ public void shouldSupportExistsWithPredicate() throws Exception {
300300
@Test // DATAJPA-679
301301
public void shouldSupportFindAllWithPredicateAndSort() {
302302

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"));
304304

305305
assertThat(users, hasSize(3));
306306
assertThat(users.get(0).getFirstname(), is(carter.getFirstname()));
@@ -309,30 +309,30 @@ public void shouldSupportFindAllWithPredicateAndSort() {
309309
}
310310

311311
@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));
314314
}
315315

316316
@Test // DATAJPA-912
317317
public void pageableQueryReportsTotalFromResult() {
318318

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));
320320
assertThat(firstPage.getContent(), hasSize(3));
321321
assertThat(firstPage.getTotalElements(), is(3L));
322322

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));
324324
assertThat(secondPage.getContent(), hasSize(1));
325325
assertThat(secondPage.getTotalElements(), is(3L));
326326
}
327327

328328
@Test // DATAJPA-912
329329
public void pageableQueryReportsTotalFromCount() {
330330

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));
332332
assertThat(firstPage.getContent(), hasSize(3));
333333
assertThat(firstPage.getTotalElements(), is(3L));
334334

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));
336336
assertThat(secondPage.getContent(), hasSize(0));
337337
assertThat(secondPage.getTotalElements(), is(3L));
338338
}

0 commit comments

Comments
 (0)