DefaultOffsetParameterResolver implements OffsetParameterResolver { @Override public Integer getOffset(final Offset offsetAnnotation, final Field field, final HttpServletRequest httpRequest) { Offset annotation = offsetAnnotation; if (annotation == null) { annotation = field.getAnnotation(Offset.class); } String value = httpRequest.getParameter(annotation.value()); if (value == null) { value = annotation.defaultValue(); } if (value == null && annotation.required()) { throw new IllegalStateException("Missing parameter '" + annotation.value() + "' of type [" + field.getDeclaringClass().getName() + "]"); } return Integer.valueOf(value); }  @Override Integer getOffset(final Offset offsetAnnotation, final Field field, final HttpServletRequest httpRequest);  }
@Test public void testGetOffset() throws Exception { Offset annotation = null; PagedRequest<PersonResource> request = new PagedRequest<>(); Integer expected = 10; when(httpRequest.getParameter(anyString())).thenReturn(String.valueOf(expected)); Integer actual = unit.getOffset(annotation, request.getClass().getDeclaredField("offset"), httpRequest); verify(httpRequest).getParameter("offset"); assertEquals(expected, actual); }
@Test public void testGetOffsetWithNullValue() throws Exception { Offset annotation = null; PagedRequest<PersonResource> request = new PagedRequest<>(); Integer expected = 0; Integer actual = unit.getOffset(annotation, request.getClass().getDeclaredField("offset"), httpRequest); verify(httpRequest).getParameter("offset"); assertEquals(expected, actual); }