LogicalTypeValidatingVisitor implements Visitor<Void> { @Override public void onVisit(Schema schema, Collection<String> breadcrumb) { try { LogicalTypes.fromSchema(schema); } catch (Exception e) { String path = breadcrumb.stream().collect(joining("/", "/", "")); throw new IllegalArgumentException("Invalid logical type declared at " + path, e); } }  @Override void onVisit(Schema schema, Collection<String> breadcrumb); @Override void onVisit(Field field, Collection<String> breadcrumb); @Override Void getResult();  }
@Test(expected = IllegalArgumentException.class) public void invalidLogicalType() throws Exception { Schema schema = SchemaBuilder.builder().stringType(); schema.addProp(LogicalType.LOGICAL_TYPE_PROP, "date"); underTest.onVisit(schema, breadcrumb); }
@Test public void validLogicalType() throws Exception { Schema schema = SchemaBuilder.builder().intType(); schema.addProp(LogicalType.LOGICAL_TYPE_PROP, "date"); underTest.onVisit(schema, breadcrumb); }
@Test(expected = IllegalArgumentException.class) public void logicalTypeField() throws Exception { Field field = new Field("f", SchemaBuilder.builder().intType(), null, (String) null); field.addProp(LogicalType.LOGICAL_TYPE_PROP, "date"); underTest.onVisit(field, breadcrumb); }
@Test public void noLogicalTypeField() throws Exception { Field field = new Field("f", SchemaBuilder.builder().intType(), null, (String) null); underTest.onVisit(field, breadcrumb); }