Skip to content

Commit 7b00c71

Browse files
Copilotozlerhakan
andcommitted
Add @ExcelCell test for records and update CI to support Java 17+
Co-authored-by: ozlerhakan <[email protected]>
1 parent 31c4c3b commit 7b00c71

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
java: [ 11, 17, 23 ]
7+
java: [ 17, 23 ]
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v3

src/test/java/com/poiji/deserialize/RecordDeserializationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.poiji.deserialize;
22

33
import com.poiji.bind.Poiji;
4+
import com.poiji.deserialize.model.byid.CalculationRecord;
45
import com.poiji.deserialize.model.byname.EmployeeRecord;
56
import com.poiji.deserialize.model.byname.PersonRecord;
67
import com.poiji.option.PoijiOptions;
@@ -86,4 +87,27 @@ public void shouldMapExcelToRecordWithOptions() {
8687
assertThat(employees, notNullValue());
8788
assertThat(employees.size(), is(3));
8889
}
90+
91+
@Test
92+
public void shouldMapExcelToRecordWithExcelCell() {
93+
// Test with @ExcelCell annotation (by index)
94+
PoijiOptions options = PoijiOptions.PoijiOptionsBuilder.settings()
95+
.sheetIndex(1)
96+
.build();
97+
98+
List<CalculationRecord> calculations = Poiji.fromExcel(
99+
new File("src/test/resources/calculations.xlsx"),
100+
CalculationRecord.class,
101+
options
102+
);
103+
104+
assertThat(calculations, notNullValue());
105+
assertThat(calculations.size(), is(4));
106+
107+
// Verify that records with @ExcelCell work correctly
108+
for (CalculationRecord calculation : calculations) {
109+
assertThat(calculation.fromDate().toString(), is("2018-01-01"));
110+
assertThat(calculation.toDate().toString(), is("2018-06-30"));
111+
}
112+
}
89113
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.poiji.deserialize.model.byid;
2+
3+
import com.poiji.annotation.ExcelCell;
4+
5+
import java.time.LocalDate;
6+
7+
/**
8+
* A record class to test Java Records support with @ExcelCell (by index)
9+
*/
10+
public record CalculationRecord(
11+
@ExcelCell(0)
12+
LocalDate fromDate,
13+
14+
@ExcelCell(1)
15+
LocalDate toDate,
16+
17+
@ExcelCell(2)
18+
String is,
19+
20+
@ExcelCell(3)
21+
Float total,
22+
23+
@ExcelCell(4)
24+
Float turnover
25+
) {
26+
}

0 commit comments

Comments
 (0)