This is an automated email from the ASF dual-hosted git repository.

delei pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fesod.git


The following commit(s) were added to refs/heads/main by this push:
     new 6904257b test: Assert valid excel file with expected column count 
(#945)
6904257b is described below

commit 6904257b04e077e6bcb9759c79e11112df7c9407
Author: Selim S. <[email protected]>
AuthorDate: Sat Jul 25 15:00:29 2026 +0200

    test: Assert valid excel file with expected column count (#945)
---
 .../fesod/sheet/examples/ExampleTestBase.java      | 37 ++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git 
a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/ExampleTestBase.java
 
b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/ExampleTestBase.java
index 479ebe7e..d633a4af 100644
--- 
a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/ExampleTestBase.java
+++ 
b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/ExampleTestBase.java
@@ -26,6 +26,8 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.nio.file.Path;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 
@@ -68,7 +70,7 @@ public abstract class ExampleTestBase {
      * Assert that the given file is a valid Excel workbook with at least the 
specified number of
      * data rows (excluding header).
      *
-     * @param file the Excel file to validate
+     * @param file        the Excel file to validate
      * @param minDataRows the minimum number of data rows expected (excluding 
header row)
      */
     protected static void assertValidExcelFile(File file, int minDataRows) {
@@ -87,10 +89,41 @@ public abstract class ExampleTestBase {
         }
     }
 
+    /**
+     * Assert that the given file is a valid Excel workbook with at least the 
specified number of
+     * columns, scanning for the first non-empty row to determine the column 
count.
+     *
+     * @param file       the Excel file to validate
+     * @param minColumns the minimum number of columns expected
+     */
+    protected static void assertValidExcelFileColumns(File file, int 
minColumns) {
+        int totalColumns = 0;
+        assertValidExcelFile(file);
+
+        try (FileInputStream fis = new FileInputStream(file);
+                Workbook workbook = WorkbookFactory.create(fis)) {
+            Sheet sheet = workbook.getSheetAt(0);
+            // find which row is not empty
+            for (int i = 0; i <= sheet.getLastRowNum(); i++) {
+                Row row = sheet.getRow(i);
+                if (row != null && row.getPhysicalNumberOfCells() > 0) {
+                    totalColumns = row.getLastCellNum();
+                    break;
+                }
+            }
+            assertTrue(
+                    totalColumns >= minColumns,
+                    "Expected at least " + minColumns + " columns, but found " 
+ totalColumns
+                            + " total columns in the first data row of: " + 
file.getAbsolutePath());
+        } catch (IOException e) {
+            fail("Failed to read workbook for column count verification: " + 
e.getMessage());
+        }
+    }
+
     /**
      * Generate a temp output file path within the given directory.
      *
-     * @param tempDir the temporary directory (typically from {@code @TempDir})
+     * @param tempDir  the temporary directory (typically from {@code 
@TempDir})
      * @param fileName the desired filename
      * @return the absolute path as a String
      */


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to