NamedFieldTypeReference implements FieldTypeReference { @Override public FieldType resolve(final TableType tableType) { if (tableType == null) { throw new IllegalArgumentException(); } for (FieldType fieldType : tableType.getFields()) { if (fieldType.getName().equals(fieldName)) { return fieldType; } } return null; } NamedFieldTypeReference(final String fieldName); @Override FieldType resolve(final TableType tableType);  }
@Test public void resolve_should_returnExistingFieldByName() { final NamedFieldTypeReference reference = new NamedFieldTypeReference(NAMED_FIELD_STR); final FieldType fieldType = reference.resolve(tableType); assertThat(fieldType.getName(), is(NAMED_FIELD_STR)); }
@Test public void resolve_ofNonExistingField_should_returnNull() { final NamedFieldTypeReference reference = new NamedFieldTypeReference("NOT_EXISTING_FIELD"); assertThat(reference.resolve(tableType), nullValue()); }
@Test(expected = IllegalArgumentException.class) public void resolveOnNullTable_should_throw() { final NamedFieldTypeReference reference = new NamedFieldTypeReference(NAMED_FIELD_STR); final FieldType fieldType = reference.resolve(null); Assert.assertThat(fieldType, nullValue()); }