@@ -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