DirectSortParameterExtractor extends AbstractSortParameterExtractor { @Override public Sort 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 org.springframework.data.domain.Sort) { return getSort((org.springframework.data.domain.Sort) value); } throw new InvalidArgumentException("No valid value was passed to deduce the paging description from"); } DirectSortParameterExtractor(int index); @Override Sort extract(Invocation invocation);  }
@Test(expectedExceptions = InvalidArgumentException.class) public void testNullInvocation() { final DirectSortParameterExtractor extractor = new DirectSortParameterExtractor(0); extractor.extract(null); }
@Test(expectedExceptions = InvalidArgumentException.class) public void testPassingNullSort() { final DirectSortParameterExtractor extractor = new DirectSortParameterExtractor(0); extractor.extract(new ImmutableInvocation(null, new Object[]{null})); }
@Test(expectedExceptions = InvalidArgumentException.class) public void testPassingWrongTypeOfArgument() { final DirectSortParameterExtractor extractor = new DirectSortParameterExtractor(0); extractor.extract(new ImmutableInvocation(null, new Object[]{new Object()})); }
@Test public void testPassingSortValue() { final DirectSortParameterExtractor extractor = new DirectSortParameterExtractor(0); final com.mmnaseri.utils.spring.data.query.Sort extracted = extractor.extract( new ImmutableInvocation(null, new Object[]{Sort.by("a", "b")})); assertThat(extracted, is(notNullValue())); assertThat(extracted.getOrders(), hasSize(2)); assertThat(extracted.getOrders().get(0).getProperty(), is("a")); assertThat(extracted.getOrders().get(0).getDirection(), is(SortDirection.ASCENDING)); assertThat(extracted.getOrders().get(0).getNullHandling(), is(NullHandling.DEFAULT)); assertThat(extracted.getOrders().get(1).getProperty(), is("b")); assertThat(extracted.getOrders().get(1).getDirection(), is(SortDirection.ASCENDING)); assertThat(extracted.getOrders().get(1).getNullHandling(), is(NullHandling.DEFAULT)); }