SchemaNegotiator { public static void negotiate(Object parent, Object child) { if (parent instanceof UsesExpectedSchema && child instanceof DeclaresExpectingSchema) { ((UsesExpectedSchema)parent).receiveExpectedSchema( ((DeclaresExpectingSchema)child).getExpectingSchema()); } if (child instanceof UsesProvidedSchema && parent instanceof DeclaresProvidingSchema) { ((UsesProvidedSchema)child).receiveProvidedSchema( ((DeclaresProvidingSchema)parent).getProvidingSchema()); } }  static void negotiate(Object parent, Object child);  }
@Test public void testParentUsesExpected() { UsesExpectedSchema parent = new UsesExpectedSchema() { private Boolean received = false; @Override public void receiveExpectedSchema(StructType expectedSchema) { if (expectedSchema.equals(SchemaUtils.binaryValueSchema())) { received = true; } } @Override public String toString() { return received.toString(); } }; DeclaresExpectingSchema child = new DeclaresExpectingSchema() { @Override public StructType getExpectingSchema() { return SchemaUtils.binaryValueSchema(); } }; SchemaNegotiator.negotiate(parent, child); assertTrue(Boolean.valueOf(parent.toString())); }
@Test public void testChildUsesProvided() { DeclaresProvidingSchema parent = new DeclaresProvidingSchema() { @Override public StructType getProvidingSchema() { return SchemaUtils.binaryValueSchema(); } }; UsesProvidedSchema child = new UsesProvidedSchema() { private Boolean received = false; @Override public void receiveProvidedSchema(StructType providedSchema) { if (providedSchema.equals(SchemaUtils.binaryValueSchema())) { received = true; } } @Override public String toString() { return received.toString(); } }; SchemaNegotiator.negotiate(parent, child); assertTrue(Boolean.valueOf(child.toString())); }
@Test public void testNeitherImplement() { String hello = "hello"; String world = "world"; SchemaNegotiator.negotiate(hello, world); }