TupleKey { public TupleKeyValue of(T value) { if (value == null) throw new IllegalArgumentException("value must not be null"); return new TupleKeyValue(this, value); } TupleKey(TupleSchema schema, String name, int index); TupleKeyValue of(T value); String getName(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void buildWithKeyValues() { Tuple person = personSchema.make( name.of("Dominic"), age.of(41), address.of(addressSchema.make( addressLines.of(asList("23 Acacia Avenue", "Sunderland")), postcode.of("VB6 5UX")))); assertThat(person, equalTo( personSchema.makeWith("Dominic", 41, addressSchema.makeWith(asList("23 Acacia Avenue", "Sunderland"), "VB6 5UX")) )); }
@Test public void keyValuesAreRefusedIfAnyBelongsToDifferentSchema() { try { personSchema.make( name.of("Dominic"), postcode.of("foo")); fail("Incorrect keys should not be accepted"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), equalTo("" + "Keys [TupleKey<name>,TupleKey<postcode>] " + "do not all belong to schema " + personSchema)); } }
@Test public void keyValuesAreRefusedIfAnyAreMissing() { try { personSchema.make( name.of("Dominic"), age.of(31)); fail("Incomplete keys should not be accepted"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), equalTo("" + "Not all slots in " + personSchema + " filled by provided keys " + "[TupleKey<name>,TupleKey<age>]")); } }