Skip to content

Commit f07d688

Browse files
authored
Merge pull request #37 from domaframework/spring-boot-2.2
Fix compile error when use Spring Boot 2.2
2 parents c3033bb + 5aa3ae0 commit f07d688

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

doma-spring-boot-core/src/test/java/org/seasar/doma/boot/PageablesTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,33 @@ public class PageablesTest {
2727

2828
@Test
2929
public void testToSelectOptions() throws Exception {
30-
SelectOptions options = Pageables.toSelectOptions(new PageRequest(0, 10));
30+
SelectOptions options = Pageables.toSelectOptions(pageRequest(0, 10));
3131
assertThat(SelectOptionsAccessor.getOffset(options), is(0L));
3232
assertThat(SelectOptionsAccessor.getLimit(options), is(10L));
3333
}
3434

3535
@Test
3636
public void testToSelectOptions2() throws Exception {
37-
SelectOptions options = Pageables.toSelectOptions(new PageRequest(2, 10));
37+
SelectOptions options = Pageables.toSelectOptions(pageRequest(2, 10));
3838
assertThat(SelectOptionsAccessor.getOffset(options), is(20L));
3939
assertThat(SelectOptionsAccessor.getLimit(options), is(10L));
4040
}
4141

4242
@Test
4343
public void testToSelectOptions3() throws Exception {
44-
SelectOptions options = Pageables.toSelectOptions(new PageRequest(2, 5));
44+
SelectOptions options = Pageables.toSelectOptions(pageRequest(2, 5));
4545
assertThat(SelectOptionsAccessor.getOffset(options), is(10L));
4646
assertThat(SelectOptionsAccessor.getLimit(options), is(5L));
4747
}
48+
49+
private static PageRequest pageRequest(int page, int size) throws Exception {
50+
try {
51+
// Try PageRequest.of(int, int) added since Spring Data Commons 2.0
52+
return (PageRequest) PageRequest.class.getMethod("of", int.class, int.class).invoke(null, page, size);
53+
} catch (NoSuchMethodException e) {
54+
// If 'of' method is missing (In other words, Spring Data Commons version is less than 2.0),
55+
// then it use constructor with two int arguments.
56+
return PageRequest.class.getConstructor(int.class, int.class).newInstance(page, size);
57+
}
58+
}
4859
}

0 commit comments

Comments
 (0)