Fix bugs, remove dead code, and expand test coverage from code review
Bug fixes:
- CSVGenerator single-arg constructor now delegates to two-arg to avoid NPE
  on formatterChain (was left null, causing NPE on generate())
- Replace Java 21 List.getLast() with Java 8-compatible get(size-1)
- Guard generateHeaders() and getAutoSizedColumns() against empty/null data
- NumberFormatterChain: add null guard before DecimalFormat.format() and
  narrow catch from Exception to IllegalArgumentException
- CurrencyFormatterChain: fix USD format from "#.00" to "#,##0.00" (adds
  thousands separator for large values)
- HyperlinkChain: guard getStringCellValue() with CellType.STRING check;
  add instanceof guard before XSSFHyperlink cast with descriptive error
- ExcelGenerator: move cellStyles from instance field to local variable in
  generate() to prevent stale-reference bug on repeated calls
- Generator: throw IllegalStateException (unchecked) instead of Exception
  for unreachable "Unknown Instance type" branches; log to stderr before
  substituting "Unknown Value" sentinel

Dead code removed:
- @Reportable.autoSize() attribute (never read; @AutoSize annotation is used)
- CellStyleUtils.NUMBER_FORMAT constant (defined but never referenced)

Code quality:
- CSVGenerator.generateWriter: replace @SuppressWarnings("resource") with
  proper try-with-resources for CSVPrinter
- ItemTest: rename inner TestPojo to ItemTestPojo to avoid shadowing the
  package-level TestPojo class

Tests (52 to 83, +31 new tests):
- CSVGeneratorSingleArgConstructorTest: verify single-arg constructor works
- CSVGeneratorEmptyDataTest: verify empty list produces valid empty output
- CSVGeneratorReportableMapTest: verify @ReportableMap with populated map
  data produces correct CSV headers and rows (was previously untested)
- ExcelGeneratorEmptyDataTest: verify empty/null data in Excel generator
- NumberFormatterChainTest: null value, integer/double formatting, bad
  pattern skip, method annotation
- HyperlinkChainTest: non-STRING cell skipped, STRING cell gets hyperlink
- NumberFormatterCellChainTest: cell style applied and cached correctly
- CenterChainTest: center alignment applied / absent as expected

Documentation (README.md):
- Fix @DecimalFormatter to @NumberFormatter (annotation did not exist)
- Rename "Decimal Formatter" section to "Number Formatter"
- Fix @StringFormatter(text=...) to @StringFormatFormatter(text=...) in
  String Format Formatter section
- Fix Format.USD to Currency.USD in Currency Formatter options
- Add note that empty list produces headers-only output (no exception)
- Add note that @ReportableMap fields must use LinkedHashMap for
  deterministic column ordering

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7552633 commit f3fb2e5f3c8165a59417703913d6c10e315af6f2
@Alexander Ljunggren Alexander Ljunggren authored on 5 May
Showing 18 changed files
View
README.md
View
src/main/java/io/ljunggren/report/generator/Generator.java
View
src/main/java/io/ljunggren/report/generator/annotation/Reportable.java
View
src/main/java/io/ljunggren/report/generator/csv/CSVGenerator.java
View
src/main/java/io/ljunggren/report/generator/excel/ExcelGenerator.java
View
src/main/java/io/ljunggren/report/generator/excel/cell/HyperlinkChain.java
View
src/main/java/io/ljunggren/report/generator/formatter/CurrencyFormatterChain.java
View
src/main/java/io/ljunggren/report/generator/formatter/NumberFormatterChain.java
View
src/main/java/io/ljunggren/report/generator/utils/CellStyleUtils.java
View
src/test/java/io/ljunggren/report/generator/ItemTest.java
View
src/test/java/io/ljunggren/report/generator/csv/CSVGeneratorEmptyDataTest.java 0 → 100755
View
src/test/java/io/ljunggren/report/generator/csv/CSVGeneratorReportableMapTest.java 0 → 100755
View
src/test/java/io/ljunggren/report/generator/csv/CSVGeneratorSingleArgConstructorTest.java 0 → 100755
View
src/test/java/io/ljunggren/report/generator/excel/ExcelGeneratorEmptyDataTest.java 0 → 100755
View
src/test/java/io/ljunggren/report/generator/excel/cell/CenterChainTest.java 0 → 100755
View
src/test/java/io/ljunggren/report/generator/excel/cell/HyperlinkChainTest.java 0 → 100755
View
src/test/java/io/ljunggren/report/generator/excel/cell/NumberFormatterCellChainTest.java 0 → 100755
View
src/test/java/io/ljunggren/report/generator/formatter/NumberFormatterChainTest.java 0 → 100755