PageablePageParameterExtractor implements PageParameterExtractor { @Override public Page extract(Invocation invocation) { if (invocation == null) { throw new InvalidArgumentException("Invocation cannot be null"); } final Object value = invocation.getArguments()[index]; if (value == null) { throw new InvalidArgumentException("Page value should not be empty"); } if (value instanceof Pageable) { final Pageable pageable = (Pageable) value; return new ImmutablePage(pageable.getPageSize(), pageable.getPageNumber()); } throw new InvalidArgumentException("No valid value was passed to deduce the paging description from"); } PageablePageParameterExtractor(int index); @Override Page extract(Invocation invocation);  }
@Test(expectedExceptions = InvalidArgumentException.class) public void testNullInvocation() { final PageablePageParameterExtractor extractor = new PageablePageParameterExtractor(0); extractor.extract(null); }
@Test(expectedExceptions = InvalidArgumentException.class) public void testPassingNullValue() { final PageablePageParameterExtractor extractor = new PageablePageParameterExtractor(0); extractor.extract(new ImmutableInvocation(null, new Object[]{null})); }
@Test(expectedExceptions = InvalidArgumentException.class) public void testPassingWrongType() { final PageablePageParameterExtractor extractor = new PageablePageParameterExtractor(0); extractor.extract(new ImmutableInvocation(null, new Object[]{new Object()})); }
@Test public void testPassingPageRequest() { final PageablePageParameterExtractor extractor = new PageablePageParameterExtractor(0); final PageRequest pageRequest = PageRequest.of(3, 7); final Page extracted = extractor.extract(new ImmutableInvocation(null, new Object[]{pageRequest})); assertThat(extracted, is(notNullValue())); assertThat(extracted.getPageNumber(), is(pageRequest.getPageNumber())); assertThat(extracted.getPageSize(), is(pageRequest.getPageSize())); }