1
2
3
4
5
6
7
8
9
10
11 package org.csveed.common;
12
13 import static org.junit.jupiter.api.Assertions.assertEquals;
14 import static org.junit.jupiter.api.Assertions.assertNotNull;
15 import static org.junit.jupiter.api.Assertions.assertThrows;
16
17 import java.util.Map;
18 import java.util.TreeMap;
19
20 import org.csveed.api.Header;
21 import org.csveed.report.CsvException;
22 import org.csveed.row.HeaderImpl;
23 import org.csveed.row.LineWithInfo;
24 import org.junit.jupiter.api.Test;
25
26
27
28
29 class ColumnTest {
30
31
32
33
34 @Test
35 void excelColumnToColumnIndex() {
36 Column excel = new ColumnExcel("AH");
37 assertEquals(34, excel.getColumnIndex());
38 }
39
40
41
42
43 @Test
44 void largestPossibleIndex() {
45 Column excel = new ColumnExcel("ZZ");
46 assertEquals(702, excel.getColumnIndex());
47 }
48
49
50
51
52 @Test
53 void columnIndexToExcelColumn() {
54 Column excel = new Column(34);
55 assertEquals("AH", excel.getExcelColumn());
56 }
57
58
59
60
61 @Test
62 void wrongIndex() {
63 assertThrows(CsvException.class, () -> new Column(0));
64 }
65
66
67
68
69 @Test
70 void nextColumn() {
71 Column column = new Column(3);
72 assertEquals(4, column.nextColumn().getColumnIndex());
73 }
74
75
76
77
78 @Test
79 void reset() {
80 Column column = new Column(3);
81 assertEquals(Column.FIRST_COLUMN_INDEX, column.nextLine().getColumnIndex());
82 }
83
84
85
86
87 @Test
88 void equals() {
89 assertEquals(new Column(3), new Column(3));
90 }
91
92
93
94
95 @Test
96 void treeMap() {
97 Map<Column, String> map = new TreeMap<>();
98 Column storeColumn = new Column("name");
99 map.put(storeColumn, "alpha");
100 LineWithInfo line = new LineWithInfo();
101 line.addCell("name");
102 Header header = new HeaderImpl(line);
103 Column searchColumn = new Column().setHeader(header);
104 assertNotNull(map.get(searchColumn));
105 }
106
107
108
109
110 @Test
111 void treeMapWithColumnIndex() {
112 Map<Column, String> map = new TreeMap<>();
113 map.put(new Column(1), "alpha");
114 map.put(new Column(2), "beta");
115 map.put(new Column(3), "gamma");
116 assertEquals("alpha", map.get(new Column(1)));
117 assertEquals("beta", map.get(new Column(2)));
118 assertEquals("gamma", map.get(new Column(3)));
119 }
120
121 }