@@ -506,6 +506,26 @@ public void testHeader() throws Exception {
506506 assertFalse (records .hasNext ());
507507 }
508508
509+ @ Test
510+ public void testSkipSetHeader () throws Exception {
511+ final Reader in = new StringReader ("a,b,c\n 1,2,3\n x,y,z" );
512+ final Iterator <CSVRecord > records = CSVFormat .DEFAULT .withHeader ("a" , "b" , "c" ).parse (in ).iterator ();
513+ final CSVRecord record = records .next ();
514+ assertEquals ("1" , record .get ("a" ));
515+ assertEquals ("2" , record .get ("b" ));
516+ assertEquals ("3" , record .get ("c" ));
517+ }
518+
519+ @ Test
520+ public void testSkipAutoHeader () throws Exception {
521+ final Reader in = new StringReader ("a,b,c\n 1,2,3\n x,y,z" );
522+ final Iterator <CSVRecord > records = CSVFormat .DEFAULT .withHeader ().parse (in ).iterator ();
523+ final CSVRecord record = records .next ();
524+ assertEquals ("1" , record .get ("a" ));
525+ assertEquals ("2" , record .get ("b" ));
526+ assertEquals ("3" , record .get ("c" ));
527+ }
528+
509529 @ Test
510530 public void testHeaderComment () throws Exception {
511531 final Reader in = new StringReader ("# comment\n a,b,c\n 1,2,3\n x,y,z" );
@@ -529,7 +549,7 @@ public void testProvidedHeader() throws Exception {
529549
530550 final Iterator <CSVRecord > records = CSVFormat .DEFAULT .withHeader ("A" , "B" , "C" ).parse (in ).iterator ();
531551
532- for (int i = 0 ; i < 3 ; i ++) {
552+ for (int i = 0 ; i < 2 ; i ++) {
533553 assertTrue (records .hasNext ());
534554 final CSVRecord record = records .next ();
535555 assertTrue (record .isMapped ("A" ));
@@ -544,25 +564,32 @@ public void testProvidedHeader() throws Exception {
544564 assertFalse (records .hasNext ());
545565 }
546566
567+ @ Test
568+ public void testProvidedHeaderAuto () throws Exception {
569+ final Reader in = new StringReader ("a,b,c\n 1,2,3\n x,y,z" );
570+
571+ final Iterator <CSVRecord > records = CSVFormat .DEFAULT .withHeader ().parse (in ).iterator ();
572+
573+ for (int i = 0 ; i < 2 ; i ++) {
574+ assertTrue (records .hasNext ());
575+ final CSVRecord record = records .next ();
576+ assertTrue (record .isMapped ("a" ));
577+ assertTrue (record .isMapped ("b" ));
578+ assertTrue (record .isMapped ("c" ));
579+ assertFalse (record .isMapped ("NOT MAPPED" ));
580+ assertEquals (record .get (0 ), record .get ("a" ));
581+ assertEquals (record .get (1 ), record .get ("b" ));
582+ assertEquals (record .get (2 ), record .get ("c" ));
583+ }
584+
585+ assertFalse (records .hasNext ());
586+ }
587+
547588 @ Test
548589 public void testMappedButNotSetAsOutlook2007ContactExport () throws Exception {
549590 final Reader in = new StringReader ("a,b,c\n 1,2\n x,y,z" );
550-
551591 final Iterator <CSVRecord > records = CSVFormat .DEFAULT .withHeader ("A" , "B" , "C" ).parse (in ).iterator ();
552-
553- // header record
554- assertTrue (records .hasNext ());
555- CSVRecord record = records .next ();
556- assertTrue (record .isMapped ("A" ));
557- assertTrue (record .isMapped ("B" ));
558- assertTrue (record .isMapped ("C" ));
559- assertTrue (record .isSet ("A" ));
560- assertTrue (record .isSet ("B" ));
561- assertTrue (record .isSet ("C" ));
562- assertEquals ("a" , record .get ("A" ));
563- assertEquals ("b" , record .get ("B" ));
564- assertEquals ("c" , record .get ("C" ));
565- assertTrue (record .isConsistent ());
592+ CSVRecord record ;
566593
567594 // 1st record
568595 record = records .next ();
@@ -604,7 +631,7 @@ public void testGetHeaderMap() throws Exception {
604631 final Iterator <CSVRecord > records = parser .iterator ();
605632
606633 // Parse to make sure getHeaderMap did not have a side-effect.
607- for (int i = 0 ; i < 3 ; i ++) {
634+ for (int i = 0 ; i < 2 ; i ++) {
608635 assertTrue (records .hasNext ());
609636 final CSVRecord record = records .next ();
610637 assertEquals (record .get (0 ), record .get ("A" ));
0 commit comments