|
3 | 3 | import com.poiji.bind.Poiji; |
4 | 4 | import com.poiji.deserialize.model.byid.CalculationRecord; |
5 | 5 | import com.poiji.deserialize.model.byname.EmployeeRecord; |
| 6 | +import com.poiji.deserialize.model.byname.OrgWithUnknownCellsRecord; |
6 | 7 | import com.poiji.deserialize.model.byname.PersonRecord; |
7 | 8 | import com.poiji.option.PoijiOptions; |
8 | 9 | import org.junit.Test; |
@@ -291,4 +292,57 @@ public void shouldMapExcelToRecordFromSheetWithConsumer() { |
291 | 292 | fail(e.getMessage()); |
292 | 293 | } |
293 | 294 | } |
| 295 | + |
| 296 | + @Test |
| 297 | + public void shouldMapExcelToRecordWithUnknownCells() { |
| 298 | + // Test with @ExcelUnknownCells annotation |
| 299 | + List<OrgWithUnknownCellsRecord> organisations = Poiji.fromExcel( |
| 300 | + new File("src/test/resources/unknown-cells.xlsx"), |
| 301 | + OrgWithUnknownCellsRecord.class, |
| 302 | + PoijiOptions.PoijiOptionsBuilder.settings() |
| 303 | + .sheetName("Organisation") |
| 304 | + .build() |
| 305 | + ); |
| 306 | + |
| 307 | + assertThat(organisations, notNullValue()); |
| 308 | + assertThat(organisations.size(), is(2)); |
| 309 | + |
| 310 | + // Test first row - verify unknownCells captures unmapped "Region" column |
| 311 | + OrgWithUnknownCellsRecord firstRow = organisations.stream() |
| 312 | + .filter(org -> org.id().equals("CrEaTe")) |
| 313 | + .findFirst() |
| 314 | + .get(); |
| 315 | + assertThat(firstRow.unknownCells(), notNullValue()); |
| 316 | + assertThat(firstRow.unknownCells().size(), is(1)); |
| 317 | + assertThat(firstRow.unknownCells().get("Region"), is("EMEA")); |
| 318 | + |
| 319 | + // Test second row |
| 320 | + OrgWithUnknownCellsRecord secondRow = organisations.stream() |
| 321 | + .filter(org -> org.id().equals("8d9e6430-8626-4556-8004-079085d2df2d")) |
| 322 | + .findFirst() |
| 323 | + .get(); |
| 324 | + assertThat(secondRow.unknownCells(), notNullValue()); |
| 325 | + assertThat(secondRow.unknownCells().size(), is(1)); |
| 326 | + assertThat(secondRow.unknownCells().get("Region"), is("NA")); |
| 327 | + } |
| 328 | + |
| 329 | + @Test |
| 330 | + public void shouldMapXLSToRecordWithUnknownCells() { |
| 331 | + // Test XLS format with @ExcelUnknownCells annotation |
| 332 | + List<OrgWithUnknownCellsRecord> organisations = Poiji.fromExcel( |
| 333 | + new File("src/test/resources/unknown-cells.xls"), |
| 334 | + OrgWithUnknownCellsRecord.class, |
| 335 | + PoijiOptions.PoijiOptionsBuilder.settings() |
| 336 | + .sheetName("Organisation") |
| 337 | + .build() |
| 338 | + ); |
| 339 | + |
| 340 | + assertThat(organisations, notNullValue()); |
| 341 | + assertThat(organisations.size(), is(2)); |
| 342 | + |
| 343 | + // Verify unknownCells are captured correctly |
| 344 | + OrgWithUnknownCellsRecord firstRow = organisations.get(0); |
| 345 | + assertThat(firstRow.unknownCells(), notNullValue()); |
| 346 | + assertThat(firstRow.unknownCells().containsKey("Region"), is(true)); |
| 347 | + } |
294 | 348 | } |
0 commit comments