static void validateCsvFormatWithSchema(CSVFormat format, Schema schema) {
    List<String> header = Arrays.asList(format.getHeader());
    for (Schema.Field field : schema.getFields()) {
      String fieldName = field.getName();
      if (!field.getType().getNullable()) {
        checkArgument(
            header.contains(fieldName),
            "Illegal %s: required %s field '%s' not found in header",
            CSVFormat.class,
            Schema.class.getTypeName(),
            fieldName);
      }
    }
  }
@Test
  public void givenRequiredSchemaFieldNotPresentInHeader_throwsException() {
    CSVFormat format = csvFormat().withHeader("foo", "bar");
    Schema schema =
        Schema.of(
            Schema.Field.of("foo", Schema.FieldType.STRING),
            Schema.Field.of("bar", Schema.FieldType.STRING),
            Schema.Field.of("baz", Schema.FieldType.STRING));
    String gotMessage =
        assertThrows(
                IllegalArgumentException.class,
                () -> CsvIOParseHelpers.validateCsvFormatWithSchema(format, schema))
            .getMessage();
    assertEquals(
        "Illegal class org.apache.commons.csv.CSVFormat: required org.apache.beam.sdk.schemas.Schema field 'baz' not found in header",
        gotMessage);
  }