### Question:
CSVFileSchemaParser implements FileSchemaParser { public void setHeaderRow(boolean headerRow) { this.headerRow = headerRow; }  @Override Schema parse(InputStream is, Charset charset, TableSchemaType target); TableSettings parseTableSettings(InputStream is, Charset charset, TableSchemaType target); boolean tableSettingsRequireFileInspection(); @Override TableSettings deriveTableSettings(TableSchemaType target); String deriveHiveRecordFormat(); void setAutoDetect(boolean autoDetect); void setHeaderRow(boolean headerRow); void setNumRowsToSample(int numRowsToSample); String getSeparatorChar(); void setSeparatorChar(String separatorChar); String getQuoteChar(); void setQuoteChar(String quoteChar); String getEscapeChar(); void setEscapeChar(String escapeChar);  }### Answer:
@Test public void testNoHeader() throws Exception { parser.setHeaderRow(false); try (InputStream is = toInputStream("r1v1,r1v2,r1v3\nr2v1,r2v2,r2v3\n")) { HiveTableSchema schema = toHiveTableSchema(is); List<? extends Field> fields = schema.getFields(); assertTrue(fields.size() == 3); IntStream.range(0, fields.size()).forEach(idx -> { assertEquals(fields.get(idx).getName(), "Col_" + (idx + 1)); assertEquals(fields.get(idx).getSampleValues().size(), 1); }); } }
@Test public void testNoHeaderFirstRowDuplicateValues() throws Exception { parser.setHeaderRow(false); firstRowDuplicateValues(); }
@Test(expected = IllegalArgumentException.class) public void testHeaderFirstRowDuplicateValues() throws Exception { parser.setHeaderRow(true); firstRowDuplicateValues(); }
@Test public void testNoHeaderFirstRowNoDuplicateValues() throws Exception { parser.setHeaderRow(false); try (InputStream is = toInputStream("HEAD_1,HEAD_2,HEAD_3\nr2v1,r2v2,r2v3\n")) { HiveTableSchema schema = toHiveTableSchema(is); List<? extends Field> fields = schema.getFields(); assertTrue(fields.size() == 3); IntStream.range(0, fields.size()).forEach(idx -> { assertEquals(fields.get(idx).getName(), "Col_" + (idx + 1)); assertEquals(fields.get(idx).getSampleValues().size(), 1); }); } }
@Test public void testHeaderFirstRowNoDuplicateValues() throws Exception { parser.setHeaderRow(true); try (InputStream is = toInputStream("HEAD_1,HEAD_2,HEAD_3\nr2v1,r2v2,r2v3\n")) { HiveTableSchema schema = toHiveTableSchema(is); List<? extends Field> fields = schema.getFields(); assertTrue(fields.size() == 3); IntStream.range(0, fields.size()).forEach(idx -> { assertEquals(fields.get(idx).getName(), "HEAD_" + (idx + 1)); assertEquals(fields.get(idx).getSampleValues().size(), 1); }); } }