@Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("Fields:");
    builder.append(System.lineSeparator());
    for (Field field : fields) {
      builder.append(field);
      builder.append(System.lineSeparator());
    }
    builder.append("Encoding positions:");
    builder.append(System.lineSeparator());
    builder.append(encodingPositions);
    builder.append(System.lineSeparator());
    builder.append("Options:");
    builder.append(options);
    builder.append("UUID: " + uuid);
    return builder.toString();
  }
@Test
  public void testSortedMethodIncludesAllSchemaFields() {
    // This test is most likely to break when new Schema object attributes are added. It is designed
    // this way to make sure that the Schema::sorted() method is updated to return a full sorted
    // copy.

    // Schema object attributes that are accounted for in Schema::sorted().
    // Note: Only the appropriate ones are copied over.
    List<String> attributesAccountedForInSorted =
        Arrays.asList(
            "fieldIndices",
            "encodingPositions",
            "encodingPositionsOverridden",
            "fields",
            "hashCode",
            "uuid",
            "options");

    // Current attributes in Schema object.
    List<String> currentAttributes =
        Arrays.stream(Schema.class.getDeclaredFields())
            .filter(field -> !field.isSynthetic())
            .map(java.lang.reflect.Field::getName)
            .collect(Collectors.toList());

    List<String> differences = new ArrayList<>(currentAttributes);
    differences.removeAll(attributesAccountedForInSorted);

    assertEquals(
        String.format(
            "Detected attributes %s in Schema object that are not accounted for in Schema::sorted(). "
                + "If appropriate, sorted() should copy over these attributes as well. Either way, update this test after checking.",
            differences.toString()),
        currentAttributes,
        attributesAccountedForInSorted);
  }