public void testFromXContent() throws IOException {
    SearchSortValues sortValues = createTestItem();
    XContentType xcontentType = randomFrom(XContentType.values());
    XContentBuilder builder = XContentFactory.contentBuilder(xcontentType);
    if (randomBoolean()) {
      builder.prettyPrint();
    }
    builder
        .startObject(); // we need to wrap xContent output in proper object to create a parser for
    // it
    builder = sortValues.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.endObject();

    XContentParser parser = createParser(builder);
    parser
        .nextToken(); // skip to the elements field name token, fromXContent advances from there if
    // called from ourside
    parser.nextToken();
    if (sortValues.sortValues().length > 0) {
      SearchSortValues parsed = SearchSortValues.fromXContent(parser);
      assertToXContentEquivalent(
          builder.bytes(), toXContent(parsed, xcontentType, true), xcontentType);
      parser.nextToken();
    }
    assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
    assertNull(parser.nextToken());
  }
 private static SearchSortValues mutate(SearchSortValues original) {
   Object[] sortValues = original.sortValues();
   if (sortValues.length == 0) {
     return new SearchSortValues(new Object[] {1});
   }
   return new SearchSortValues(Arrays.copyOf(sortValues, sortValues.length + 1));
 }
 private static SearchSortValues copy(SearchSortValues original) {
   return new SearchSortValues(Arrays.copyOf(original.sortValues(), original.sortValues().length));
 }