View Javadoc
1   /*
2    * CSVeed (https://github.com/42BV/CSVeed)
3    *
4    * Copyright 2013-2023 CSVeed.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
10   */
11  package org.csveed.row;
12  
13  import static org.junit.jupiter.api.Assertions.assertEquals;
14  import static org.junit.jupiter.api.Assertions.assertThrows;
15  
16  import org.csveed.api.Header;
17  import org.csveed.report.CsvException;
18  import org.junit.jupiter.api.Test;
19  
20  /**
21   * The Class HeaderTest.
22   */
23  class HeaderTest {
24  
25      /**
26       * Gets the non existing column name.
27       */
28      @Test
29      void getNonExistingColumnName() {
30          Header header = new HeaderImpl(createLine("alpha"));
31          assertThrows(CsvException.class, () -> header.getIndex("does-not-exist"));
32      }
33  
34      /**
35       * Gets the non existing column index.
36       */
37      @Test
38      void getNonExistingColumnIndex() {
39          Header header = new HeaderImpl(createLine("alpha"));
40          assertThrows(CsvException.class, () -> header.getName(13));
41      }
42  
43      /**
44       * To lower case.
45       */
46      @Test
47      void toLowerCase() {
48          Header header = new HeaderImpl(createLine("Alpha"));
49          assertEquals("Alpha", header.getName(1));
50          assertEquals(1, header.getIndex("Alpha"));
51      }
52  
53      /**
54       * Creates the line.
55       *
56       * @param cell
57       *            the cell
58       *
59       * @return the line with info
60       */
61      protected LineWithInfo createLine(String cell) {
62          LineWithInfo line = new LineWithInfo();
63          line.addCell(cell);
64          return line;
65      }
66  }