@Test
public void testVisit() throws IOException {

  Schema recSchema = new Schema.Parser().parse(SCHEMA);
  Schemas.visit(recSchema, new PrintingVisitor());
  String schemaStr = Resources.toString(Resources.getResource("SchemaBuilder.avsc"), StandardCharsets.US_ASCII);
  Schema schema = new Schema.Parser().parse(schemaStr);
  Map<String, Schema> schemas = Schemas.visit(schema, new SchemasWithClasses());
  Assert.assertThat(schemas, Matchers.hasValue(schema));
  Schema trimmed = Schemas.visit(recSchema, new CloningVisitor(recSchema));
  Assert.assertNull(trimmed.getDoc());
  Assert.assertNotNull(recSchema.getDoc());
  SchemaCompatibility.SchemaCompatibilityType compat
          = SchemaCompatibility.checkReaderWriterCompatibility(trimmed, recSchema).getType();
  Assert.assertEquals(SchemaCompatibility.SchemaCompatibilityType.COMPATIBLE, compat);
  compat = SchemaCompatibility.checkReaderWriterCompatibility(recSchema, trimmed).getType();
  Assert.assertEquals(SchemaCompatibility.SchemaCompatibilityType.COMPATIBLE, compat);
  Schema unmodifyable = Schemas.visit(recSchema, new ImmutableCloningVisitor(recSchema, false));
  Assert.assertNotNull(unmodifyable.getDoc());
  compat
          = SchemaCompatibility.checkReaderWriterCompatibility(unmodifyable, recSchema).getType();
  Assert.assertEquals(SchemaCompatibility.SchemaCompatibilityType.COMPATIBLE, compat);
  compat = SchemaCompatibility.checkReaderWriterCompatibility(recSchema, unmodifyable).getType();
  Assert.assertEquals(SchemaCompatibility.SchemaCompatibilityType.COMPATIBLE, compat);
  Schema schema1 = unmodifyable.getField("subNodes").schema().getElementType().getField("node").schema();
  try {
    schema1.addAlias("yahooo");
    Assert.fail();
  } catch (UnsupportedOperationException ex) {
  }
  try {
    schema1.setFields(Collections.EMPTY_LIST);
    Assert.fail();
  } catch (UnsupportedOperationException ex) {
  }
}