test: add tests for EscapeHexCellWriteHandler - #1001
Conversation
There was a problem hiding this comment.
Pull request overview
Adds comprehensive regression tests for EscapeHexCellWriteHandler (per #1000), re-establishing coverage for both the core escaping rule and an end-to-end round-trip scenario across supported formats.
Changes:
- Adds parameterized unit tests covering valid
_xHHHH_escaping, invalid patterns, non-idempotency, and null/non-string guards. - Adds a
ROUND_TRIPintegration test parameterized over XLSX/XLS/CSV to ensure the literal sequence survives write+read with the handler registered.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| fesod-sheet/src/test/java/org/apache/fesod/sheet/write/handler/EscapeHexCellWriteHandlerTest.java | Unit-level parameterized coverage for pattern escaping and guard conditions. |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/write/handler/EscapeHexCellWriteHandlerRoundTripTest.java | End-to-end round-trip test across XLSX/XLS/CSV with the handler registered. |
Suppressed comments (1)
fesod-sheet/src/test/java/org/apache/fesod/sheet/write/handler/EscapeHexCellWriteHandlerRoundTripTest.java:63
- Reading the generated CSV with FileReader relies on the platform default charset. Use UTF-8 explicitly so the round-trip assertion is stable across environments.
if (format == ExcelFormat.CSV) {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
reader.readLine(); // header
return reader.readLine();
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
LGTM. |
alaahong
left a comment
There was a problem hiding this comment.
Generally fine, can you revise the code as common practice?
| () -> handler.afterCellDataConverted(null, null, emptyStringData, cell, null, 0, Boolean.FALSE)); | ||
| Assertions.assertNull(emptyStringData.getStringValue()); | ||
| } | ||
| } |
There was a problem hiding this comment.
It should be fine, a little suggestion, seems it's bringing some new additional exceptions by testing code?
https://github.com/apache/fesod/actions/runs/31603043137/job/94135710567
There was a problem hiding this comment.
Hi @alaahong! Thank you for the review!
I partly based my setup on PoiUtilsTest:test_customHeight_unsupportedType_false, which has exactly the same WARN. This is why I overlooked it.
One fix could be sheet.flushRows();. However, in my case, the handler does nothing with the cell beyond cell instanceof SXSSFCell, so I decided to fix it with Mockito.mock(SXSSFCell.class), and it also makes the code easier to read.
The one thing the mock gave up was coverage of the instanceof check itself, so I've pushed a follow-up test, afterCellDataConverted_ignoresNonSxssfCells, which runs the handler over a mocked HSSFCell and asserts the value is left untouched.
Please resolve the conversation if you accept this fix :)
Related: #1000
Purpose of the pull request
EscapeHexCellWriteHandlerhas no tests. It used to have them, but they were deleted by accident (read #1000).This PR is not a blind restore of those lost tests! I took a different approach; for example,
@ParameterizedTestwere used for better scalability and readability, etc.What's changed?
_xHHHH_to_x005F_xHHHH_) and eight that must be left exactly as typed.STRINGcell data, a nullWriteCellData, and aSTRINGholding a null value.@ExcelFormatSource: write a file through Fesod with the handler registered, read it back, and require the caller's literal. It sits in its own class taggedROUND_TRIP, which keeps the rest taggedUNIT.Checklist