NestedFieldsContainerRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { UriInfo uriInfo = containerRequestContext.getUriInfo(); MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); String nestedFields = queryParameters.getFirst("nestedFields"); if (Validator.isNotNull(nestedFields)) { List<String> fieldNames = Arrays.asList( nestedFields.split("\\s*,\\s*")); NestedFieldsContextThreadLocal.setNestedFieldsContext( new NestedFieldsContext( fieldNames, JAXRSUtils.getCurrentMessage(), uriInfo.getPathParameters(), _getResourceVersion(uriInfo.getPathSegments()), queryParameters)); } }  @Override void filter(ContainerRequestContext containerRequestContext);  }
@Test public void testFilter() throws IOException { NestedFieldsContainerRequestFilter nestedFieldsContainerRequestFilter = new NestedFieldsContainerRequestFilter(); ContainerRequestContext containerRequestContext = Mockito.mock( ContainerRequestContext.class); UriInfo uriInfo = Mockito.mock(UriInfo.class); Mockito.when( containerRequestContext.getUriInfo() ).thenReturn( uriInfo ); List<PathSegment> pathSegments = new ArrayList<>(); pathSegments.add(new PathSegmentImpl("v1.0")); pathSegments.add(new PathSegmentImpl("products")); Mockito.when( uriInfo.getPathSegments() ).thenReturn( pathSegments ); MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>(); Mockito.when( uriInfo.getQueryParameters() ).thenReturn( queryParameters ); nestedFieldsContainerRequestFilter.filter(containerRequestContext); NestedFieldsContext nestedFieldsContext = NestedFieldsContextThreadLocal.getNestedFieldsContext(); Assert.assertNull(nestedFieldsContext); queryParameters.putSingle("nestedFields", "skus,productOptions"); nestedFieldsContainerRequestFilter.filter(containerRequestContext); nestedFieldsContext = NestedFieldsContextThreadLocal.getNestedFieldsContext(); List<String> fieldNames = nestedFieldsContext.getFieldNames(); Assert.assertEquals(fieldNames.toString(), 2, fieldNames.size()); }