View Javadoc
1   package org.csveed.common;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   import static org.junit.jupiter.api.Assertions.assertNotNull;
5   import static org.junit.jupiter.api.Assertions.assertThrows;
6   
7   import java.util.Map;
8   import java.util.TreeMap;
9   
10  import org.csveed.api.Header;
11  import org.csveed.report.CsvException;
12  import org.csveed.row.HeaderImpl;
13  import org.csveed.row.LineWithInfo;
14  import org.junit.jupiter.api.Test;
15  
16  public class ColumnTest {
17  
18      @Test
19      public void excelColumnToColumnIndex() {
20          Column excel = new ColumnExcel("AH");
21          assertEquals(34, excel.getColumnIndex());
22      }
23  
24      @Test
25      public void largestPossibleIndex() {
26          Column excel = new ColumnExcel("ZZ");
27          assertEquals(702, excel.getColumnIndex());
28      }
29  
30      @Test
31      public void columnIndexToExcelColumn() {
32          Column excel = new Column(34);
33          assertEquals("AH", excel.getExcelColumn());
34      }
35  
36      @Test
37      public void wrongIndex() {
38          assertThrows(CsvException.class, () ->  {
39              new Column(0);
40          });
41      }
42  
43      @Test
44      public void nextColumn() {
45          Column column = new Column(3);
46          assertEquals(4, column.nextColumn().getColumnIndex());
47      }
48  
49      @Test
50      public void reset() {
51          Column column = new Column(3);
52          assertEquals(Column.FIRST_COLUMN_INDEX, column.nextLine().getColumnIndex());
53      }
54  
55      @Test
56      public void equals() {
57          assertEquals(new Column(3), new Column(3));
58      }
59  
60      @Test
61      public void treeMap() {
62          Map<Column, String> map = new TreeMap<>();
63          Column storeColumn = new Column("name");
64          map.put(storeColumn, "alpha");
65          LineWithInfo line = new LineWithInfo();
66          line.addCell("name");
67          Header header = new HeaderImpl(line);
68          Column searchColumn = new Column().setHeader(header);
69          assertNotNull(map.get(searchColumn));
70      }
71  
72      @Test
73      public void treeMapWithColumnIndex() {
74          Map<Column, String> map = new TreeMap<>();
75          map.put(new Column(1), "alpha");
76          map.put(new Column(2), "beta");
77          map.put(new Column(3), "gamma");
78          assertEquals("alpha", map.get(new Column(1)));
79          assertEquals("beta", map.get(new Column(2)));
80          assertEquals("gamma", map.get(new Column(3)));
81      }
82  
83  }