@Test
public void testGetHeaderMap() throws Exception {

    final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"));
    final Map<String, Integer> headerMap = parser.getHeaderMap();
    final Iterator<String> columnNames = headerMap.keySet().iterator();
    // Headers are iterated in column order.
    Assert.assertEquals("A", columnNames.next());
    Assert.assertEquals("B", columnNames.next());
    Assert.assertEquals("C", columnNames.next());
    final Iterator<CSVRecord> records = parser.iterator();
    // Parse to make sure getHeaderMap did not have a side-effect.
    for (int i = 0; i < 3; i++) {
        assertTrue(records.hasNext());
        final CSVRecord record = records.next();
        assertEquals(record.get(0), record.get("A"));
        assertEquals(record.get(1), record.get("B"));
        assertEquals(record.get(2), record.get("C"));
    }
    assertFalse(records.hasNext());
}