View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.commons.csv.issues;
21  
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  
24  import java.io.IOException;
25  import java.io.InputStream;
26  import java.io.InputStreamReader;
27  import java.io.UnsupportedEncodingException;
28  import java.nio.charset.StandardCharsets;
29  
30  import org.apache.commons.csv.CSVFormat;
31  import org.apache.commons.csv.CSVParser;
32  import org.junit.jupiter.api.Test;
33  
34  class JiraCsv198Test {
35  
36      // @formatter:off
37      private static final CSVFormat CSV_FORMAT = CSVFormat.EXCEL.builder()
38          .setDelimiter('^')
39          .setHeader()
40          .setSkipHeaderRecord(true)
41          .get();
42      // @formatter:on
43  
44      @Test
45      void test() throws UnsupportedEncodingException, IOException {
46          final InputStream pointsOfReference = getClass().getResourceAsStream("/org/apache/commons/csv/CSV-198/optd_por_public.csv");
47          assertNotNull(pointsOfReference);
48          try (@SuppressWarnings("resource")
49          CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, StandardCharsets.UTF_8))) {
50              parser.forEach(record -> assertNotNull(record.get("location_type")));
51          }
52      }
53  
54  }