1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ package org .apache .commons .csv .issues ;
19+
20+ import static org .junit .jupiter .api .Assertions .assertEquals ;
21+ import static org .junit .jupiter .api .Assertions .assertFalse ;
22+ import java .io .Reader ;
23+ import java .io .StringReader ;
24+ import java .util .Arrays ;
25+ import java .util .Iterator ;
26+
27+ import org .apache .commons .csv .CSVFormat ;
28+ import org .apache .commons .csv .CSVParser ;
29+ import org .apache .commons .csv .CSVRecord ;
30+ import org .junit .jupiter .api .Test ;
31+
32+ public class JiraCvs247Test {
33+
34+ @ Test
35+ public void testHeadersMissingOneColumn () throws Exception {
36+ final Reader in = new StringReader ("a,,c,d,e\n 1,2,3,4,5\n v,w,x,y,z" );
37+ try (final CSVParser parser = CSVFormat .DEFAULT .withHeader ().parse (in )) {
38+ assertEquals (Arrays .asList ("a" , "" , "c" , "d" , "e" ), parser .getHeaderNames ());
39+ final Iterator <CSVRecord > iterator = parser .iterator ();
40+ CSVRecord record = iterator .next ();
41+ assertEquals ("1" , record .get (0 ));
42+ assertEquals ("2" , record .get (1 ));
43+ assertEquals ("3" , record .get (2 ));
44+ assertEquals ("4" , record .get (3 ));
45+ assertEquals ("5" , record .get (4 ));
46+ record = iterator .next ();
47+ assertEquals ("v" , record .get (0 ));
48+ assertEquals ("w" , record .get (1 ));
49+ assertEquals ("x" , record .get (2 ));
50+ assertEquals ("y" , record .get (3 ));
51+ assertEquals ("z" , record .get (4 ));
52+ assertFalse (iterator .hasNext ());
53+ }
54+ }
55+
56+ @ Test
57+ public void testJiraDescription () throws Exception {
58+ final Reader in = new StringReader ("a,,c,d\n 1,2,3,4\n x,y,z,zz" );
59+ try (final CSVParser parser = CSVFormat .DEFAULT .withHeader ().parse (in )) {
60+ parser .iterator ();
61+ }
62+ }
63+
64+ }
0 commit comments