Copilot commented on code in PR #954:
URL: https://github.com/apache/fesod/pull/954#discussion_r3602878804
##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java:
##########
@@ -120,6 +126,87 @@ void testCsvWriteWithModelShouldSuccess() {
.doWrite(modelData());
}
+ /**
+ * Verifies that {@link CsvCell} handles {@link java.sql.Date} the same
way as
+ * {@link org.apache.fesod.sheet.metadata.data.WriteCellData}: the date is
extracted
+ * via {@code toLocalDate().atStartOfDay()}, stripping any time component
that may
+ * exist in the underlying milliseconds (common when JDBC drivers create
+ * {@code java.sql.Date} from a {@code java.util.Date} with time info).
+ */
+ @Test
+ void testCsvCellSqlDateConversion() {
+ // Create a java.sql.Date from a java.util.Date that has a time
component
+ java.util.Date utilDate = new java.util.Date(2023 - 1900,
Calendar.JUNE, 15, 23, 30, 0);
+ java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
+
+ Cell cell = csvRow.createCell(0, CellType.NUMERIC);
+ cell.setCellValue(sqlDate);
+
+ LocalDateTime dateValue = ((CsvCell) cell).getLocalDateTimeCellValue();
+ // java.sql.Date is date-only: time component must be stripped to
midnight
+ Assertions.assertEquals(LocalDateTime.of(2023, 6, 15, 0, 0, 0),
dateValue);
+ }
+
+ /**
+ * Verifies that {@link CsvCell} handles {@link java.sql.Time} the same
way as
+ * {@link org.apache.fesod.sheet.metadata.data.WriteCellData}: the time is
extracted
+ * via {@code toLocalTime().atDate(LocalDate.of(1970, 1, 1))}, stripping
any date
+ * component that may exist in the underlying milliseconds.
+ */
+ @Test
+ void testCsvCellSqlTimeConversion() {
+ // Create a java.sql.Time from a java.util.Date that has a date
component
+ java.util.Date utilDate = new java.util.Date(2023 - 1900,
Calendar.JUNE, 15, 12, 30, 45);
+ java.sql.Time sqlTime = new java.sql.Time(utilDate.getTime());
+
+ Cell cell = csvRow.createCell(0, CellType.NUMERIC);
+ cell.setCellValue(sqlTime);
+
+ LocalDateTime dateValue = ((CsvCell) cell).getLocalDateTimeCellValue();
+ // java.sql.Time is time-only: date component must be normalized to
1970-01-01
+ Assertions.assertEquals(LocalDateTime.of(1970, 1, 1, 12, 30, 45),
dateValue);
+ }
+
+ /**
+ * Real-file integration test: writes a physical CSV file containing
+ * {@code java.sql.Date} and {@code java.sql.Time} values via the
+ * {@link CsvCell} API, then reads the file back to verify the output.
+ * <p>
+ * Without the fix, {@code CsvCell.setCellValueImpl(Date)} calls
+ * {@code value.toInstant()} which throws {@code
UnsupportedOperationException}
+ * on Java 9+ for {@code java.sql.Date}/{@code java.sql.Time}.
+ */
+ @Test
+ void csvWrite_withSqlDateAndTime_producesCorrectFile() throws Exception {
+ File csvFile = new File(tempDir, "sql-date-test.csv");
+
+ try (FileWriter writer = new FileWriter(csvFile)) {
Review Comment:
Using FileWriter here relies on the platform-default charset (Java 8 has no
FileWriter(File, Charset)). Since the test reads with UTF-8 and passes UTF-8
into CsvWorkbook, create the writer via Files.newBufferedWriter(..., UTF_8) to
keep encoding consistent and platform-independent.
##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java:
##########
@@ -20,10 +20,16 @@
package org.apache.fesod.sheet.format;
import java.io.File;
+import java.io.FileWriter;
Review Comment:
CsvWorkbook is configured with UTF-8, but this test currently uses
FileWriter (platform-default charset). On Java 8 this can make the test
platform-dependent and also makes the UTF-8 intent unclear. Prefer using a
Writer type and construct it with Files.newBufferedWriter(..., UTF_8).
##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java:
##########
@@ -120,6 +126,87 @@ void testCsvWriteWithModelShouldSuccess() {
.doWrite(modelData());
}
+ /**
+ * Verifies that {@link CsvCell} handles {@link java.sql.Date} the same
way as
+ * {@link org.apache.fesod.sheet.metadata.data.WriteCellData}: the date is
extracted
+ * via {@code toLocalDate().atStartOfDay()}, stripping any time component
that may
+ * exist in the underlying milliseconds (common when JDBC drivers create
+ * {@code java.sql.Date} from a {@code java.util.Date} with time info).
+ */
+ @Test
+ void testCsvCellSqlDateConversion() {
+ // Create a java.sql.Date from a java.util.Date that has a time
component
+ java.util.Date utilDate = new java.util.Date(2023 - 1900,
Calendar.JUNE, 15, 23, 30, 0);
+ java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
+
+ Cell cell = csvRow.createCell(0, CellType.NUMERIC);
+ cell.setCellValue(sqlDate);
+
+ LocalDateTime dateValue = ((CsvCell) cell).getLocalDateTimeCellValue();
+ // java.sql.Date is date-only: time component must be stripped to
midnight
+ Assertions.assertEquals(LocalDateTime.of(2023, 6, 15, 0, 0, 0),
dateValue);
+ }
+
+ /**
+ * Verifies that {@link CsvCell} handles {@link java.sql.Time} the same
way as
+ * {@link org.apache.fesod.sheet.metadata.data.WriteCellData}: the time is
extracted
+ * via {@code toLocalTime().atDate(LocalDate.of(1970, 1, 1))}, stripping
any date
+ * component that may exist in the underlying milliseconds.
+ */
+ @Test
+ void testCsvCellSqlTimeConversion() {
+ // Create a java.sql.Time from a java.util.Date that has a date
component
+ java.util.Date utilDate = new java.util.Date(2023 - 1900,
Calendar.JUNE, 15, 12, 30, 45);
+ java.sql.Time sqlTime = new java.sql.Time(utilDate.getTime());
Review Comment:
The java.util.Date(int, int, ...) constructor is deprecated and can
introduce avoidable warnings in the test suite. Use Calendar (already imported)
to build the millis instead.
##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java:
##########
@@ -120,6 +126,87 @@ void testCsvWriteWithModelShouldSuccess() {
.doWrite(modelData());
}
+ /**
+ * Verifies that {@link CsvCell} handles {@link java.sql.Date} the same
way as
+ * {@link org.apache.fesod.sheet.metadata.data.WriteCellData}: the date is
extracted
+ * via {@code toLocalDate().atStartOfDay()}, stripping any time component
that may
+ * exist in the underlying milliseconds (common when JDBC drivers create
+ * {@code java.sql.Date} from a {@code java.util.Date} with time info).
+ */
+ @Test
+ void testCsvCellSqlDateConversion() {
+ // Create a java.sql.Date from a java.util.Date that has a time
component
+ java.util.Date utilDate = new java.util.Date(2023 - 1900,
Calendar.JUNE, 15, 23, 30, 0);
+ java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
Review Comment:
The java.util.Date(int, int, ...) constructor is deprecated and can
introduce avoidable warnings in the test suite. Use Calendar (already imported)
to build the millis instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]