### Question:
MetadataEntityHeaderParser { public MetadataHeader readHeader(InputStream stream) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { String line = reader.readLine(); if (StringUtils.isBlank(line)) { throw new MetadataReadingException("Input file doesn't have expected header."); } String[] columns = line.split(delimiter); if (columns.length < 1) { throw new MetadataReadingException("At least one column should be present."); } MetadataHeader header = new MetadataHeader(headerParser.readClassColumn(columns[0])); for (int i = 1; i < columns.length; i++) { header.addField(i, headerParser.readFieldColumn(columns[i])); } return header; } catch (IOException e) { throw new MetadataReadingException(e.getMessage(), e); } } MetadataEntityHeaderParser(String delimiter); MetadataHeader readHeader(InputStream stream);  }### Answer:
@Test public void testReadHeader() throws IOException { MetadataHeader expected = new MetadataHeader(CLASS_NAME); expected.addField(1, new EntityTypeField("name", EntityTypeField.DEFAULT_TYPE, false, false)); expected.addField(2, new EntityTypeField("type", EntityTypeField.DEFAULT_TYPE, false, false)); expected.addField(3, new EntityTypeField("patient", "Participant", true, false)); expected.addField(4, new EntityTypeField("pairs", "Pair", true, true)); MetadataHeader tabHeader = new MetadataEntityHeaderParser("\t") .readHeader(ByteSource.wrap(TAB_HEADER.getBytes()).openStream()); assertEquals(expected, tabHeader); MetadataHeader csvHeader = new MetadataEntityHeaderParser(CSV_DELIMITER) .readHeader(ByteSource.wrap(CSV_HEADER.getBytes()).openStream()); assertEquals(expected, csvHeader); }
@Test(expected = MetadataReadingException.class) public void testInvalidClassColumn() throws IOException { new MetadataEntityHeaderParser(CSV_DELIMITER) .readHeader(ByteSource.wrap(INVALID_CLASS_HEADER.getBytes()).openStream()); }
@Test(expected = MetadataReadingException.class) public void testInvalidFieldsColumn() throws IOException { new MetadataEntityHeaderParser(CSV_DELIMITER) .readHeader(ByteSource.wrap(INVALID_FIELD_HEADER.getBytes()).openStream()); }