bengbengbalabalabeng commented on code in PR #901:
URL: https://github.com/apache/fesod/pull/901#discussion_r3458575131
##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/template/TemplateDataTest.java:
##########
@@ -25,73 +25,45 @@
package org.apache.fesod.sheet.template;
+import static org.apache.fesod.sheet.testkit.params.FormatCapability.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
-import java.util.ArrayList;
import java.util.List;
import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.testkit.Tags;
+import org.apache.fesod.sheet.testkit.base.AbstractExcelTest;
+import org.apache.fesod.sheet.testkit.builders.TestDataBuilder;
+import org.apache.fesod.sheet.testkit.enums.ExcelFormat;
+import org.apache.fesod.sheet.testkit.params.ExcelFormatSource;
+import org.apache.fesod.sheet.testkit.params.FormatScope;
import org.apache.fesod.sheet.util.TestFileUtil;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.MethodOrderer;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.params.ParameterizedTest;
/**
- *
+ * Test template write/read for binary Excel formats using parameterized tests.
*/
-@TestMethodOrder(MethodOrderer.MethodName.class)
-public class TemplateDataTest {
-
- private static File file07;
- private static File file03;
-
- @BeforeAll
- public static void init() {
- file07 = TestFileUtil.createNewFile("template07.xlsx");
- file03 = TestFileUtil.createNewFile("template03.xls");
- }
-
- @Test
- public void t01ReadAndWrite07() {
- readAndWrite07(file07);
- }
-
- @Test
- public void t02ReadAndWrite03() {
- readAndWrite03(file03);
- }
+@Tag(Tags.ROUND_TRIP)
+public class TemplateDataTest extends AbstractExcelTest {
- private void readAndWrite07(File file) {
+ @ParameterizedTest
+ @ExcelFormatSource(value = FormatScope.BINARY, requires = TEMPLATES)
+ void readAndWrite(ExcelFormat format) throws Exception {
+ File file = createTempFile("template", format);
+ String templateName = "template" + File.separator + "template" +
(format == ExcelFormat.XLSX ? "07" : "03")
+ + format.getExtension();
+ File template = TestFileUtil.readFile(templateName);
Review Comment:
The File path resolved by `TestFileUtil.readFile()` is
`file:/Users/.../META-INF/versions/9/template/template07.xlsx`. This type of
path does not correspond to a real file, and running tests locally (on macOS)
will fail.
Could we either obtain the `InputStream` via `getResourceAsStream` for use,
or write the stream into a TempDir and then return a File for use?
Additionally, since the usage of `TestFileUtil` is limited to unit testing
and only the `readFile()` method is utilized, it is recommended to refactor
`readFile()` into an internal utility method within `AbstractExcelTest` and
remove `TestFileUtil`.
```java
protected File readFile(String name) throws IOException {
Path target = tempDir.toPath().resolve(name);
Files.createDirectories(target.getParent());
try (InputStream inputStream =
getClass().getClassLoader().getResourceAsStream(name)) {
Files.copy(inputStream, target, StandardCopyOption.REPLACE_EXISTING);
return target.toFile();
}
}
```
--
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]