@Test(expected = InvalidKeyPathException.class)
public void unionBranchIncompatible() throws InvalidKeyPathException {

  Path path = KeyPathParser.parse("$.a.c");
  Schema schema = SchemaBuilder
      .record("X")
      .fields()
      .name("a")
      .type(SchemaBuilder
          .unionOf()
          .type(SchemaBuilder.record("Z").fields().name("c").type(Schema.create(Type.STRING)).noDefault().endRecord())
          .and()
          .type(Schema.create(Type.INT))
          .endUnion())
      .noDefault()
      .endRecord();
  try {
    new KeyPathValidator(path, schema).validate();
  } catch (Exception e) {
    assertThat(e.getMessage(),
        is("Element '$.a(UnionIndex:1)' not a traversable type (found 'INT'), in path: $.a.c"));
    throw e;
  }
}