AssetQueryParameters { public SortOptions getSortOptions() throws InvalidParameterException { String sortByField = params.get(SORT_BY_PARAM); String sortOrderParam = params.get(SORT_ORDER_PARAM); SortOrder sortOrder; if (sortByField != null && sortByField.isEmpty()) { throw new InvalidParameterException(SORT_BY_PARAM + " must not be blank"); } if (sortOrderParam != null && sortByField == null) { throw new InvalidParameterException(SORT_ORDER_PARAM + " may only be provided if " + SORT_BY_PARAM + " is also provided"); } if (sortOrderParam == null) { sortOrder = SortOrder.ASCENDING; } else if (sortOrderParam.equalsIgnoreCase(SORT_BY_ASC)) { sortOrder = SortOrder.ASCENDING; } else if (sortOrderParam.equalsIgnoreCase(SORT_BY_DESC)) { sortOrder = SortOrder.DESCENDING; } else { throw new InvalidParameterException(SORT_ORDER_PARAM + " must be either \"" + SORT_BY_ASC + "\" or \"" + SORT_BY_DESC + "\""); } if (sortByField != null) { return new SortOptions(sortByField, sortOrder); } else { return null; } } private  AssetQueryParameters(Map<String, String> params); static AssetQueryParameters create(UriInfo uriInfo); Collection<AssetFilter> getFilters(); PaginationOptions getPagination(); String getSearchTerm(); String getFields(); SortOptions getSortOptions();  }
@Test public void testGetSortOptions() throws Exception { UriInfo uriInfo = new DummyUriInfo("http: AssetQueryParameters params = AssetQueryParameters.create(uriInfo); assertEquals(new SortOptions("foo", SortOrder.ASCENDING), params.getSortOptions()); uriInfo = new DummyUriInfo("http: params = AssetQueryParameters.create(uriInfo); assertEquals(new SortOptions("foo", SortOrder.DESCENDING), params.getSortOptions()); uriInfo = new DummyUriInfo("http: params = AssetQueryParameters.create(uriInfo); assertEquals(new SortOptions("foo", SortOrder.ASCENDING), params.getSortOptions()); params = AssetQueryParameters.create(ALL_PARAMS_URI); assertEquals(new SortOptions("x", SortOrder.ASCENDING), params.getSortOptions()); }