Browse Source

升级junit

pull/3168/head
Jiaju Zhuang 2 years ago
parent
commit
07167642d4
  1. 5
      easyexcel-test/pom.xml
  2. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataListener.java
  3. 44
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java
  4. 18
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataListener.java
  5. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java
  6. 43
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/bom/BomDataTest.java
  7. 44
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/cache/CacheDataTest.java
  8. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataListener.java
  9. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java
  10. 24
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/charset/CharsetDataTest.java
  11. 53
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityTest.java
  12. 36
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataListener.java
  13. 15
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java
  14. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterTest.java
  15. 82
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java
  16. 22
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java
  17. 16
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataListener.java
  18. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataTest.java
  19. 16
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/exception/ExceptionDataListener.java
  20. 18
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/exception/ExceptionDataTest.java
  21. 69
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java
  22. 36
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataListener.java
  23. 24
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java
  24. 32
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java
  25. 36
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java
  26. 262
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleAnnotatedTest.java
  27. 260
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleDataTest.java
  28. 314
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandler.java
  29. 16
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandlerTest.java
  30. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ComplexDataListener.java
  31. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ComplexHeadDataTest.java
  32. 18
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ListHeadDataListener.java
  33. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ListHeadDataTest.java
  34. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/NoHeadDataListener.java
  35. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/NoHeadDataTest.java
  36. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataListener.java
  37. 22
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java
  38. 16
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java
  39. 10
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsListener.java
  40. 54
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java
  41. 28
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataListener.java
  42. 13
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataTest.java
  43. 16
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataListener.java
  44. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java
  45. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataListener.java
  46. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java
  47. 18
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataListener.java
  48. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataSheetNameListener.java
  49. 25
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java
  50. 26
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/skip/SkipDataTest.java
  51. 23
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataListener.java
  52. 42
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataTest.java
  53. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataListener.java
  54. 44
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java
  55. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataListener.java
  56. 14
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java
  57. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java
  58. 7
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/rare/WriteTest.java
  59. 7
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/DemoExtraListener.java
  60. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java
  61. 1
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/ImageDataWithAnnotation.java
  62. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
  63. 2
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/DemoData3.java
  64. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java
  65. 19
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
  66. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java
  67. 8
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java
  68. 1
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleData.java
  69. 11
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java
  70. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java
  71. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteV33Test.java
  72. 23
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteV34Test.java
  73. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java
  74. 9
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/bug/ExcelCreat.java
  75. 2
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/bug/HeadType.java
  76. 13
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/cache/CacheTest.java
  77. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java
  78. 2
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/data/HeadType.java
  79. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java
  80. 162
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java
  81. 9
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java
  82. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java
  83. 10
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java
  84. 26
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue2443/Issue2443Test.java
  85. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/LargeDataListener.java
  86. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/NoModelLargeDataListener.java
  87. 19
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java
  88. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi2Test.java
  89. 9
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java
  90. 10
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiEncryptTest.java
  91. 5
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiFormatTest.java
  92. 9
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java
  93. 10
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java
  94. 11
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java
  95. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HDListener.java
  96. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadListener.java
  97. 2
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadData.java
  98. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
  99. 23
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java
  100. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/simple/RepeatListener.java
  101. Some files were not shown because too many files have changed in this diff Show More

5
easyexcel-test/pom.xml

@ -40,11 +40,6 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<version>2.7.11</version> <version>2.7.11</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<!-- logback --> <!-- logback -->
<dependency> <dependency>

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataListener.java

@ -4,16 +4,16 @@ import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelCommonException; import com.alibaba.excel.exception.ExcelCommonException;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -28,14 +28,14 @@ public class AnnotationDataListener extends AnalysisEventListener<AnnotationData
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
AnnotationData data = list.get(0); AnnotationData data = list.get(0);
try { try {
Assert.assertEquals(data.getDate(), DateUtils.parseDate("2020-01-01 01:01:01")); Assertions.assertEquals(data.getDate(), DateUtils.parseDate("2020-01-01 01:01:01"));
} catch (ParseException e) { } catch (ParseException e) {
throw new ExcelCommonException("Test Exception", e); throw new ExcelCommonException("Test Exception", e);
} }
Assert.assertEquals(data.getNumber(), 99.99, 0.00); Assertions.assertEquals(data.getNumber(), 99.99, 0.00);
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

44
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java

@ -14,16 +14,16 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class AnnotationDataTest { public class AnnotationDataTest {
private static File file07; private static File file07;
@ -32,7 +32,7 @@ public class AnnotationDataTest {
private static File fileStyle07; private static File fileStyle07;
private static File fileStyle03; private static File fileStyle03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("annotation07.xlsx"); file07 = TestFileUtil.createNewFile("annotation07.xlsx");
file03 = TestFileUtil.createNewFile("annotation03.xls"); file03 = TestFileUtil.createNewFile("annotation03.xls");
@ -74,24 +74,24 @@ public class AnnotationDataTest {
Row row0 = sheet.getRow(0); Row row0 = sheet.getRow(0);
Cell cell00 = row0.getCell(0); Cell cell00 = row0.getCell(0);
Assert.assertArrayEquals(new byte[] {-1, 0, -1}, StyleTestUtils.getFillForegroundColor(cell00)); Assertions.assertArrayEquals(new byte[] {-1, 0, -1}, StyleTestUtils.getFillForegroundColor(cell00));
Assert.assertArrayEquals(new byte[] {-1, -52, 0}, StyleTestUtils.getFontColor(cell00, workbook)); Assertions.assertArrayEquals(new byte[] {-1, -52, 0}, StyleTestUtils.getFontColor(cell00, workbook));
Assert.assertEquals(40, StyleTestUtils.getFontHeightInPoints(cell00, workbook)); Assertions.assertEquals(40, StyleTestUtils.getFontHeightInPoints(cell00, workbook));
Cell cell01 = row0.getCell(1); Cell cell01 = row0.getCell(1);
Assert.assertArrayEquals(new byte[] {-1, 0, 0}, StyleTestUtils.getFillForegroundColor(cell01)); Assertions.assertArrayEquals(new byte[] {-1, 0, 0}, StyleTestUtils.getFillForegroundColor(cell01));
Assert.assertArrayEquals(new byte[] {0, -1, -1}, StyleTestUtils.getFontColor(cell01, workbook)); Assertions.assertArrayEquals(new byte[] {0, -1, -1}, StyleTestUtils.getFontColor(cell01, workbook));
Assert.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell01, workbook)); Assertions.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell01, workbook));
Row row1 = sheet.getRow(1); Row row1 = sheet.getRow(1);
Cell cell10 = row1.getCell(0); Cell cell10 = row1.getCell(0);
Assert.assertArrayEquals(new byte[] {0, -52, -1}, StyleTestUtils.getFillForegroundColor(cell10)); Assertions.assertArrayEquals(new byte[] {0, -52, -1}, StyleTestUtils.getFillForegroundColor(cell10));
Assert.assertArrayEquals(new byte[] {0, 0, -1}, StyleTestUtils.getFontColor(cell10, workbook)); Assertions.assertArrayEquals(new byte[] {0, 0, -1}, StyleTestUtils.getFontColor(cell10, workbook));
Assert.assertEquals(50, StyleTestUtils.getFontHeightInPoints(cell10, workbook)); Assertions.assertEquals(50, StyleTestUtils.getFontHeightInPoints(cell10, workbook));
Cell cell11 = row1.getCell(1); Cell cell11 = row1.getCell(1);
Assert.assertArrayEquals(new byte[] {0, -128, 0}, StyleTestUtils.getFillForegroundColor(cell11)); Assertions.assertArrayEquals(new byte[] {0, -128, 0}, StyleTestUtils.getFillForegroundColor(cell11));
Assert.assertArrayEquals(new byte[] {-64, -64, -64}, StyleTestUtils.getFontColor(cell11, workbook)); Assertions.assertArrayEquals(new byte[] {-64, -64, -64}, StyleTestUtils.getFontColor(cell11, workbook));
Assert.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell11, workbook)); Assertions.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell11, workbook));
} }
private void readAndWrite(File file) throws Exception { private void readAndWrite(File file) throws Exception {
@ -103,13 +103,13 @@ public class AnnotationDataTest {
Workbook workbook = WorkbookFactory.create(file); Workbook workbook = WorkbookFactory.create(file);
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
Assert.assertEquals(50 * 256, sheet.getColumnWidth(0), 0); Assertions.assertEquals(50 * 256, sheet.getColumnWidth(0), 0);
Row row0 = sheet.getRow(0); Row row0 = sheet.getRow(0);
Assert.assertEquals(1000, row0.getHeight(), 0); Assertions.assertEquals(1000, row0.getHeight(), 0);
Row row1 = sheet.getRow(1); Row row1 = sheet.getRow(1);
Assert.assertEquals(2000, row1.getHeight(), 0); Assertions.assertEquals(2000, row1.getHeight(), 0);
} }
private List<AnnotationStyleData> dataStyle() throws Exception { private List<AnnotationStyleData> dataStyle() throws Exception {

18
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.annotation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -25,12 +25,12 @@ public class AnnotationIndexAndNameDataListener extends AnalysisEventListener<An
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
AnnotationIndexAndNameData data = list.get(0); AnnotationIndexAndNameData data = list.get(0);
Assert.assertEquals(data.getIndex0(), "第0个"); Assertions.assertEquals(data.getIndex0(), "第0个");
Assert.assertEquals(data.getIndex1(), "第1个"); Assertions.assertEquals(data.getIndex1(), "第1个");
Assert.assertEquals(data.getIndex2(), "第2个"); Assertions.assertEquals(data.getIndex2(), "第2个");
Assert.assertEquals(data.getIndex4(), "第4个"); Assertions.assertEquals(data.getIndex4(), "第4个");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java

@ -7,24 +7,24 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* Annotation data test * Annotation data test
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class AnnotationIndexAndNameDataTest { public class AnnotationIndexAndNameDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("annotationIndexAndName07.xlsx"); file07 = TestFileUtil.createNewFile("annotationIndexAndName07.xlsx");
file03 = TestFileUtil.createNewFile("annotationIndexAndName03.xls"); file03 = TestFileUtil.createNewFile("annotationIndexAndName03.xls");

43
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/bom/BomDataTest.java

@ -1,37 +1,32 @@
package com.alibaba.easyexcel.test.core.bom; package com.alibaba.easyexcel.test.core.bom;
import com.alibaba.easyexcel.test.core.simple.SimpleData; import java.io.File;
import com.alibaba.easyexcel.test.demo.read.DemoData; import java.io.FileOutputStream;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.util.ListUtils; import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists; import org.apache.commons.compress.utils.Lists;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/** /**
* bom test * bom test
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
@Slf4j @Slf4j
public class BomDataTest { public class BomDataTest {
@ -72,7 +67,7 @@ public class BomDataTest {
@Override @Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) { public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
String head = headMap.get(0).getStringValue(); String head = headMap.get(0).getStringValue();
Assert.assertEquals("姓名", head); Assertions.assertEquals("姓名", head);
} }
@Override @Override
@ -82,10 +77,10 @@ public class BomDataTest {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(dataList.size(), 10); Assertions.assertEquals(dataList.size(), 10);
BomData bomData = dataList.get(0); BomData bomData = dataList.get(0);
Assert.assertEquals("姓名0", bomData.getName()); Assertions.assertEquals("姓名0", bomData.getName());
Assert.assertEquals(20, (long)bomData.getAge()); Assertions.assertEquals(20, (long)bomData.getAge());
} }
}) })
.charset(charset) .charset(charset)
@ -100,7 +95,7 @@ public class BomDataTest {
@Override @Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) { public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
String head = headMap.get(0).getStringValue(); String head = headMap.get(0).getStringValue();
Assert.assertEquals("姓名", head); Assertions.assertEquals("姓名", head);
} }
@Override @Override
@ -110,10 +105,10 @@ public class BomDataTest {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(dataList.size(), 10); Assertions.assertEquals(dataList.size(), 10);
BomData bomData = dataList.get(0); BomData bomData = dataList.get(0);
Assert.assertEquals("姓名0", bomData.getName()); Assertions.assertEquals("姓名0", bomData.getName());
Assert.assertEquals(20L, (long)bomData.getAge()); Assertions.assertEquals(20L, (long)bomData.getAge());
} }
}).sheet().doRead(); }).sheet().doRead();
} }

44
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/cache/CacheDataTest.java vendored

@ -21,16 +21,16 @@ import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.FieldUtils; import com.alibaba.excel.util.FieldUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
@Slf4j @Slf4j
public class CacheDataTest { public class CacheDataTest {
@ -40,7 +40,7 @@ public class CacheDataTest {
private static File fileCacheInvokeMemory; private static File fileCacheInvokeMemory;
private static File fileCacheInvokeMemory2; private static File fileCacheInvokeMemory2;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("cache/cache.xlsx"); file07 = TestFileUtil.createNewFile("cache/cache.xlsx");
fileCacheInvoke = TestFileUtil.createNewFile("cache/fileCacheInvoke.xlsx"); fileCacheInvoke = TestFileUtil.createNewFile("cache/fileCacheInvoke.xlsx");
@ -54,14 +54,14 @@ public class CacheDataTest {
Field field = FieldUtils.getField(ClassUtils.class, "FIELD_THREAD_LOCAL", true); Field field = FieldUtils.getField(ClassUtils.class, "FIELD_THREAD_LOCAL", true);
ThreadLocal<Map<Class<?>, FieldCache>> fieldThreadLocal = (ThreadLocal<Map<Class<?>, FieldCache>>)field.get( ThreadLocal<Map<Class<?>, FieldCache>> fieldThreadLocal = (ThreadLocal<Map<Class<?>, FieldCache>>)field.get(
ClassUtils.class.newInstance()); ClassUtils.class.newInstance());
Assert.assertNull(fieldThreadLocal.get()); Assertions.assertNull(fieldThreadLocal.get());
EasyExcel.write(file07, CacheData.class).sheet().doWrite(data()); EasyExcel.write(file07, CacheData.class).sheet().doWrite(data());
EasyExcel.read(file07, CacheData.class, new PageReadListener<DemoData>(dataList -> { EasyExcel.read(file07, CacheData.class, new PageReadListener<DemoData>(dataList -> {
Assert.assertNotNull(fieldThreadLocal.get()); Assertions.assertNotNull(fieldThreadLocal.get());
})) }))
.sheet() .sheet()
.doRead(); .doRead();
Assert.assertNull(fieldThreadLocal.get()); Assertions.assertNull(fieldThreadLocal.get());
} }
@Test @Test
@ -71,9 +71,9 @@ public class CacheDataTest {
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
Assert.assertEquals(2, headMap.size()); Assertions.assertEquals(2, headMap.size());
Assert.assertEquals("姓名", headMap.get(0)); Assertions.assertEquals("姓名", headMap.get(0));
Assert.assertEquals("年龄", headMap.get(1)); Assertions.assertEquals("年龄", headMap.get(1));
} }
@Override @Override
@ -100,9 +100,9 @@ public class CacheDataTest {
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
Assert.assertEquals(2, headMap.size()); Assertions.assertEquals(2, headMap.size());
Assert.assertEquals("姓名2", headMap.get(0)); Assertions.assertEquals("姓名2", headMap.get(0));
Assert.assertEquals("年龄", headMap.get(1)); Assertions.assertEquals("年龄", headMap.get(1));
} }
@Override @Override
@ -129,9 +129,9 @@ public class CacheDataTest {
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
Assert.assertEquals(2, headMap.size()); Assertions.assertEquals(2, headMap.size());
Assert.assertEquals("姓名", headMap.get(0)); Assertions.assertEquals("姓名", headMap.get(0));
Assert.assertEquals("年龄", headMap.get(1)); Assertions.assertEquals("年龄", headMap.get(1));
} }
@Override @Override
@ -164,9 +164,9 @@ public class CacheDataTest {
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
Assert.assertEquals(2, headMap.size()); Assertions.assertEquals(2, headMap.size());
Assert.assertEquals("姓名", headMap.get(0)); Assertions.assertEquals("姓名", headMap.get(0));
Assert.assertEquals("年龄", headMap.get(1)); Assertions.assertEquals("年龄", headMap.get(1));
} }
@Override @Override

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataListener.java

@ -8,7 +8,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -26,16 +26,16 @@ public class CellDataDataListener extends AnalysisEventListener<CellDataReadData
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
CellDataReadData cellDataData = list.get(0); CellDataReadData cellDataData = list.get(0);
Assert.assertEquals("2020年01月01日", cellDataData.getDate().getData()); Assertions.assertEquals("2020年01月01日", cellDataData.getDate().getData());
Assert.assertEquals((long)cellDataData.getInteger1().getData(), 2L); Assertions.assertEquals((long)cellDataData.getInteger1().getData(), 2L);
Assert.assertEquals((long)cellDataData.getInteger2(), 2L); Assertions.assertEquals((long)cellDataData.getInteger2(), 2L);
if (context.readWorkbookHolder().getExcelType() != ExcelTypeEnum.CSV) { if (context.readWorkbookHolder().getExcelType() != ExcelTypeEnum.CSV) {
Assert.assertEquals(cellDataData.getFormulaValue().getFormulaData().getFormulaValue(), "B2+C2"); Assertions.assertEquals(cellDataData.getFormulaValue().getFormulaData().getFormulaValue(), "B2+C2");
} else { } else {
Assert.assertNull(cellDataData.getFormulaValue().getData()); Assertions.assertNull(cellDataData.getFormulaValue().getData());
} }
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java

@ -12,23 +12,22 @@ import com.alibaba.excel.metadata.data.FormulaData;
import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class CellDataDataTest { public class CellDataDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeAll
@BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("cellData07.xlsx"); file07 = TestFileUtil.createNewFile("cellData07.xlsx");
file03 = TestFileUtil.createNewFile("cellData03.xls"); file03 = TestFileUtil.createNewFile("cellData03.xls");
@ -50,7 +49,6 @@ public class CellDataDataTest {
readAndWrite(fileCsv); readAndWrite(fileCsv);
} }
private void readAndWrite(File file) throws Exception { private void readAndWrite(File file) throws Exception {
EasyExcel.write(file, CellDataWriteData.class).sheet().doWrite(data()); EasyExcel.write(file, CellDataWriteData.class).sheet().doWrite(data());
EasyExcel.read(file, CellDataReadData.class, new CellDataDataListener()).sheet().doRead(); EasyExcel.read(file, CellDataReadData.class, new CellDataDataListener()).sheet().doRead();

24
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/charset/CharsetDataTest.java

@ -14,11 +14,11 @@ import com.alibaba.excel.read.listener.ReadListener;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists; import org.apache.commons.compress.utils.Lists;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* charset * charset
@ -26,14 +26,14 @@ import org.junit.runners.MethodSorters;
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Slf4j @Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class CharsetDataTest { public class CharsetDataTest {
private static final Charset GBK = Charset.forName("GBK"); private static final Charset GBK = Charset.forName("GBK");
private static File fileCsvGbk; private static File fileCsvGbk;
private static File fileCsvUtf8; private static File fileCsvUtf8;
private static File fileCsvError; private static File fileCsvError;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
fileCsvGbk = TestFileUtil.createNewFile("charset" + File.separator + "fileCsvGbk.csv"); fileCsvGbk = TestFileUtil.createNewFile("charset" + File.separator + "fileCsvGbk.csv");
fileCsvUtf8 = TestFileUtil.createNewFile("charset" + File.separator + "fileCsvUtf8.csv"); fileCsvUtf8 = TestFileUtil.createNewFile("charset" + File.separator + "fileCsvUtf8.csv");
@ -56,7 +56,7 @@ public class CharsetDataTest {
@Override @Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) { public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
String head = headMap.get(0).getStringValue(); String head = headMap.get(0).getStringValue();
Assert.assertNotEquals("姓名", head); Assertions.assertNotEquals("姓名", head);
} }
@Override @Override
@ -79,7 +79,7 @@ public class CharsetDataTest {
@Override @Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) { public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
String head = headMap.get(0).getStringValue(); String head = headMap.get(0).getStringValue();
Assert.assertEquals("姓名", head); Assertions.assertEquals("姓名", head);
} }
@Override @Override
@ -89,10 +89,10 @@ public class CharsetDataTest {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(dataList.size(), 10); Assertions.assertEquals(dataList.size(), 10);
CharsetData charsetData = dataList.get(0); CharsetData charsetData = dataList.get(0);
Assert.assertEquals("姓名0", charsetData.getName()); Assertions.assertEquals("姓名0", charsetData.getName());
Assert.assertEquals(0, (long)charsetData.getAge()); Assertions.assertEquals(0, (long)charsetData.getAge());
} }
}).charset(charset).sheet().doRead(); }).charset(charset).sheet().doRead();
} }

53
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityTest.java

@ -6,30 +6,27 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.alibaba.easyexcel.test.core.large.LargeData;
import com.alibaba.easyexcel.test.core.large.LargeDataListener;
import com.alibaba.easyexcel.test.core.simple.SimpleData; import com.alibaba.easyexcel.test.core.simple.SimpleData;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.cache.Ehcache; import com.alibaba.excel.cache.Ehcache;
import com.alibaba.excel.constant.EasyExcelConstants;
import com.alibaba.excel.enums.ReadDefaultReturnEnum; import com.alibaba.excel.enums.ReadDefaultReturnEnum;
import com.alibaba.excel.util.FileUtils; import com.alibaba.excel.util.FileUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* Compatible with some special files * Compatible with some special files
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
@Slf4j @Slf4j
public class CompatibilityTest { public class CompatibilityTest {
@ -38,9 +35,9 @@ public class CompatibilityTest {
// https://github.com/alibaba/easyexcel/issues/2236 // https://github.com/alibaba/easyexcel/issues/2236
List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t01.xls").sheet() List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t01.xls").sheet()
.doReadSync(); .doReadSync();
Assert.assertEquals(2, list.size()); Assertions.assertEquals(2, list.size());
Map<Integer, Object> row1 = list.get(1); Map<Integer, Object> row1 = list.get(1);
Assert.assertEquals("Q235(碳钢)", row1.get(0)); Assertions.assertEquals("Q235(碳钢)", row1.get(0));
} }
@Test @Test
@ -49,9 +46,9 @@ public class CompatibilityTest {
List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t02.xlsx").sheet() List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t02.xlsx").sheet()
.headRowNumber(0).doReadSync(); .headRowNumber(0).doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals(3, list.size()); Assertions.assertEquals(3, list.size());
Map<Integer, Object> row2 = list.get(2); Map<Integer, Object> row2 = list.get(2);
Assert.assertEquals("1,2-戊二醇", row2.get(2)); Assertions.assertEquals("1,2-戊二醇", row2.get(2));
} }
@Test @Test
@ -60,9 +57,9 @@ public class CompatibilityTest {
List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t03.xlsx").sheet() List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t03.xlsx").sheet()
.doReadSync(); .doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals(1, list.size()); Assertions.assertEquals(1, list.size());
Map<Integer, Object> row0 = list.get(0); Map<Integer, Object> row0 = list.get(0);
Assert.assertEquals(12, row0.size()); Assertions.assertEquals(12, row0.size());
} }
@Test @Test
@ -71,9 +68,9 @@ public class CompatibilityTest {
List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t04.xlsx").sheet() List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t04.xlsx").sheet()
.doReadSync(); .doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals(56, list.size()); Assertions.assertEquals(56, list.size());
Map<Integer, Object> row0 = list.get(0); Map<Integer, Object> row0 = list.get(0);
Assert.assertEquals("QQSJK28F152A012242S0081", row0.get(5)); Assertions.assertEquals("QQSJK28F152A012242S0081", row0.get(5));
} }
@Test @Test
@ -85,11 +82,11 @@ public class CompatibilityTest {
.sheet() .sheet()
.doReadSync(); .doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals("2023-01-01 00:00:00", list.get(0).get(0)); Assertions.assertEquals("2023-01-01 00:00:00", list.get(0).get(0));
Assert.assertEquals("2023-01-01 00:00:00", list.get(1).get(0)); Assertions.assertEquals("2023-01-01 00:00:00", list.get(1).get(0));
Assert.assertEquals("2023-01-01 00:00:00", list.get(2).get(0)); Assertions.assertEquals("2023-01-01 00:00:00", list.get(2).get(0));
Assert.assertEquals("2023-01-01 00:00:01", list.get(3).get(0)); Assertions.assertEquals("2023-01-01 00:00:01", list.get(3).get(0));
Assert.assertEquals("2023-01-01 00:00:01", list.get(4).get(0)); Assertions.assertEquals("2023-01-01 00:00:01", list.get(4).get(0));
} }
@Test @Test
@ -101,7 +98,7 @@ public class CompatibilityTest {
.sheet() .sheet()
.doReadSync(); .doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals("2087.03", list.get(0).get(2)); Assertions.assertEquals("2087.03", list.get(0).get(2));
} }
@Test @Test
@ -114,14 +111,14 @@ public class CompatibilityTest {
.sheet() .sheet()
.doReadSync(); .doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals(0, new BigDecimal("24.1998124").compareTo((BigDecimal)list.get(0).get(11))); Assertions.assertEquals(0, new BigDecimal("24.1998124").compareTo((BigDecimal)list.get(0).get(11)));
list = EasyExcel list = EasyExcel
.read(TestFileUtil.getPath() + "compatibility/t07.xlsx") .read(TestFileUtil.getPath() + "compatibility/t07.xlsx")
.sheet() .sheet()
.doReadSync(); .doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals("24.20", list.get(0).get(11)); Assertions.assertEquals("24.20", list.get(0).get(11));
} }
@Test @Test
@ -137,7 +134,7 @@ public class CompatibilityTest {
.readCache(new Ehcache(null, 20)) .readCache(new Ehcache(null, 20))
.sheet() .sheet()
.doReadSync(); .doReadSync();
Assert.assertEquals(10L, list.size()); Assertions.assertEquals(10L, list.size());
FileUtils.delete(new File(System.getProperty(TempFile.JAVA_IO_TMPDIR))); FileUtils.delete(new File(System.getProperty(TempFile.JAVA_IO_TMPDIR)));
@ -145,7 +142,7 @@ public class CompatibilityTest {
.readCache(new Ehcache(null, 20)) .readCache(new Ehcache(null, 20))
.sheet() .sheet()
.doReadSync(); .doReadSync();
Assert.assertEquals(10L, list.size()); Assertions.assertEquals(10L, list.size());
} }
@Test @Test
@ -157,9 +154,9 @@ public class CompatibilityTest {
.sheet() .sheet()
.doReadSync(); .doReadSync();
log.info("data:{}", JSON.toJSONString(list)); log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals(1, list.size()); Assertions.assertEquals(1, list.size());
Assert.assertEquals("SH_x000D_Z002", list.get(0).get(0)); Assertions.assertEquals("SH_x000D_Z002", list.get(0).get(0));
} }
private List<SimpleData> data() { private List<SimpleData> data() {

36
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataListener.java

@ -2,19 +2,15 @@ package com.alibaba.easyexcel.test.core.converter;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.ParseException;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.alibaba.easyexcel.test.util.TestUtil; import com.alibaba.easyexcel.test.util.TestUtil;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelCommonException;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,22 +28,22 @@ public class ConverterDataListener extends AnalysisEventListener<ConverterReadDa
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
ConverterReadData data = list.get(0); ConverterReadData data = list.get(0);
Assert.assertEquals(TestUtil.TEST_DATE, data.getDate()); Assertions.assertEquals(TestUtil.TEST_DATE, data.getDate());
Assert.assertEquals(TestUtil.TEST_LOCAL_DATE, data.getLocalDate()); Assertions.assertEquals(TestUtil.TEST_LOCAL_DATE, data.getLocalDate());
Assert.assertEquals(TestUtil.TEST_LOCAL_DATE_TIME, data.getLocalDateTime()); Assertions.assertEquals(TestUtil.TEST_LOCAL_DATE_TIME, data.getLocalDateTime());
Assert.assertEquals(data.getBooleanData(), Boolean.TRUE); Assertions.assertEquals(data.getBooleanData(), Boolean.TRUE);
Assert.assertEquals(data.getBigDecimal().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0); Assertions.assertEquals(data.getBigDecimal().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0);
Assert.assertEquals(data.getBigInteger().intValue(), BigInteger.ONE.intValue(), 0.0); Assertions.assertEquals(data.getBigInteger().intValue(), BigInteger.ONE.intValue(), 0.0);
Assert.assertEquals((long)data.getLongData(), 1L); Assertions.assertEquals((long)data.getLongData(), 1L);
Assert.assertEquals((long)data.getIntegerData(), 1L); Assertions.assertEquals((long)data.getIntegerData(), 1L);
Assert.assertEquals((long)data.getShortData(), 1L); Assertions.assertEquals((long)data.getShortData(), 1L);
Assert.assertEquals((long)data.getByteData(), 1L); Assertions.assertEquals((long)data.getByteData(), 1L);
Assert.assertEquals(data.getDoubleData(), 1.0, 0.0); Assertions.assertEquals(data.getDoubleData(), 1.0, 0.0);
Assert.assertEquals(data.getFloatData(), (float)1.0, 0.0); Assertions.assertEquals(data.getFloatData(), (float)1.0, 0.0);
Assert.assertEquals(data.getString(), "测试"); Assertions.assertEquals(data.getString(), "测试");
Assert.assertEquals(data.getCellData().getStringValue(), "自定义"); Assertions.assertEquals(data.getCellData().getStringValue(), "自定义");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

15
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java

@ -4,8 +4,6 @@ import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -13,18 +11,17 @@ import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.easyexcel.test.util.TestUtil; import com.alibaba.easyexcel.test.util.TestUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.FileUtils; import com.alibaba.excel.util.FileUtils;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class ConverterDataTest { public class ConverterDataTest {
private static File file07; private static File file07;
@ -33,7 +30,7 @@ public class ConverterDataTest {
private static File fileImage07; private static File fileImage07;
private static File fileImage03; private static File fileImage03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("converter07.xlsx"); file07 = TestFileUtil.createNewFile("converter07.xlsx");
file03 = TestFileUtil.createNewFile("converter03.xls"); file03 = TestFileUtil.createNewFile("converter03.xls");

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterTest.java

@ -6,15 +6,15 @@ import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.converters.floatconverter.FloatNumberConverter; import com.alibaba.excel.converters.floatconverter.FloatNumberConverter;
import com.alibaba.excel.metadata.data.WriteCellData; import com.alibaba.excel.metadata.data.WriteCellData;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class ConverterTest { public class ConverterTest {
@Test @Test
@ -23,7 +23,7 @@ public class ConverterTest {
WriteConverterContext<Float> context = new WriteConverterContext<>(); WriteConverterContext<Float> context = new WriteConverterContext<>();
context.setValue(95.62F); context.setValue(95.62F);
WriteCellData<?> writeCellData = floatNumberConverter.convertToExcelData(context); WriteCellData<?> writeCellData = floatNumberConverter.convertToExcelData(context);
Assert.assertEquals(0, writeCellData.getNumberValue().compareTo(new BigDecimal("95.62"))); Assertions.assertEquals(0, writeCellData.getNumberValue().compareTo(new BigDecimal("95.62")));
} }
} }

82
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ReadAllConverterDataListener.java

@ -13,7 +13,7 @@ import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -31,54 +31,56 @@ public class ReadAllConverterDataListener extends AnalysisEventListener<ReadAllC
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
ReadAllConverterData data = list.get(0); ReadAllConverterData data = list.get(0);
Assert.assertEquals(data.getBigDecimalBoolean().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0); Assertions.assertEquals(data.getBigDecimalBoolean().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0);
Assert.assertEquals(data.getBigDecimalNumber().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0); Assertions.assertEquals(data.getBigDecimalNumber().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0);
Assert.assertEquals(data.getBigDecimalString().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0); Assertions.assertEquals(data.getBigDecimalString().doubleValue(), BigDecimal.ONE.doubleValue(), 0.0);
Assert.assertEquals(data.getBigIntegerBoolean().intValue(), BigInteger.ONE.intValue(), 0.0); Assertions.assertEquals(data.getBigIntegerBoolean().intValue(), BigInteger.ONE.intValue(), 0.0);
Assert.assertEquals(data.getBigIntegerNumber().intValue(), BigInteger.ONE.intValue(), 0.0); Assertions.assertEquals(data.getBigIntegerNumber().intValue(), BigInteger.ONE.intValue(), 0.0);
Assert.assertEquals(data.getBigIntegerString().intValue(), BigInteger.ONE.intValue(), 0.0); Assertions.assertEquals(data.getBigIntegerString().intValue(), BigInteger.ONE.intValue(), 0.0);
Assert.assertTrue(data.getBooleanBoolean()); Assertions.assertTrue(data.getBooleanBoolean());
Assert.assertTrue(data.getBooleanNumber()); Assertions.assertTrue(data.getBooleanNumber());
Assert.assertTrue(data.getBooleanString()); Assertions.assertTrue(data.getBooleanString());
Assert.assertEquals((long)data.getByteBoolean(), 1L); Assertions.assertEquals((long)data.getByteBoolean(), 1L);
Assert.assertEquals((long)data.getByteNumber(), 1L); Assertions.assertEquals((long)data.getByteNumber(), 1L);
Assert.assertEquals((long)data.getByteString(), 1L); Assertions.assertEquals((long)data.getByteString(), 1L);
try { try {
Assert.assertEquals(data.getDateNumber(), DateUtils.parseDate("2020-01-01 01:01:01")); Assertions.assertEquals(data.getDateNumber(), DateUtils.parseDate("2020-01-01 01:01:01"));
Assert.assertEquals(data.getDateString(), DateUtils.parseDate("2020-01-01 01:01:01")); Assertions.assertEquals(data.getDateString(), DateUtils.parseDate("2020-01-01 01:01:01"));
} catch (ParseException e) { } catch (ParseException e) {
throw new ExcelCommonException("Test Exception", e); throw new ExcelCommonException("Test Exception", e);
} }
Assert.assertEquals(data.getLocalDateTimeNumber(), DateUtils.parseLocalDateTime("2020-01-01 01:01:01", null, null)); Assertions.assertEquals(data.getLocalDateTimeNumber(),
Assert.assertEquals(data.getLocalDateTimeString(), DateUtils.parseLocalDateTime("2020-01-01 01:01:01", null, null)); DateUtils.parseLocalDateTime("2020-01-01 01:01:01", null, null));
Assert.assertEquals(data.getDoubleBoolean(), 1.0, 0.0); Assertions.assertEquals(data.getLocalDateTimeString(),
Assert.assertEquals(data.getDoubleNumber(), 1.0, 0.0); DateUtils.parseLocalDateTime("2020-01-01 01:01:01", null, null));
Assert.assertEquals(data.getDoubleString(), 1.0, 0.0); Assertions.assertEquals(data.getDoubleBoolean(), 1.0, 0.0);
Assert.assertEquals(data.getFloatBoolean(), (float)1.0, 0.0); Assertions.assertEquals(data.getDoubleNumber(), 1.0, 0.0);
Assert.assertEquals(data.getFloatNumber(), (float)1.0, 0.0); Assertions.assertEquals(data.getDoubleString(), 1.0, 0.0);
Assert.assertEquals(data.getFloatString(), (float)1.0, 0.0); Assertions.assertEquals(data.getFloatBoolean(), (float)1.0, 0.0);
Assert.assertEquals((long)data.getIntegerBoolean(), 1L); Assertions.assertEquals(data.getFloatNumber(), (float)1.0, 0.0);
Assert.assertEquals((long)data.getIntegerNumber(), 1L); Assertions.assertEquals(data.getFloatString(), (float)1.0, 0.0);
Assert.assertEquals((long)data.getIntegerString(), 1L); Assertions.assertEquals((long)data.getIntegerBoolean(), 1L);
Assert.assertEquals((long)data.getLongBoolean(), 1L); Assertions.assertEquals((long)data.getIntegerNumber(), 1L);
Assert.assertEquals((long)data.getLongNumber(), 1L); Assertions.assertEquals((long)data.getIntegerString(), 1L);
Assert.assertEquals((long)data.getLongString(), 1L); Assertions.assertEquals((long)data.getLongBoolean(), 1L);
Assert.assertEquals((long)data.getShortBoolean(), 1L); Assertions.assertEquals((long)data.getLongNumber(), 1L);
Assert.assertEquals((long)data.getShortNumber(), 1L); Assertions.assertEquals((long)data.getLongString(), 1L);
Assert.assertEquals((long)data.getShortString(), 1L); Assertions.assertEquals((long)data.getShortBoolean(), 1L);
Assert.assertEquals(data.getStringBoolean().toLowerCase(), "true"); Assertions.assertEquals((long)data.getShortNumber(), 1L);
Assert.assertEquals(data.getStringString(), "测试"); Assertions.assertEquals((long)data.getShortString(), 1L);
Assert.assertEquals(data.getStringError(), "#VALUE!"); Assertions.assertEquals(data.getStringBoolean().toLowerCase(), "true");
Assertions.assertEquals(data.getStringString(), "测试");
Assertions.assertEquals(data.getStringError(), "#VALUE!");
if (context.readWorkbookHolder().getExcelType() != ExcelTypeEnum.CSV) { if (context.readWorkbookHolder().getExcelType() != ExcelTypeEnum.CSV) {
Assert.assertEquals("2020-1-1 1:01", data.getStringNumberDate()); Assertions.assertEquals("2020-1-1 1:01", data.getStringNumberDate());
} else { } else {
Assert.assertEquals("2020-01-01 01:01:01", data.getStringNumberDate()); Assertions.assertEquals("2020-01-01 01:01:01", data.getStringNumberDate());
} }
double doubleStringFormulaNumber = new BigDecimal(data.getStringFormulaNumber()).doubleValue(); double doubleStringFormulaNumber = new BigDecimal(data.getStringFormulaNumber()).doubleValue();
Assert.assertEquals(doubleStringFormulaNumber, 2.0, 0.0); Assertions.assertEquals(doubleStringFormulaNumber, 2.0, 0.0);
Assert.assertEquals(data.getStringFormulaString(), "1测试"); Assertions.assertEquals(data.getStringFormulaString(), "1测试");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

22
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java

@ -8,23 +8,23 @@ import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
@Slf4j @Slf4j
public class DateFormatTest { public class DateFormatTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xlsx"); file07 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xlsx");
file03 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xls"); file03 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xls");
@ -54,8 +54,8 @@ public class DateFormatTest {
} }
} }
for (DateFormatData data : list) { for (DateFormatData data : list) {
Assert.assertEquals(data.getDateStringCn(), data.getDate()); Assertions.assertEquals(data.getDateStringCn(), data.getDate());
Assert.assertEquals(data.getNumberStringCn(), data.getNumber()); Assertions.assertEquals(data.getNumberStringCn(), data.getNumber());
} }
} }
@ -71,8 +71,8 @@ public class DateFormatTest {
} }
} }
for (DateFormatData data : list) { for (DateFormatData data : list) {
Assert.assertEquals(data.getDateStringUs(), data.getDate()); Assertions.assertEquals(data.getDateStringUs(), data.getDate());
Assert.assertEquals(data.getNumberStringUs(), data.getNumber()); Assertions.assertEquals(data.getNumberStringUs(), data.getNumber());
} }
} }
} }

16
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.encrypt;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -25,10 +25,10 @@ public class EncryptDataListener extends AnalysisEventListener<EncryptData> {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 10); Assertions.assertEquals(list.size(), 10);
Assert.assertEquals(list.get(0).getName(), "姓名0"); Assertions.assertEquals(list.get(0).getName(), "姓名0");
Assert.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0); Assertions.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0);
Assert.assertEquals( Assertions.assertEquals(
context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名"); context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataTest.java

@ -14,15 +14,15 @@ import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class EncryptDataTest { public class EncryptDataTest {
private static File file07; private static File file07;
@ -39,7 +39,7 @@ public class EncryptDataTest {
System.out.println(decimalFormat.format(bigDecimal)); System.out.println(decimalFormat.format(bigDecimal));
} }
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("encrypt07.xlsx"); file07 = TestFileUtil.createNewFile("encrypt07.xlsx");
file03 = TestFileUtil.createNewFile("encrypt03.xls"); file03 = TestFileUtil.createNewFile("encrypt03.xls");

16
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/exception/ExceptionDataListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.exception;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -38,10 +38,10 @@ public class ExceptionDataListener extends AnalysisEventListener<ExceptionData>
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 8); Assertions.assertEquals(list.size(), 8);
Assert.assertEquals(list.get(0).getName(), "姓名0"); Assertions.assertEquals(list.get(0).getName(), "姓名0");
Assert.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0); Assertions.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0);
Assert.assertEquals( Assertions.assertEquals(
context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名"); context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }

18
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/exception/ExceptionDataTest.java

@ -9,16 +9,16 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class ExceptionDataTest { public class ExceptionDataTest {
private static File file07; private static File file07;
@ -27,7 +27,7 @@ public class ExceptionDataTest {
private static File fileException03; private static File fileException03;
private static File fileCsv; private static File fileCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("exception.xlsx"); file07 = TestFileUtil.createNewFile("exception.xlsx");
file03 = TestFileUtil.createNewFile("exception.xls"); file03 = TestFileUtil.createNewFile("exception.xls");
@ -63,10 +63,10 @@ public class ExceptionDataTest {
private void readAndWriteException(File file) throws Exception { private void readAndWriteException(File file) throws Exception {
EasyExcel.write(new FileOutputStream(file), ExceptionData.class).sheet().doWrite(data()); EasyExcel.write(new FileOutputStream(file), ExceptionData.class).sheet().doWrite(data());
ArithmeticException exception = Assert.assertThrows(ArithmeticException.class, () -> EasyExcel.read( ArithmeticException exception = Assertions.assertThrows(ArithmeticException.class, () -> EasyExcel.read(
new FileInputStream(file), ExceptionData.class, new FileInputStream(file), ExceptionData.class,
new ExceptionThrowDataListener()).sheet().doRead()); new ExceptionThrowDataListener()).sheet().doRead());
Assert.assertEquals("/ by zero",exception.getMessage()); Assertions.assertEquals("/ by zero", exception.getMessage());
} }
private void readAndWrite(File file) throws Exception { private void readAndWrite(File file) throws Exception {

69
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java

@ -10,16 +10,16 @@ import java.util.Set;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class ExcludeOrIncludeDataTest { public class ExcludeOrIncludeDataTest {
private static File excludeIndex07; private static File excludeIndex07;
@ -42,7 +42,7 @@ public class ExcludeOrIncludeDataTest {
private static File includeFieldNameOrderIndex03; private static File includeFieldNameOrderIndex03;
private static File includeFieldNameOrderIndexCsv; private static File includeFieldNameOrderIndexCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
excludeIndex07 = TestFileUtil.createNewFile("excludeIndex.xlsx"); excludeIndex07 = TestFileUtil.createNewFile("excludeIndex.xlsx");
excludeIndex03 = TestFileUtil.createNewFile("excludeIndex.xls"); excludeIndex03 = TestFileUtil.createNewFile("excludeIndex.xls");
@ -94,7 +94,6 @@ public class ExcludeOrIncludeDataTest {
excludeFieldName(excludeFieldNameCsv); excludeFieldName(excludeFieldNameCsv);
} }
@Test @Test
public void t21IncludeIndex07() { public void t21IncludeIndex07() {
includeIndex(includeIndex07); includeIndex(includeIndex07);
@ -162,11 +161,11 @@ public class ExcludeOrIncludeDataTest {
EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnIndexes(excludeColumnIndexes).sheet() EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnIndexes(excludeColumnIndexes).sheet()
.doWrite(data()); .doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals(2, record.size()); Assertions.assertEquals(2, record.size());
Assert.assertEquals("column2", record.get(0)); Assertions.assertEquals("column2", record.get(0));
Assert.assertEquals("column3", record.get(1)); Assertions.assertEquals("column3", record.get(1));
} }
@ -178,10 +177,10 @@ public class ExcludeOrIncludeDataTest {
EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFieldNames(excludeColumnFieldNames).sheet() EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFieldNames(excludeColumnFieldNames).sheet()
.doWrite(data()); .doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals(1, record.size()); Assertions.assertEquals(1, record.size());
Assert.assertEquals("column2", record.get(0)); Assertions.assertEquals("column2", record.get(0));
} }
@ -192,11 +191,11 @@ public class ExcludeOrIncludeDataTest {
EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnIndexes(includeColumnIndexes).sheet() EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnIndexes(includeColumnIndexes).sheet()
.doWrite(data()); .doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals(2, record.size()); Assertions.assertEquals(2, record.size());
Assert.assertEquals("column2", record.get(0)); Assertions.assertEquals("column2", record.get(0));
Assert.assertEquals("column3", record.get(1)); Assertions.assertEquals("column3", record.get(1));
} }
@ -207,14 +206,13 @@ public class ExcludeOrIncludeDataTest {
EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFieldNames(includeColumnFieldNames).sheet() EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFieldNames(includeColumnFieldNames).sheet()
.doWrite(data()); .doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals(2, record.size()); Assertions.assertEquals(2, record.size());
Assert.assertEquals("column2", record.get(0)); Assertions.assertEquals("column2", record.get(0));
Assert.assertEquals("column3", record.get(1)); Assertions.assertEquals("column3", record.get(1));
} }
private void includeFieldNameOrderIndex(File file) { private void includeFieldNameOrderIndex(File file) {
List<Integer> includeColumnIndexes = new ArrayList<>(); List<Integer> includeColumnIndexes = new ArrayList<>();
includeColumnIndexes.add(3); includeColumnIndexes.add(3);
@ -227,14 +225,15 @@ public class ExcludeOrIncludeDataTest {
sheet() sheet()
.doWrite(data()); .doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals(4, record.size()); Assertions.assertEquals(4, record.size());
Assert.assertEquals("column4", record.get(0)); Assertions.assertEquals("column4", record.get(0));
Assert.assertEquals("column2", record.get(1)); Assertions.assertEquals("column2", record.get(1));
Assert.assertEquals("column3", record.get(2)); Assertions.assertEquals("column3", record.get(2));
Assert.assertEquals("column1", record.get(3)); Assertions.assertEquals("column1", record.get(3));
} }
private void includeFieldNameOrder(File file) { private void includeFieldNameOrder(File file) {
List<String> includeColumnFieldNames = new ArrayList<>(); List<String> includeColumnFieldNames = new ArrayList<>();
includeColumnFieldNames.add("column4"); includeColumnFieldNames.add("column4");
@ -246,12 +245,12 @@ public class ExcludeOrIncludeDataTest {
sheet() sheet()
.doWrite(data()); .doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals(3, record.size()); Assertions.assertEquals(3, record.size());
Assert.assertEquals("column4", record.get(0)); Assertions.assertEquals("column4", record.get(0));
Assert.assertEquals("column2", record.get(1)); Assertions.assertEquals("column2", record.get(1));
Assert.assertEquals("column3", record.get(2)); Assertions.assertEquals("column3", record.get(2));
} }
private List<ExcludeOrIncludeData> data() { private List<ExcludeOrIncludeData> data() {

36
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataListener.java

@ -1,14 +1,14 @@
package com.alibaba.easyexcel.test.core.extra; package com.alibaba.easyexcel.test.core.extra;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.CellExtra; import com.alibaba.excel.metadata.CellExtra;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -26,28 +26,28 @@ public class ExtraDataListener extends AnalysisEventListener<ExtraData> {
LOGGER.info("extra data:{}", JSON.toJSONString(extra)); LOGGER.info("extra data:{}", JSON.toJSONString(extra));
switch (extra.getType()) { switch (extra.getType()) {
case COMMENT: case COMMENT:
Assert.assertEquals("批注的内容", extra.getText()); Assertions.assertEquals("批注的内容", extra.getText());
Assert.assertEquals(4, (int)extra.getRowIndex()); Assertions.assertEquals(4, (int)extra.getRowIndex());
Assert.assertEquals(0, (int)extra.getColumnIndex()); Assertions.assertEquals(0, (int)extra.getColumnIndex());
break; break;
case HYPERLINK: case HYPERLINK:
if ("Sheet1!A1".equals(extra.getText())) { if ("Sheet1!A1".equals(extra.getText())) {
Assert.assertEquals(1, (int)extra.getRowIndex()); Assertions.assertEquals(1, (int)extra.getRowIndex());
Assert.assertEquals(0, (int)extra.getColumnIndex()); Assertions.assertEquals(0, (int)extra.getColumnIndex());
} else if ("Sheet2!A1".equals(extra.getText())) { } else if ("Sheet2!A1".equals(extra.getText())) {
Assert.assertEquals(2, (int)extra.getFirstRowIndex()); Assertions.assertEquals(2, (int)extra.getFirstRowIndex());
Assert.assertEquals(0, (int)extra.getFirstColumnIndex()); Assertions.assertEquals(0, (int)extra.getFirstColumnIndex());
Assert.assertEquals(3, (int)extra.getLastRowIndex()); Assertions.assertEquals(3, (int)extra.getLastRowIndex());
Assert.assertEquals(1, (int)extra.getLastColumnIndex()); Assertions.assertEquals(1, (int)extra.getLastColumnIndex());
} else { } else {
Assert.fail("Unknown hyperlink!"); Assertions.fail("Unknown hyperlink!");
} }
break; break;
case MERGE: case MERGE:
Assert.assertEquals(5, (int)extra.getFirstRowIndex()); Assertions.assertEquals(5, (int)extra.getFirstRowIndex());
Assert.assertEquals(0, (int)extra.getFirstColumnIndex()); Assertions.assertEquals(0, (int)extra.getFirstColumnIndex());
Assert.assertEquals(6, (int)extra.getLastRowIndex()); Assertions.assertEquals(6, (int)extra.getLastRowIndex());
Assert.assertEquals(1, (int)extra.getLastColumnIndex()); Assertions.assertEquals(1, (int)extra.getLastColumnIndex());
break; break;
default: default:
} }

24
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java

@ -2,12 +2,6 @@ package com.alibaba.easyexcel.test.core.extra;
import java.io.File; import java.io.File;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
@ -16,6 +10,12 @@ import com.alibaba.excel.metadata.CellExtra;
import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -26,7 +26,7 @@ public class ExtraDataTest {
private static File extraRelationships; private static File extraRelationships;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file03 = TestFileUtil.readFile("extra" + File.separator + "extra.xls"); file03 = TestFileUtil.readFile("extra" + File.separator + "extra.xls");
file07 = TestFileUtil.readFile("extra" + File.separator + "extra.xlsx"); file07 = TestFileUtil.readFile("extra" + File.separator + "extra.xlsx");
@ -60,13 +60,13 @@ public class ExtraDataTest {
switch (extra.getType()) { switch (extra.getType()) {
case HYPERLINK: case HYPERLINK:
if ("222222222".equals(extra.getText())) { if ("222222222".equals(extra.getText())) {
Assert.assertEquals(1, (int)extra.getRowIndex()); Assertions.assertEquals(1, (int)extra.getRowIndex());
Assert.assertEquals(0, (int)extra.getColumnIndex()); Assertions.assertEquals(0, (int)extra.getColumnIndex());
} else if ("333333333333".equals(extra.getText())) { } else if ("333333333333".equals(extra.getText())) {
Assert.assertEquals(1, (int)extra.getRowIndex()); Assertions.assertEquals(1, (int)extra.getRowIndex());
Assert.assertEquals(1, (int)extra.getColumnIndex()); Assertions.assertEquals(1, (int)extra.getColumnIndex());
} else { } else {
Assert.fail("Unknown hyperlink!"); Assertions.fail("Unknown hyperlink!");
} }
break; break;
default: default:

32
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java

@ -16,16 +16,16 @@ import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig; import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.excel.write.metadata.fill.FillWrapper;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class FillDataTest { public class FillDataTest {
private static File file07; private static File file07;
@ -51,7 +51,7 @@ public class FillDataTest {
private static File fileComposite03; private static File fileComposite03;
private static File compositeFillTemplate03; private static File compositeFillTemplate03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("fill07.xlsx"); file07 = TestFileUtil.createNewFile("fill07.xlsx");
file03 = TestFileUtil.createNewFile("fill03.xls"); file03 = TestFileUtil.createNewFile("fill03.xls");
@ -89,9 +89,9 @@ public class FillDataTest {
@Test @Test
public void t03FillCsv() { public void t03FillCsv() {
ExcelGenerateException excelGenerateException = Assert.assertThrows(ExcelGenerateException.class, ExcelGenerateException excelGenerateException = Assertions.assertThrows(ExcelGenerateException.class,
() -> fill(fileCsv, simpleTemplateCsv)); () -> fill(fileCsv, simpleTemplateCsv));
Assert.assertEquals("csv cannot use template.", excelGenerateException.getMessage()); Assertions.assertEquals("csv cannot use template.", excelGenerateException.getMessage());
} }
@Test @Test
@ -159,11 +159,11 @@ public class FillDataTest {
List<Object> list = EasyExcel.read(file).ignoreEmptyRow(false).sheet().headRowNumber(0).doReadSync(); List<Object> list = EasyExcel.read(file).ignoreEmptyRow(false).sheet().headRowNumber(0).doReadSync();
Map<String, String> map0 = (Map<String, String>)list.get(0); Map<String, String> map0 = (Map<String, String>)list.get(0);
Assert.assertEquals("张三", map0.get(21)); Assertions.assertEquals("张三", map0.get(21));
Map<String, String> map27 = (Map<String, String>)list.get(27); Map<String, String> map27 = (Map<String, String>)list.get(27);
Assert.assertEquals("张三", map27.get(0)); Assertions.assertEquals("张三", map27.get(0));
Map<String, String> map29 = (Map<String, String>)list.get(29); Map<String, String> map29 = (Map<String, String>)list.get(29);
Assert.assertEquals("张三", map29.get(3)); Assertions.assertEquals("张三", map29.get(3));
} }
private void horizontalFill(File file, File template) { private void horizontalFill(File file, File template) {
@ -179,9 +179,9 @@ public class FillDataTest {
} }
List<Object> list = EasyExcel.read(file).sheet().headRowNumber(0).doReadSync(); List<Object> list = EasyExcel.read(file).sheet().headRowNumber(0).doReadSync();
Assert.assertEquals(list.size(), 5L); Assertions.assertEquals(list.size(), 5L);
Map<String, String> map0 = (Map<String, String>)list.get(0); Map<String, String> map0 = (Map<String, String>)list.get(0);
Assert.assertEquals("张三", map0.get(2)); Assertions.assertEquals("张三", map0.get(2));
} }
private void complexFill(File file, File template) { private void complexFill(File file, File template) {
@ -196,9 +196,9 @@ public class FillDataTest {
excelWriter.fill(map, writeSheet); excelWriter.fill(map, writeSheet);
} }
List<Object> list = EasyExcel.read(file).sheet().headRowNumber(3).doReadSync(); List<Object> list = EasyExcel.read(file).sheet().headRowNumber(3).doReadSync();
Assert.assertEquals(list.size(), 21L); Assertions.assertEquals(list.size(), 21L);
Map<String, String> map19 = (Map<String, String>)list.get(19); Map<String, String> map19 = (Map<String, String>)list.get(19);
Assert.assertEquals("张三", map19.get(0)); Assertions.assertEquals("张三", map19.get(0));
} }
private void fill(File file, File template) { private void fill(File file, File template) {

36
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java

@ -22,17 +22,17 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFPicture; import org.apache.poi.xssf.usermodel.XSSFPicture;
import org.apache.poi.xssf.usermodel.XSSFShape; import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class FillAnnotationDataTest { public class FillAnnotationDataTest {
private static File file07; private static File file07;
@ -40,7 +40,7 @@ public class FillAnnotationDataTest {
private static File fileTemplate07; private static File fileTemplate07;
private static File fileTemplate03; private static File fileTemplate03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("fillAnnotation07.xlsx"); file07 = TestFileUtil.createNewFile("fillAnnotation07.xlsx");
file03 = TestFileUtil.createNewFile("fillAnnotation03.xls"); file03 = TestFileUtil.createNewFile("fillAnnotation03.xls");
@ -65,14 +65,14 @@ public class FillAnnotationDataTest {
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
Row row1 = sheet.getRow(1); Row row1 = sheet.getRow(1);
Assert.assertEquals(2000, row1.getHeight(), 0); Assertions.assertEquals(2000, row1.getHeight(), 0);
Cell cell10 = row1.getCell(0); Cell cell10 = row1.getCell(0);
Date date = cell10.getDateCellValue(); Date date = cell10.getDateCellValue();
Assert.assertEquals(DateUtils.parseDate("2020-01-01 01:01:01").getTime(), date.getTime()); Assertions.assertEquals(DateUtils.parseDate("2020-01-01 01:01:01").getTime(), date.getTime());
String dataFormatString = cell10.getCellStyle().getDataFormatString(); String dataFormatString = cell10.getCellStyle().getDataFormatString();
Assert.assertEquals("yyyy年MM月dd日HH时mm分ss秒", dataFormatString); Assertions.assertEquals("yyyy年MM月dd日HH时mm分ss秒", dataFormatString);
Cell cell11 = row1.getCell(1); Cell cell11 = row1.getCell(1);
Assert.assertEquals(99.99, cell11.getNumericCellValue(), 2); Assertions.assertEquals(99.99, cell11.getNumericCellValue(), 2);
boolean hasMerge = false; boolean hasMerge = false;
for (CellRangeAddress mergedRegion : sheet.getMergedRegions()) { for (CellRangeAddress mergedRegion : sheet.getMergedRegions()) {
if (mergedRegion.getFirstRow() == 1 && mergedRegion.getLastRow() == 1 if (mergedRegion.getFirstRow() == 1 && mergedRegion.getLastRow() == 1
@ -81,25 +81,25 @@ public class FillAnnotationDataTest {
break; break;
} }
} }
Assert.assertTrue(hasMerge); Assertions.assertTrue(hasMerge);
if (sheet instanceof XSSFSheet) { if (sheet instanceof XSSFSheet) {
XSSFSheet xssfSheet = (XSSFSheet)sheet; XSSFSheet xssfSheet = (XSSFSheet)sheet;
List<XSSFShape> shapeList = xssfSheet.getDrawingPatriarch().getShapes(); List<XSSFShape> shapeList = xssfSheet.getDrawingPatriarch().getShapes();
XSSFShape shape0 = shapeList.get(0); XSSFShape shape0 = shapeList.get(0);
Assert.assertTrue(shape0 instanceof XSSFPicture); Assertions.assertTrue(shape0 instanceof XSSFPicture);
XSSFPicture picture0 = (XSSFPicture)shape0; XSSFPicture picture0 = (XSSFPicture)shape0;
CTMarker ctMarker0 = picture0.getPreferredSize().getFrom(); CTMarker ctMarker0 = picture0.getPreferredSize().getFrom();
Assert.assertEquals(1, ctMarker0.getRow()); Assertions.assertEquals(1, ctMarker0.getRow());
Assert.assertEquals(4, ctMarker0.getCol()); Assertions.assertEquals(4, ctMarker0.getCol());
} else { } else {
HSSFSheet hssfSheet = (HSSFSheet)sheet; HSSFSheet hssfSheet = (HSSFSheet)sheet;
List<HSSFShape> shapeList = hssfSheet.getDrawingPatriarch().getChildren(); List<HSSFShape> shapeList = hssfSheet.getDrawingPatriarch().getChildren();
HSSFShape shape0 = shapeList.get(0); HSSFShape shape0 = shapeList.get(0);
Assert.assertTrue(shape0 instanceof HSSFPicture); Assertions.assertTrue(shape0 instanceof HSSFPicture);
HSSFPicture picture0 = (HSSFPicture)shape0; HSSFPicture picture0 = (HSSFPicture)shape0;
HSSFClientAnchor anchor = (HSSFClientAnchor)picture0.getAnchor(); HSSFClientAnchor anchor = (HSSFClientAnchor)picture0.getAnchor();
Assert.assertEquals(1, anchor.getRow1()); Assertions.assertEquals(1, anchor.getRow1());
Assert.assertEquals(4, anchor.getCol1()); Assertions.assertEquals(4, anchor.getCol1());
} }
} }
} }

262
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleAnnotatedTest.java

@ -25,16 +25,16 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class FillStyleAnnotatedTest { public class FillStyleAnnotatedTest {
private static File FillStyleAnnotated07; private static File FillStyleAnnotated07;
@ -42,7 +42,7 @@ public class FillStyleAnnotatedTest {
private static File fileStyleTemplate07; private static File fileStyleTemplate07;
private static File fileStyleTemplate03; private static File fileStyleTemplate03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
FillStyleAnnotated07 = TestFileUtil.createNewFile("FillStyleAnnotated07.xlsx"); FillStyleAnnotated07 = TestFileUtil.createNewFile("FillStyleAnnotated07.xlsx");
FillStyleAnnotated03 = TestFileUtil.createNewFile("FillStyleAnnotated03.xls"); FillStyleAnnotated03 = TestFileUtil.createNewFile("FillStyleAnnotated03.xls");
@ -61,46 +61,47 @@ public class FillStyleAnnotatedTest {
private void t01Fill07check(XSSFRow row) { private void t01Fill07check(XSSFRow row) {
XSSFCell cell0 = row.getCell(0); XSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("FFFFFF00", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFFFF00", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF808000", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF808000", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell0.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont().getBold());
XSSFCell cell1 = row.getCell(1); XSSFCell cell1 = row.getCell(1);
Assert.assertEquals(5.2, cell1.getNumericCellValue(), 1); Assertions.assertEquals(5.2, cell1.getNumericCellValue(), 1);
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF0000", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFF0000", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF800000", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF800000", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell1.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell1.getCellStyle().getFont().getBold());
XSSFCell cell2 = row.getCell(2); XSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("FF008000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("FF003300", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF008000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertTrue(cell2.getCellStyle().getFont().getBold()); Assertions.assertEquals("FF003300", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assertions.assertTrue(cell2.getCellStyle().getFont().getBold());
XSSFCell cell3 = row.getCell(3); XSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5.2岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5.2岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF0000", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFF0000", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FFEEECE1", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FFEEECE1", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell3.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont().getBold());
XSSFCell cell4 = row.getCell(4); XSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("FFC00000", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFC00000", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF000000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF000000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertFalse(cell4.getCellStyle().getFont().getBold()); Assertions.assertFalse(cell4.getCellStyle().getFont().getBold());
XSSFCell cell5 = row.getCell(5); XSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("FFF79646", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFF79646", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF8064A2", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF8064A2", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertFalse(cell5.getCellStyle().getFont().getBold()); Assertions.assertFalse(cell5.getCellStyle().getFont().getBold());
} }
@Test @Test
@ -114,150 +115,153 @@ public class FillStyleAnnotatedTest {
private void t02Fill03check(HSSFWorkbook workbook, HSSFRow row) { private void t02Fill03check(HSSFWorkbook workbook, HSSFRow row) {
HSSFCell cell0 = row.getCell(0); HSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:FFFF:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:FFFF:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:8080:0", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:8080:0", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell0.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont(workbook).getBold());
HSSFCell cell1 = row.getCell(1); HSSFCell cell1 = row.getCell(1);
Assert.assertEquals(5.2, cell1.getNumericCellValue(), 1); Assertions.assertEquals(5.2, cell1.getNumericCellValue(), 1);
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:0:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:0:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:0:0", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:0:0", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell1.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell1.getCellStyle().getFont(workbook).getBold());
HSSFCell cell2 = row.getCell(2); HSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("0:8080:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("0:3333:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook).getHexString()); Assertions.assertEquals("0:8080:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertTrue(cell2.getCellStyle().getFont(workbook).getBold()); Assertions.assertEquals("0:3333:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString());
Assertions.assertTrue(cell2.getCellStyle().getFont(workbook).getBold());
HSSFCell cell3 = row.getCell(3); HSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5.2岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5.2岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:0:0", cell3.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:0:0", cell3.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("FFFF:FFFF:9999", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("FFFF:FFFF:9999", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell3.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont(workbook).getBold());
HSSFCell cell4 = row.getCell(4); HSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("9999:3333:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("9999:3333:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("3333:3333:3333", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("3333:3333:3333", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertFalse(cell4.getCellStyle().getFont(workbook).getBold()); Assertions.assertFalse(cell4.getCellStyle().getFont(workbook).getBold());
HSSFCell cell5 = row.getCell(5); HSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("9999:3333:0", cell5.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("9999:3333:0", cell5.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("CCCC:9999:FFFF", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("CCCC:9999:FFFF", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertFalse(cell5.getCellStyle().getFont(workbook).getBold()); Assertions.assertFalse(cell5.getCellStyle().getFont(workbook).getBold());
} }
private void fill(File file, File template) throws Exception { private void fill(File file, File template) throws Exception {
EasyExcel.write(file, FillStyleAnnotatedData.class).withTemplate(template).sheet().doFill(data()); EasyExcel.write(file, FillStyleAnnotatedData.class).withTemplate(template).sheet().doFill(data());
} }
private void t11FillStyleHandler07check(XSSFRow row) { private void t11FillStyleHandler07check(XSSFRow row) {
XSSFCell cell0 = row.getCell(0); XSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("FFFFFF00", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFFFF00", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF808000", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF808000", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell0.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont().getBold());
XSSFCell cell1 = row.getCell(1); XSSFCell cell1 = row.getCell(1);
Assert.assertEquals("5", cell1.getStringCellValue()); Assertions.assertEquals("5", cell1.getStringCellValue());
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF0000", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFF0000", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF800000", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF800000", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell1.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell1.getCellStyle().getFont().getBold());
XSSFCell cell2 = row.getCell(2); XSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("FF008000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("FF003300", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF008000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertTrue(cell2.getCellStyle().getFont().getBold()); Assertions.assertEquals("FF003300", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assertions.assertTrue(cell2.getCellStyle().getFont().getBold());
XSSFCell cell3 = row.getCell(3); XSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("FF0000FF", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FF0000FF", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF000080", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF000080", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell3.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont().getBold());
XSSFCell cell4 = row.getCell(4); XSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("FFFFFF00", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFFFF00", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF808000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF808000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell4.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell4.getCellStyle().getFont().getBold());
XSSFCell cell5 = row.getCell(5); XSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("FF008080", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FF008080", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF003366", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF003366", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell5.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell5.getCellStyle().getFont().getBold());
} }
private void t12FillStyleHandler03check(HSSFWorkbook workbook, HSSFRow row) { private void t12FillStyleHandler03check(HSSFWorkbook workbook, HSSFRow row) {
HSSFCell cell0 = row.getCell(0); HSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:FFFF:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:FFFF:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:8080:0", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:8080:0", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell0.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont(workbook).getBold());
HSSFCell cell1 = row.getCell(1); HSSFCell cell1 = row.getCell(1);
Assert.assertEquals("5", cell1.getStringCellValue()); Assertions.assertEquals("5", cell1.getStringCellValue());
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:0:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:0:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:0:0", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:0:0", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell1.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell1.getCellStyle().getFont(workbook).getBold());
HSSFCell cell2 = row.getCell(2); HSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("0:8080:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("0:3333:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook).getHexString()); Assertions.assertEquals("0:8080:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertTrue(cell2.getCellStyle().getFont(workbook).getBold()); Assertions.assertEquals("0:3333:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString());
Assertions.assertTrue(cell2.getCellStyle().getFont(workbook).getBold());
HSSFCell cell3 = row.getCell(3); HSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("0:0:FFFF", cell3.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("0:0:FFFF", cell3.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("0:0:8080", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("0:0:8080", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell3.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont(workbook).getBold());
HSSFCell cell4 = row.getCell(4); HSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:FFFF:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:FFFF:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:8080:0", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:8080:0", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell4.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell4.getCellStyle().getFont(workbook).getBold());
HSSFCell cell5 = row.getCell(5); HSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("0:8080:8080", cell5.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("0:8080:8080", cell5.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("0:3333:6666", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("0:3333:6666", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell5.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell5.getCellStyle().getFont(workbook).getBold());
} }
private void fillStyleHandler(File file, File template) throws Exception { private void fillStyleHandler(File file, File template) throws Exception {

260
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleDataTest.java

@ -24,16 +24,16 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class FillStyleDataTest { public class FillStyleDataTest {
private static File fileStyle07; private static File fileStyle07;
@ -43,7 +43,7 @@ public class FillStyleDataTest {
private static File fileStyleTemplate07; private static File fileStyleTemplate07;
private static File fileStyleTemplate03; private static File fileStyleTemplate03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
fileStyle07 = TestFileUtil.createNewFile("fileStyle07.xlsx"); fileStyle07 = TestFileUtil.createNewFile("fileStyle07.xlsx");
fileStyle03 = TestFileUtil.createNewFile("fileStyle03.xls"); fileStyle03 = TestFileUtil.createNewFile("fileStyle03.xls");
@ -64,46 +64,47 @@ public class FillStyleDataTest {
private void t01Fill07check(XSSFRow row) { private void t01Fill07check(XSSFRow row) {
XSSFCell cell0 = row.getCell(0); XSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("FF00B050", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FF00B050", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF7030A0", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF7030A0", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell0.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont().getBold());
XSSFCell cell1 = row.getCell(1); XSSFCell cell1 = row.getCell(1);
Assert.assertEquals(5.2, cell1.getNumericCellValue(), 1); Assertions.assertEquals(5.2, cell1.getNumericCellValue(), 1);
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("FF92D050", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FF92D050", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF4BACC6", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF4BACC6", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertFalse(cell1.getCellStyle().getFont().getBold()); Assertions.assertFalse(cell1.getCellStyle().getFont().getBold());
XSSFCell cell2 = row.getCell(2); XSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("FFFFC000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("FFC0504D", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FFFFC000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertTrue(cell2.getCellStyle().getFont().getBold()); Assertions.assertEquals("FFC0504D", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assertions.assertTrue(cell2.getCellStyle().getFont().getBold());
XSSFCell cell3 = row.getCell(3); XSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5.2岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5.2岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF0000", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFF0000", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FFEEECE1", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FFEEECE1", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell3.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont().getBold());
XSSFCell cell4 = row.getCell(4); XSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("FFC00000", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFC00000", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF000000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF000000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertFalse(cell4.getCellStyle().getFont().getBold()); Assertions.assertFalse(cell4.getCellStyle().getFont().getBold());
XSSFCell cell5 = row.getCell(5); XSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("FFF79646", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFF79646", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF8064A2", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF8064A2", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertFalse(cell5.getCellStyle().getFont().getBold()); Assertions.assertFalse(cell5.getCellStyle().getFont().getBold());
} }
@Test @Test
@ -117,51 +118,53 @@ public class FillStyleDataTest {
private void t02Fill03check(HSSFWorkbook workbook, HSSFRow row) { private void t02Fill03check(HSSFWorkbook workbook, HSSFRow row) {
HSSFCell cell0 = row.getCell(0); HSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("0:8080:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("0:8080:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:0:8080", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:0:8080", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell0.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont(workbook).getBold());
HSSFCell cell1 = row.getCell(1); HSSFCell cell1 = row.getCell(1);
Assert.assertEquals(5.2, cell1.getNumericCellValue(), 1); Assertions.assertEquals(5.2, cell1.getNumericCellValue(), 1);
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("9999:CCCC:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("9999:CCCC:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("0:8080:8080", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("0:8080:8080", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertFalse(cell1.getCellStyle().getFont(workbook).getBold()); Assertions.assertFalse(cell1.getCellStyle().getFont(workbook).getBold());
HSSFCell cell2 = row.getCell(2); HSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("FFFF:CCCC:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("8080:0:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook).getHexString()); Assertions.assertEquals("FFFF:CCCC:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertTrue(cell2.getCellStyle().getFont(workbook).getBold()); Assertions.assertEquals("8080:0:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString());
Assertions.assertTrue(cell2.getCellStyle().getFont(workbook).getBold());
HSSFCell cell3 = row.getCell(3); HSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5.2岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5.2岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:0:0", cell3.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:0:0", cell3.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("FFFF:FFFF:9999", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("FFFF:FFFF:9999", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell3.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont(workbook).getBold());
HSSFCell cell4 = row.getCell(4); HSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("9999:3333:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("9999:3333:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("3333:3333:3333", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("3333:3333:3333", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertFalse(cell4.getCellStyle().getFont(workbook).getBold()); Assertions.assertFalse(cell4.getCellStyle().getFont(workbook).getBold());
HSSFCell cell5 = row.getCell(5); HSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("9999:3333:0", cell5.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("9999:3333:0", cell5.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("CCCC:9999:FFFF", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("CCCC:9999:FFFF", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertFalse(cell5.getCellStyle().getFont(workbook).getBold()); Assertions.assertFalse(cell5.getCellStyle().getFont(workbook).getBold());
} }
private void fill(File file, File template) throws Exception { private void fill(File file, File template) throws Exception {
@ -179,46 +182,47 @@ public class FillStyleDataTest {
private void t11FillStyleHandler07check(XSSFRow row) { private void t11FillStyleHandler07check(XSSFRow row) {
XSSFCell cell0 = row.getCell(0); XSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("FFFFFF00", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFFFF00", cell0.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF808000", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF808000", cell0.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell0.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont().getBold());
XSSFCell cell1 = row.getCell(1); XSSFCell cell1 = row.getCell(1);
Assert.assertEquals(5.2, cell1.getNumericCellValue(), 1); Assertions.assertEquals(5.2, cell1.getNumericCellValue(), 1);
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF0000", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFF0000", cell1.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF800000", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF800000", cell1.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell1.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell1.getCellStyle().getFont().getBold());
XSSFCell cell2 = row.getCell(2); XSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("FF008000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("FF003300", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF008000", cell2.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertTrue(cell2.getCellStyle().getFont().getBold()); Assertions.assertEquals("FF003300", cell2.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assertions.assertTrue(cell2.getCellStyle().getFont().getBold());
XSSFCell cell3 = row.getCell(3); XSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5.2岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5.2岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF0000", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFFF0000", cell3.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FFEEECE1", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FFEEECE1", cell3.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertTrue(cell3.getCellStyle().getFont().getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont().getBold());
XSSFCell cell4 = row.getCell(4); XSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("FFC00000", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFC00000", cell4.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF000000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF000000", cell4.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertFalse(cell4.getCellStyle().getFont().getBold()); Assertions.assertFalse(cell4.getCellStyle().getFont().getBold());
XSSFCell cell5 = row.getCell(5); XSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("FFF79646", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex()); Assertions.assertEquals("FFF79646", cell5.getCellStyle().getFillForegroundColorColor().getARGBHex());
Assert.assertEquals("FF8064A2", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex()); Assertions.assertEquals("FF8064A2", cell5.getCellStyle().getFont().getXSSFColor().getARGBHex());
Assert.assertFalse(cell5.getCellStyle().getFont().getBold()); Assertions.assertFalse(cell5.getCellStyle().getFont().getBold());
} }
@Test @Test
@ -232,51 +236,53 @@ public class FillStyleDataTest {
private void t12FillStyleHandler03check(HSSFWorkbook workbook, HSSFRow row) { private void t12FillStyleHandler03check(HSSFWorkbook workbook, HSSFRow row) {
HSSFCell cell0 = row.getCell(0); HSSFCell cell0 = row.getCell(0);
Assert.assertEquals("张三", cell0.getStringCellValue()); Assertions.assertEquals("张三", cell0.getStringCellValue());
Assert.assertEquals(49, cell0.getCellStyle().getDataFormat()); Assertions.assertEquals(49, cell0.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:FFFF:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:FFFF:0", cell0.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:8080:0", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:8080:0", cell0.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell0.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell0.getCellStyle().getFont(workbook).getBold());
HSSFCell cell1 = row.getCell(1); HSSFCell cell1 = row.getCell(1);
Assert.assertEquals(5.2, cell1.getNumericCellValue(), 1); Assertions.assertEquals(5.2, cell1.getNumericCellValue(), 1);
Assert.assertEquals(0, cell1.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell1.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:0:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:0:0", cell1.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("8080:0:0", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("8080:0:0", cell1.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell1.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell1.getCellStyle().getFont(workbook).getBold());
HSSFCell cell2 = row.getCell(2); HSSFCell cell2 = row.getCell(2);
Assert.assertEquals("2020-01-01 01:01:01", DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss")); Assertions.assertEquals("2020-01-01 01:01:01",
Assert.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString()); DateUtils.format(cell2.getDateCellValue(), "yyyy-MM-dd HH:mm:ss"));
Assert.assertEquals("0:8080:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("yyyy-MM-dd HH:mm:ss", cell2.getCellStyle().getDataFormatString());
Assert.assertEquals("0:3333:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook).getHexString()); Assertions.assertEquals("0:8080:0", cell2.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertTrue(cell2.getCellStyle().getFont(workbook).getBold()); Assertions.assertEquals("0:3333:0", cell2.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString());
Assertions.assertTrue(cell2.getCellStyle().getFont(workbook).getBold());
HSSFCell cell3 = row.getCell(3); HSSFCell cell3 = row.getCell(3);
Assert.assertEquals("张三今年5.2岁了", cell3.getStringCellValue()); Assertions.assertEquals("张三今年5.2岁了", cell3.getStringCellValue());
Assert.assertEquals(0, cell3.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell3.getCellStyle().getDataFormat());
Assert.assertEquals("FFFF:0:0", cell3.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("FFFF:0:0", cell3.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("FFFF:FFFF:9999", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("FFFF:FFFF:9999", cell3.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertTrue(cell3.getCellStyle().getFont(workbook).getBold()); Assertions.assertTrue(cell3.getCellStyle().getFont(workbook).getBold());
HSSFCell cell4 = row.getCell(4); HSSFCell cell4 = row.getCell(4);
Assert.assertEquals("{.name}忽略,张三", cell4.getStringCellValue()); Assertions.assertEquals("{.name}忽略,张三", cell4.getStringCellValue());
Assert.assertEquals(0, cell4.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell4.getCellStyle().getDataFormat());
Assert.assertEquals("9999:3333:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("9999:3333:0", cell4.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("3333:3333:3333", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("3333:3333:3333", cell4.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertFalse(cell4.getCellStyle().getFont(workbook).getBold()); Assertions.assertFalse(cell4.getCellStyle().getFont(workbook).getBold());
HSSFCell cell5 = row.getCell(5); HSSFCell cell5 = row.getCell(5);
Assert.assertEquals("空", cell5.getStringCellValue()); Assertions.assertEquals("空", cell5.getStringCellValue());
Assert.assertEquals(0, cell5.getCellStyle().getDataFormat()); Assertions.assertEquals(0, cell5.getCellStyle().getDataFormat());
Assert.assertEquals("9999:3333:0", cell5.getCellStyle().getFillForegroundColorColor().getHexString()); Assertions.assertEquals("9999:3333:0", cell5.getCellStyle().getFillForegroundColorColor().getHexString());
Assert.assertEquals("CCCC:9999:FFFF", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook) Assertions.assertEquals("CCCC:9999:FFFF", cell5.getCellStyle().getFont(workbook).getHSSFColor(workbook)
.getHexString()); .getHexString());
Assert.assertFalse(cell5.getCellStyle().getFont(workbook).getBold()); Assertions.assertFalse(cell5.getCellStyle().getFont(workbook).getBold());
} }
private void fillStyleHandler(File file, File template) throws Exception { private void fillStyleHandler(File file, File template) throws Exception {

314
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandler.java

@ -14,7 +14,7 @@ import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
/** /**
* @author JiaJu Zhuang * @author JiaJu Zhuang
@ -38,18 +38,18 @@ public class WriteHandler implements WorkbookWriteHandler, SheetWriteHandler, Ro
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) { Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
if (isHead) { if (isHead) {
Assert.assertEquals(0L, beforeCellCreate); Assertions.assertEquals(0L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(1L, afterRowCreate); Assertions.assertEquals(1L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
beforeCellCreate++; beforeCellCreate++;
} }
@ -59,18 +59,18 @@ public class WriteHandler implements WorkbookWriteHandler, SheetWriteHandler, Ro
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
Head head, Integer relativeRowIndex, Boolean isHead) { Head head, Integer relativeRowIndex, Boolean isHead) {
if (isHead) { if (isHead) {
Assert.assertEquals(1L, beforeCellCreate); Assertions.assertEquals(1L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(1L, afterRowCreate); Assertions.assertEquals(1L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterCellCreate++; afterCellCreate++;
} }
} }
@ -78,18 +78,18 @@ public class WriteHandler implements WorkbookWriteHandler, SheetWriteHandler, Ro
@Override @Override
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
Assert.assertEquals(1L, beforeCellCreate); Assertions.assertEquals(1L, beforeCellCreate);
Assert.assertEquals(1L, afterCellCreate); Assertions.assertEquals(1L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(1, afterCellDispose); Assertions.assertEquals(1, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(1L, afterRowCreate); Assertions.assertEquals(1L, afterRowCreate);
Assert.assertEquals(1L, afterRowDispose); Assertions.assertEquals(1L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterCellDataConverted++; afterCellDataConverted++;
} }
@ -97,18 +97,18 @@ public class WriteHandler implements WorkbookWriteHandler, SheetWriteHandler, Ro
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) { List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
if (isHead) { if (isHead) {
Assert.assertEquals(1L, beforeCellCreate); Assertions.assertEquals(1L, beforeCellCreate);
Assert.assertEquals(1L, afterCellCreate); Assertions.assertEquals(1L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(1L, afterRowCreate); Assertions.assertEquals(1L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterCellDispose++; afterCellDispose++;
} }
} }
@ -117,18 +117,18 @@ public class WriteHandler implements WorkbookWriteHandler, SheetWriteHandler, Ro
public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex, public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex,
Integer relativeRowIndex, Boolean isHead) { Integer relativeRowIndex, Boolean isHead) {
if (isHead) { if (isHead) {
Assert.assertEquals(0L, beforeCellCreate); Assertions.assertEquals(0L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(0L, beforeRowCreate); Assertions.assertEquals(0L, beforeRowCreate);
Assert.assertEquals(0L, afterRowCreate); Assertions.assertEquals(0L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
beforeRowCreate++; beforeRowCreate++;
} }
@ -138,18 +138,18 @@ public class WriteHandler implements WorkbookWriteHandler, SheetWriteHandler, Ro
public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Integer relativeRowIndex, Boolean isHead) { Integer relativeRowIndex, Boolean isHead) {
if (isHead) { if (isHead) {
Assert.assertEquals(0L, beforeCellCreate); Assertions.assertEquals(0L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(0L, afterRowCreate); Assertions.assertEquals(0L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterRowCreate++; afterRowCreate++;
} }
} }
@ -158,120 +158,120 @@ public class WriteHandler implements WorkbookWriteHandler, SheetWriteHandler, Ro
public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
Integer relativeRowIndex, Boolean isHead) { Integer relativeRowIndex, Boolean isHead) {
if (isHead) { if (isHead) {
Assert.assertEquals(1L, beforeCellCreate); Assertions.assertEquals(1L, beforeCellCreate);
Assert.assertEquals(1L, afterCellCreate); Assertions.assertEquals(1L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(1L, afterCellDispose); Assertions.assertEquals(1L, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(1L, afterRowCreate); Assertions.assertEquals(1L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterRowDispose++; afterRowDispose++;
} }
} }
@Override @Override
public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
Assert.assertEquals(0L, beforeCellCreate); Assertions.assertEquals(0L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(0L, beforeRowCreate); Assertions.assertEquals(0L, beforeRowCreate);
Assert.assertEquals(0L, afterRowCreate); Assertions.assertEquals(0L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(0L, beforeSheetCreate); Assertions.assertEquals(0L, beforeSheetCreate);
Assert.assertEquals(0L, afterSheetCreate); Assertions.assertEquals(0L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
beforeSheetCreate++; beforeSheetCreate++;
} }
@Override @Override
public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
Assert.assertEquals(0L, beforeCellCreate); Assertions.assertEquals(0L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(0L, beforeRowCreate); Assertions.assertEquals(0L, beforeRowCreate);
Assert.assertEquals(0L, afterRowCreate); Assertions.assertEquals(0L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(0L, afterSheetCreate); Assertions.assertEquals(0L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterSheetCreate++; afterSheetCreate++;
} }
@Override @Override
public void beforeWorkbookCreate() { public void beforeWorkbookCreate() {
Assert.assertEquals(0L, beforeCellCreate); Assertions.assertEquals(0L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(0L, beforeRowCreate); Assertions.assertEquals(0L, beforeRowCreate);
Assert.assertEquals(0L, afterRowCreate); Assertions.assertEquals(0L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(0L, beforeSheetCreate); Assertions.assertEquals(0L, beforeSheetCreate);
Assert.assertEquals(0L, afterSheetCreate); Assertions.assertEquals(0L, afterSheetCreate);
Assert.assertEquals(0L, beforeWorkbookCreate); Assertions.assertEquals(0L, beforeWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookCreate); Assertions.assertEquals(0L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
beforeWorkbookCreate++; beforeWorkbookCreate++;
} }
@Override @Override
public void afterWorkbookCreate(WriteWorkbookHolder writeWorkbookHolder) { public void afterWorkbookCreate(WriteWorkbookHolder writeWorkbookHolder) {
Assert.assertEquals(0L, beforeCellCreate); Assertions.assertEquals(0L, beforeCellCreate);
Assert.assertEquals(0L, afterCellCreate); Assertions.assertEquals(0L, afterCellCreate);
Assert.assertEquals(0L, afterCellDataConverted); Assertions.assertEquals(0L, afterCellDataConverted);
Assert.assertEquals(0L, afterCellDispose); Assertions.assertEquals(0L, afterCellDispose);
Assert.assertEquals(0L, beforeRowCreate); Assertions.assertEquals(0L, beforeRowCreate);
Assert.assertEquals(0L, afterRowCreate); Assertions.assertEquals(0L, afterRowCreate);
Assert.assertEquals(0L, afterRowDispose); Assertions.assertEquals(0L, afterRowDispose);
Assert.assertEquals(0L, beforeSheetCreate); Assertions.assertEquals(0L, beforeSheetCreate);
Assert.assertEquals(0L, afterSheetCreate); Assertions.assertEquals(0L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookCreate); Assertions.assertEquals(0L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterWorkbookCreate++; afterWorkbookCreate++;
} }
@Override @Override
public void afterWorkbookDispose(WriteWorkbookHolder writeWorkbookHolder) { public void afterWorkbookDispose(WriteWorkbookHolder writeWorkbookHolder) {
Assert.assertEquals(1L, beforeCellCreate); Assertions.assertEquals(1L, beforeCellCreate);
Assert.assertEquals(1L, afterCellCreate); Assertions.assertEquals(1L, afterCellCreate);
Assert.assertEquals(1L, afterCellDataConverted); Assertions.assertEquals(1L, afterCellDataConverted);
Assert.assertEquals(1L, afterCellDispose); Assertions.assertEquals(1L, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(1L, afterRowCreate); Assertions.assertEquals(1L, afterRowCreate);
Assert.assertEquals(1L, afterRowDispose); Assertions.assertEquals(1L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(0L, afterWorkbookDispose); Assertions.assertEquals(0L, afterWorkbookDispose);
afterWorkbookDispose++; afterWorkbookDispose++;
} }
public void afterAll() { public void afterAll() {
Assert.assertEquals(1L, beforeCellCreate); Assertions.assertEquals(1L, beforeCellCreate);
Assert.assertEquals(1L, afterCellCreate); Assertions.assertEquals(1L, afterCellCreate);
Assert.assertEquals(1L, afterCellDataConverted); Assertions.assertEquals(1L, afterCellDataConverted);
Assert.assertEquals(1L, afterCellDispose); Assertions.assertEquals(1L, afterCellDispose);
Assert.assertEquals(1L, beforeRowCreate); Assertions.assertEquals(1L, beforeRowCreate);
Assert.assertEquals(1L, afterRowCreate); Assertions.assertEquals(1L, afterRowCreate);
Assert.assertEquals(1L, afterRowDispose); Assertions.assertEquals(1L, afterRowDispose);
Assert.assertEquals(1L, beforeSheetCreate); Assertions.assertEquals(1L, beforeSheetCreate);
Assert.assertEquals(1L, afterSheetCreate); Assertions.assertEquals(1L, afterSheetCreate);
Assert.assertEquals(1L, beforeWorkbookCreate); Assertions.assertEquals(1L, beforeWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookCreate); Assertions.assertEquals(1L, afterWorkbookCreate);
Assert.assertEquals(1L, afterWorkbookDispose); Assertions.assertEquals(1L, afterWorkbookDispose);
} }
} }

16
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/handler/WriteHandlerTest.java

@ -7,24 +7,22 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
*
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class WriteHandlerTest { public class WriteHandlerTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeAll
@BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("writeHandler07.xlsx"); file07 = TestFileUtil.createNewFile("writeHandler07.xlsx");
file03 = TestFileUtil.createNewFile("writeHandler03.xls"); file03 = TestFileUtil.createNewFile("writeHandler03.xls");
@ -46,7 +44,6 @@ public class WriteHandlerTest {
workbookWrite(fileCsv); workbookWrite(fileCsv);
} }
@Test @Test
public void t11SheetWrite07() throws Exception { public void t11SheetWrite07() throws Exception {
sheetWrite(file07); sheetWrite(file07);
@ -72,7 +69,6 @@ public class WriteHandlerTest {
tableWrite(file03); tableWrite(file03);
} }
@Test @Test
public void t23TableWriteCsv() throws Exception { public void t23TableWriteCsv() throws Exception {
tableWrite(fileCsv); tableWrite(fileCsv);

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ComplexDataListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.head;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -25,9 +25,9 @@ public class ComplexDataListener extends AnalysisEventListener<ComplexHeadData>
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
ComplexHeadData data = list.get(0); ComplexHeadData data = list.get(0);
Assert.assertEquals(data.getString4(), "字符串4"); Assertions.assertEquals(data.getString4(), "字符串4");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ComplexHeadDataTest.java

@ -7,15 +7,15 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class ComplexHeadDataTest { public class ComplexHeadDataTest {
private static File file07; private static File file07;
@ -25,7 +25,7 @@ public class ComplexHeadDataTest {
private static File file03AutomaticMergeHead; private static File file03AutomaticMergeHead;
private static File fileCsvAutomaticMergeHead; private static File fileCsvAutomaticMergeHead;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("complexHead07.xlsx"); file07 = TestFileUtil.createNewFile("complexHead07.xlsx");
file03 = TestFileUtil.createNewFile("complexHead03.xls"); file03 = TestFileUtil.createNewFile("complexHead03.xls");

18
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ListHeadDataListener.java

@ -9,7 +9,7 @@ import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -23,10 +23,10 @@ public class ListHeadDataListener implements ReadListener<Map<Integer, String>>
@Override @Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) { public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
Assert.assertNotNull(context.readRowHolder().getRowIndex()); Assertions.assertNotNull(context.readRowHolder().getRowIndex());
headMap.forEach((key, value) -> { headMap.forEach((key, value) -> {
Assert.assertEquals(value.getRowIndex(), context.readRowHolder().getRowIndex()); Assertions.assertEquals(value.getRowIndex(), context.readRowHolder().getRowIndex());
Assert.assertEquals(value.getColumnIndex(), key); Assertions.assertEquals(value.getColumnIndex(), key);
}); });
} }
@ -37,12 +37,12 @@ public class ListHeadDataListener implements ReadListener<Map<Integer, String>>
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
Map<Integer, String> data = list.get(0); Map<Integer, String> data = list.get(0);
Assert.assertEquals("字符串0", data.get(0)); Assertions.assertEquals("字符串0", data.get(0));
Assert.assertEquals("1", data.get(1)); Assertions.assertEquals("1", data.get(1));
Assert.assertEquals("2020-01-01 01:01:01", data.get(2)); Assertions.assertEquals("2020-01-01 01:01:01", data.get(2));
Assert.assertEquals("额外数据", data.get(3)); Assertions.assertEquals("额外数据", data.get(3));
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/ListHeadDataTest.java

@ -9,24 +9,22 @@ import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
*
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class ListHeadDataTest { public class ListHeadDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeAll
@BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("listHead07.xlsx"); file07 = TestFileUtil.createNewFile("listHead07.xlsx");
file03 = TestFileUtil.createNewFile("listHead03.xls"); file03 = TestFileUtil.createNewFile("listHead03.xls");

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/NoHeadDataListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.head;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -25,9 +25,9 @@ public class NoHeadDataListener extends AnalysisEventListener<NoHeadData> {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
NoHeadData data = list.get(0); NoHeadData data = list.get(0);
Assert.assertEquals(data.getString(), "字符串0"); Assertions.assertEquals(data.getString(), "字符串0");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/head/NoHeadDataTest.java

@ -7,22 +7,22 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class NoHeadDataTest { public class NoHeadDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("noHead07.xlsx"); file07 = TestFileUtil.createNewFile("noHead07.xlsx");
file03 = TestFileUtil.createNewFile("noHead03.xls"); file03 = TestFileUtil.createNewFile("noHead03.xls");

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataListener.java

@ -5,7 +5,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -31,9 +31,9 @@ public class LargeDataListener extends AnalysisEventListener<LargeData> {
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
LOGGER.info("Large row count:{}", count); LOGGER.info("Large row count:{}", count);
if (context.readWorkbookHolder().getExcelType() != ExcelTypeEnum.CSV) { if (context.readWorkbookHolder().getExcelType() != ExcelTypeEnum.CSV) {
Assert.assertEquals(count, 464509); Assertions.assertEquals(count, 464509);
} else { } else {
Assert.assertEquals(count, 499999); Assertions.assertEquals(count, 499999);
} }
} }
} }

22
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java

@ -2,35 +2,30 @@ package com.alibaba.easyexcel.test.core.large;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.cache.Ehcache;
import com.alibaba.excel.cache.ReadCache;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.streaming.SXSSFCell; import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow; import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class LargeDataTest { public class LargeDataTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataTest.class);
private static File fileFill07; private static File fileFill07;
@ -42,7 +37,7 @@ public class LargeDataTest {
private int i = 0; private int i = 0;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx"); fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx");
fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx"); fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx");
@ -60,7 +55,6 @@ public class LargeDataTest {
LOGGER.info("Large data total time spent:{}", System.currentTimeMillis() - start); LOGGER.info("Large data total time spent:{}", System.currentTimeMillis() - start);
} }
@Test @Test
public void t02Fill() { public void t02Fill() {
try (ExcelWriter excelWriter = EasyExcel.write(fileFill07).withTemplate(template07).build()) { try (ExcelWriter excelWriter = EasyExcel.write(fileFill07).withTemplate(template07).build()) {
@ -131,7 +125,7 @@ public class LargeDataTest {
long costPoi = System.currentTimeMillis() - start; long costPoi = System.currentTimeMillis() - start;
LOGGER.info("poi write cost:{}", System.currentTimeMillis() - start); LOGGER.info("poi write cost:{}", System.currentTimeMillis() - start);
LOGGER.info("{} vs {}", cost, costPoi); LOGGER.info("{} vs {}", cost, costPoi);
Assert.assertTrue(costPoi * 2 > cost); Assertions.assertTrue(costPoi * 2 > cost);
} }
private List<LargeData> data() { private List<LargeData> data() {

16
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java

@ -8,22 +8,22 @@ import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader; import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadSheet;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class MultipleSheetsDataTest { public class MultipleSheetsDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xlsx"); file07 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xlsx");
file03 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xls"); file03 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xls");
@ -56,7 +56,7 @@ public class MultipleSheetsDataTest {
int count = 1; int count = 1;
for (ReadSheet readSheet : sheets) { for (ReadSheet readSheet : sheets) {
excelReader.read(readSheet); excelReader.read(readSheet);
Assert.assertEquals(multipleSheetsListener.getList().size(), count); Assertions.assertEquals(multipleSheetsListener.getList().size(), count);
count++; count++;
} }
} }

10
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.multiplesheets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -26,7 +26,7 @@ public class MultipleSheetsListener extends AnalysisEventListener<MultipleSheets
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
LOGGER.debug("A form is read finished."); LOGGER.debug("A form is read finished.");
Assert.assertEquals(list.get(0).getTitle(), "表1数据"); Assertions.assertEquals(list.get(0).getTitle(), "表1数据");
LOGGER.debug("All row:{}", JSON.toJSONString(list)); LOGGER.debug("All row:{}", JSON.toJSONString(list));
} }

54
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java

@ -15,16 +15,16 @@ import com.alibaba.excel.util.DateUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
@Slf4j @Slf4j
public class NoModelDataTest { public class NoModelDataTest {
@ -35,7 +35,7 @@ public class NoModelDataTest {
private static File fileRepeat03; private static File fileRepeat03;
private static File fileRepeatCsv; private static File fileRepeatCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("noModel07.xlsx"); file07 = TestFileUtil.createNewFile("noModel07.xlsx");
file03 = TestFileUtil.createNewFile("noModel03.xls"); file03 = TestFileUtil.createNewFile("noModel03.xls");
@ -63,11 +63,11 @@ public class NoModelDataTest {
private void readAndWrite(File file, File fileRepeat, boolean isCsv) throws Exception { private void readAndWrite(File file, File fileRepeat, boolean isCsv) throws Exception {
EasyExcel.write(file).sheet().doWrite(data()); EasyExcel.write(file).sheet().doWrite(data());
List<Map<Integer, String>> result = EasyExcel.read(file).headRowNumber(0).sheet().doReadSync(); List<Map<Integer, String>> result = EasyExcel.read(file).headRowNumber(0).sheet().doReadSync();
Assert.assertEquals(10, result.size()); Assertions.assertEquals(10, result.size());
Map<Integer, String> data10 = result.get(9); Map<Integer, String> data10 = result.get(9);
Assert.assertEquals("string19", data10.get(0)); Assertions.assertEquals("string19", data10.get(0));
Assert.assertEquals("109", data10.get(1)); Assertions.assertEquals("109", data10.get(1));
Assert.assertEquals("2020-01-01 01:01:01", data10.get(2)); Assertions.assertEquals("2020-01-01 01:01:01", data10.get(2));
List<Map<Integer, Object>> actualDataList = EasyExcel.read(file) List<Map<Integer, Object>> actualDataList = EasyExcel.read(file)
.headRowNumber(0) .headRowNumber(0)
@ -75,16 +75,16 @@ public class NoModelDataTest {
.sheet() .sheet()
.doReadSync(); .doReadSync();
log.info("actualDataList:{}", JSON.toJSONString(actualDataList)); log.info("actualDataList:{}", JSON.toJSONString(actualDataList));
Assert.assertEquals(10, actualDataList.size()); Assertions.assertEquals(10, actualDataList.size());
Map<Integer, Object> actualData10 = actualDataList.get(9); Map<Integer, Object> actualData10 = actualDataList.get(9);
Assert.assertEquals("string19", actualData10.get(0)); Assertions.assertEquals("string19", actualData10.get(0));
if (isCsv) { if (isCsv) {
// CSV only string type // CSV only string type
Assert.assertEquals("109", actualData10.get(1)); Assertions.assertEquals("109", actualData10.get(1));
Assert.assertEquals("2020-01-01 01:01:01", actualData10.get(2)); Assertions.assertEquals("2020-01-01 01:01:01", actualData10.get(2));
} else { } else {
Assert.assertEquals(0, new BigDecimal("109").compareTo((BigDecimal)actualData10.get(1))); Assertions.assertEquals(0, new BigDecimal("109").compareTo((BigDecimal)actualData10.get(1)));
Assert.assertEquals(LocalDateTime.of(2020, 1, 1, 1, 1, 1), actualData10.get(2)); Assertions.assertEquals(LocalDateTime.of(2020, 1, 1, 1, 1, 1), actualData10.get(2));
} }
List<Map<Integer, ReadCellData<?>>> readCellDataList = EasyExcel.read(file) List<Map<Integer, ReadCellData<?>>> readCellDataList = EasyExcel.read(file)
@ -93,25 +93,25 @@ public class NoModelDataTest {
.sheet() .sheet()
.doReadSync(); .doReadSync();
log.info("readCellDataList:{}", JSON.toJSONString(readCellDataList)); log.info("readCellDataList:{}", JSON.toJSONString(readCellDataList));
Assert.assertEquals(10, readCellDataList.size()); Assertions.assertEquals(10, readCellDataList.size());
Map<Integer, ReadCellData<?>> readCellData10 = readCellDataList.get(9); Map<Integer, ReadCellData<?>> readCellData10 = readCellDataList.get(9);
Assert.assertEquals("string19", readCellData10.get(0).getData()); Assertions.assertEquals("string19", readCellData10.get(0).getData());
if (isCsv) { if (isCsv) {
// CSV only string type // CSV only string type
Assert.assertEquals("109", readCellData10.get(1).getData()); Assertions.assertEquals("109", readCellData10.get(1).getData());
Assert.assertEquals("2020-01-01 01:01:01", readCellData10.get(2).getData()); Assertions.assertEquals("2020-01-01 01:01:01", readCellData10.get(2).getData());
} else { } else {
Assert.assertEquals(0, new BigDecimal("109").compareTo((BigDecimal)readCellData10.get(1).getData())); Assertions.assertEquals(0, new BigDecimal("109").compareTo((BigDecimal)readCellData10.get(1).getData()));
Assert.assertEquals(LocalDateTime.of(2020, 1, 1, 1, 1, 1), readCellData10.get(2).getData()); Assertions.assertEquals(LocalDateTime.of(2020, 1, 1, 1, 1, 1), readCellData10.get(2).getData());
} }
EasyExcel.write(fileRepeat).sheet().doWrite(result); EasyExcel.write(fileRepeat).sheet().doWrite(result);
result = EasyExcel.read(fileRepeat).headRowNumber(0).sheet().doReadSync(); result = EasyExcel.read(fileRepeat).headRowNumber(0).sheet().doReadSync();
Assert.assertEquals(10, result.size()); Assertions.assertEquals(10, result.size());
data10 = result.get(9); data10 = result.get(9);
Assert.assertEquals("string19", data10.get(0)); Assertions.assertEquals("string19", data10.get(0));
Assert.assertEquals("109", data10.get(1)); Assertions.assertEquals("109", data10.get(1));
Assert.assertEquals("2020-01-01 01:01:01", data10.get(2)); Assertions.assertEquals("2020-01-01 01:01:01", data10.get(2));
} }
private List<List<Object>> data() throws Exception { private List<List<Object>> data() throws Exception {

28
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataListener.java

@ -9,7 +9,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
@ -21,12 +21,12 @@ public class UnCamelDataListener extends AnalysisEventListener<UnCamelData> {
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
log.debug("Head is:{}", JSON.toJSONString(headMap)); log.debug("Head is:{}", JSON.toJSONString(headMap));
Assert.assertEquals(headMap.get(0), "string1"); Assertions.assertEquals(headMap.get(0), "string1");
Assert.assertEquals(headMap.get(1), "string2"); Assertions.assertEquals(headMap.get(1), "string2");
Assert.assertEquals(headMap.get(2), "STring3"); Assertions.assertEquals(headMap.get(2), "STring3");
Assert.assertEquals(headMap.get(3), "STring4"); Assertions.assertEquals(headMap.get(3), "STring4");
Assert.assertEquals(headMap.get(4), "STRING5"); Assertions.assertEquals(headMap.get(4), "STRING5");
Assert.assertEquals(headMap.get(5), "STRing6"); Assertions.assertEquals(headMap.get(5), "STRing6");
} }
@ -37,14 +37,14 @@ public class UnCamelDataListener extends AnalysisEventListener<UnCamelData> {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 10); Assertions.assertEquals(list.size(), 10);
UnCamelData unCamelData = list.get(0); UnCamelData unCamelData = list.get(0);
Assert.assertEquals(unCamelData.getString1(), "string1"); Assertions.assertEquals(unCamelData.getString1(), "string1");
Assert.assertEquals(unCamelData.getString2(), "string2"); Assertions.assertEquals(unCamelData.getString2(), "string2");
Assert.assertEquals(unCamelData.getSTring3(), "string3"); Assertions.assertEquals(unCamelData.getSTring3(), "string3");
Assert.assertEquals(unCamelData.getSTring4(), "string4"); Assertions.assertEquals(unCamelData.getSTring4(), "string4");
Assert.assertEquals(unCamelData.getSTRING5(), "string5"); Assertions.assertEquals(unCamelData.getSTRING5(), "string5");
Assert.assertEquals(unCamelData.getSTRing6(), "string6"); Assertions.assertEquals(unCamelData.getSTRing6(), "string6");
log.debug("First row:{}", JSON.toJSONString(list.get(0))); log.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

13
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataTest.java

@ -7,23 +7,22 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class UnCamelDataTest { public class UnCamelDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeAll
@BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("unCame07.xlsx"); file07 = TestFileUtil.createNewFile("unCame07.xlsx");
file03 = TestFileUtil.createNewFile("unCame03.xls"); file03 = TestFileUtil.createNewFile("unCame03.xls");

16
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.parameter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -25,10 +25,10 @@ public class ParameterDataListener extends AnalysisEventListener<ParameterData>
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 10); Assertions.assertEquals(list.size(), 10);
Assert.assertEquals(list.get(0).getName(), "姓名0"); Assertions.assertEquals(list.get(0).getName(), "姓名0");
Assert.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0); Assertions.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0);
Assert.assertEquals( Assertions.assertEquals(
context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名"); context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java

@ -16,21 +16,21 @@ import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.WriteTable; import com.alibaba.excel.write.metadata.WriteTable;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class ParameterDataTest { public class ParameterDataTest {
private static File file07; private static File file07;
private static File fileCsv; private static File fileCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("parameter07.xlsx"); file07 = TestFileUtil.createNewFile("parameter07.xlsx");
fileCsv = TestFileUtil.createNewFile("parameterCsv.csv"); fileCsv = TestFileUtil.createNewFile("parameterCsv.csv");

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataListener.java

@ -3,15 +3,15 @@ package com.alibaba.easyexcel.test.core.repetition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.core.simple.SimpleDataListener; import com.alibaba.easyexcel.test.core.simple.SimpleDataListener;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -26,9 +26,9 @@ public class RepetitionDataListener extends AnalysisEventListener<RepetitionData
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 2); Assertions.assertEquals(list.size(), 2);
Assert.assertEquals(list.get(0).getString(), "字符串0"); Assertions.assertEquals(list.get(0).getString(), "字符串0");
Assert.assertEquals(list.get(1).getString(), "字符串0"); Assertions.assertEquals(list.get(1).getString(), "字符串0");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java

@ -12,15 +12,15 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.WriteTable; import com.alibaba.excel.write.metadata.WriteTable;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class RepetitionDataTest { public class RepetitionDataTest {
private static File file07; private static File file07;
@ -30,7 +30,7 @@ public class RepetitionDataTest {
private static File fileTable03; private static File fileTable03;
private static File fileTableCsv; private static File fileTableCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("repetition07.xlsx"); file07 = TestFileUtil.createNewFile("repetition07.xlsx");
file03 = TestFileUtil.createNewFile("repetition03.xls"); file03 = TestFileUtil.createNewFile("repetition03.xls");

18
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataListener.java

@ -4,14 +4,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -22,7 +22,7 @@ public class SimpleDataListener extends AnalysisEventListener<SimpleData> {
@Override @Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
LOGGER.debug("Head is:{}", JSON.toJSONString(headMap)); LOGGER.debug("Head is:{}", JSON.toJSONString(headMap));
Assert.assertEquals(headMap.get(0), "姓名"); Assertions.assertEquals(headMap.get(0), "姓名");
} }
@Override @Override
@ -32,10 +32,10 @@ public class SimpleDataListener extends AnalysisEventListener<SimpleData> {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 10); Assertions.assertEquals(list.size(), 10);
Assert.assertEquals(list.get(0).getName(), "姓名0"); Assertions.assertEquals(list.get(0).getName(), "姓名0");
Assert.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0); Assertions.assertEquals((int)(context.readSheetHolder().getSheetNo()), 0);
Assert.assertEquals( Assertions.assertEquals(
context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名"); context.readSheetHolder().getExcelReadHeadProperty().getHeadMap().get(0).getHeadNameList().get(0), "姓名");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataSheetNameListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.core.simple;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -25,8 +25,8 @@ public class SimpleDataSheetNameListener extends AnalysisEventListener<SimpleDat
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
Assert.assertEquals(list.get(0).getName(), "张三"); Assertions.assertEquals(list.get(0).getName(), "张三");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

25
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java

@ -7,23 +7,22 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.alibaba.easyexcel.test.demo.read.DemoData;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener; import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
@Slf4j @Slf4j
public class SimpleDataTest { public class SimpleDataTest {
@ -31,7 +30,7 @@ public class SimpleDataTest {
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("simple07.xlsx"); file07 = TestFileUtil.createNewFile("simple07.xlsx");
file03 = TestFileUtil.createNewFile("simple03.xls"); file03 = TestFileUtil.createNewFile("simple03.xls");
@ -99,14 +98,14 @@ public class SimpleDataTest {
TestFileUtil.readFile("simple" + File.separator + "simple07.xlsx")) TestFileUtil.readFile("simple" + File.separator + "simple07.xlsx"))
.sheet("simple") .sheet("simple")
.doReadSync(); .doReadSync();
Assert.assertEquals(1, list.size()); Assertions.assertEquals(1, list.size());
} }
@Test @Test
public void t22PageReadListener07() { public void t22PageReadListener07() {
EasyExcel.read(file07, SimpleData.class, EasyExcel.read(file07, SimpleData.class,
new PageReadListener<SimpleData>(dataList -> { new PageReadListener<SimpleData>(dataList -> {
Assert.assertEquals(5, dataList.size()); Assertions.assertEquals(5, dataList.size());
}, 5)) }, 5))
.sheet().doRead(); .sheet().doRead();
} }
@ -114,9 +113,9 @@ public class SimpleDataTest {
private void synchronousRead(File file) { private void synchronousRead(File file) {
// Synchronous read file // Synchronous read file
List<Object> list = EasyExcel.read(file).head(SimpleData.class).sheet().doReadSync(); List<Object> list = EasyExcel.read(file).head(SimpleData.class).sheet().doReadSync();
Assert.assertEquals(list.size(), 10); Assertions.assertEquals(list.size(), 10);
Assert.assertTrue(list.get(0) instanceof SimpleData); Assertions.assertTrue(list.get(0) instanceof SimpleData);
Assert.assertEquals(((SimpleData)list.get(0)).getName(), "姓名0"); Assertions.assertEquals(((SimpleData)list.get(0)).getName(), "姓名0");
} }
private List<SimpleData> data() { private List<SimpleData> data() {

26
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/skip/SkipDataTest.java

@ -14,23 +14,23 @@ import com.alibaba.excel.exception.ExcelGenerateException;
import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class SkipDataTest { public class SkipDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File fileCsv; private static File fileCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("skip.xlsx"); file07 = TestFileUtil.createNewFile("skip.xlsx");
file03 = TestFileUtil.createNewFile("skip.xls"); file03 = TestFileUtil.createNewFile("skip.xls");
@ -49,7 +49,7 @@ public class SkipDataTest {
@Test @Test
public void t03ReadAndWriteCsv() { public void t03ReadAndWriteCsv() {
Assert.assertThrows(ExcelGenerateException.class, () -> readAndWrite(fileCsv)); Assertions.assertThrows(ExcelGenerateException.class, () -> readAndWrite(fileCsv));
} }
private void readAndWrite(File file) { private void readAndWrite(File file) {
@ -65,8 +65,8 @@ public class SkipDataTest {
} }
List<SkipData> list = EasyExcel.read(file, SkipData.class, null).sheet("第二个").doReadSync(); List<SkipData> list = EasyExcel.read(file, SkipData.class, null).sheet("第二个").doReadSync();
Assert.assertEquals(1, list.size()); Assertions.assertEquals(1, list.size());
Assert.assertEquals("name2", list.get(0).getName()); Assertions.assertEquals("name2", list.get(0).getName());
SyncReadListener syncReadListener = new SyncReadListener(); SyncReadListener syncReadListener = new SyncReadListener();
try (ExcelReader excelReader = EasyExcel.read(file, SkipData.class, null).registerReadListener(syncReadListener) try (ExcelReader excelReader = EasyExcel.read(file, SkipData.class, null).registerReadListener(syncReadListener)
@ -75,9 +75,9 @@ public class SkipDataTest {
ReadSheet readSheet3 = EasyExcel.readSheet("第四个").build(); ReadSheet readSheet3 = EasyExcel.readSheet("第四个").build();
excelReader.read(readSheet1, readSheet3); excelReader.read(readSheet1, readSheet3);
List<Object> syncList = syncReadListener.getList(); List<Object> syncList = syncReadListener.getList();
Assert.assertEquals(2, syncList.size()); Assertions.assertEquals(2, syncList.size());
Assert.assertEquals("name2", ((SkipData)syncList.get(0)).getName()); Assertions.assertEquals("name2", ((SkipData)syncList.get(0)).getName());
Assert.assertEquals("name4", ((SkipData)syncList.get(1)).getName()); Assertions.assertEquals("name4", ((SkipData)syncList.get(1)).getName());
} }
} }

23
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataListener.java

@ -3,13 +3,13 @@ package com.alibaba.easyexcel.test.core.sort;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -18,7 +18,6 @@ public class SortDataListener extends AnalysisEventListener<SortData> {
private static final Logger LOGGER = LoggerFactory.getLogger(SortDataListener.class); private static final Logger LOGGER = LoggerFactory.getLogger(SortDataListener.class);
List<SortData> list = new ArrayList<SortData>(); List<SortData> list = new ArrayList<SortData>();
@Override @Override
public void invoke(SortData data, AnalysisContext context) { public void invoke(SortData data, AnalysisContext context) {
list.add(data); list.add(data);
@ -26,13 +25,13 @@ public class SortDataListener extends AnalysisEventListener<SortData> {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 1); Assertions.assertEquals(list.size(), 1);
SortData sortData = list.get(0); SortData sortData = list.get(0);
Assert.assertEquals("column1", sortData.getColumn1()); Assertions.assertEquals("column1", sortData.getColumn1());
Assert.assertEquals("column2", sortData.getColumn2()); Assertions.assertEquals("column2", sortData.getColumn2());
Assert.assertEquals("column3", sortData.getColumn3()); Assertions.assertEquals("column3", sortData.getColumn3());
Assert.assertEquals("column4", sortData.getColumn4()); Assertions.assertEquals("column4", sortData.getColumn4());
Assert.assertEquals("column5", sortData.getColumn5()); Assertions.assertEquals("column5", sortData.getColumn5());
Assert.assertEquals("column6", sortData.getColumn6()); Assertions.assertEquals("column6", sortData.getColumn6());
} }
} }

42
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataTest.java

@ -9,16 +9,16 @@ import java.util.Map;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class SortDataTest { public class SortDataTest {
private static File file07; private static File file07;
@ -28,7 +28,7 @@ public class SortDataTest {
private static File sortNoHead03; private static File sortNoHead03;
private static File sortNoHeadCsv; private static File sortNoHeadCsv;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("sort.xlsx"); file07 = TestFileUtil.createNewFile("sort.xlsx");
file03 = TestFileUtil.createNewFile("sort.xls"); file03 = TestFileUtil.createNewFile("sort.xls");
@ -71,14 +71,14 @@ public class SortDataTest {
private void readAndWrite(File file) { private void readAndWrite(File file) {
EasyExcel.write(file, SortData.class).sheet().doWrite(data()); EasyExcel.write(file, SortData.class).sheet().doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals("column1", record.get(0)); Assertions.assertEquals("column1", record.get(0));
Assert.assertEquals("column2", record.get(1)); Assertions.assertEquals("column2", record.get(1));
Assert.assertEquals("column3", record.get(2)); Assertions.assertEquals("column3", record.get(2));
Assert.assertEquals("column4", record.get(3)); Assertions.assertEquals("column4", record.get(3));
Assert.assertEquals("column5", record.get(4)); Assertions.assertEquals("column5", record.get(4));
Assert.assertEquals("column6", record.get(5)); Assertions.assertEquals("column6", record.get(5));
EasyExcel.read(file, SortData.class, new SortDataListener()).sheet().doRead(); EasyExcel.read(file, SortData.class, new SortDataListener()).sheet().doRead();
} }
@ -86,14 +86,14 @@ public class SortDataTest {
private void readAndWriteNoHead(File file) { private void readAndWriteNoHead(File file) {
EasyExcel.write(file).head(head()).sheet().doWrite(data()); EasyExcel.write(file).head(head()).sheet().doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync(); List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size()); Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0); Map<Integer, String> record = dataMap.get(0);
Assert.assertEquals("column1", record.get(0)); Assertions.assertEquals("column1", record.get(0));
Assert.assertEquals("column2", record.get(1)); Assertions.assertEquals("column2", record.get(1));
Assert.assertEquals("column3", record.get(2)); Assertions.assertEquals("column3", record.get(2));
Assert.assertEquals("column4", record.get(3)); Assertions.assertEquals("column4", record.get(3));
Assert.assertEquals("column5", record.get(4)); Assertions.assertEquals("column5", record.get(4));
Assert.assertEquals("column6", record.get(5)); Assertions.assertEquals("column6", record.get(5));
EasyExcel.read(file, SortData.class, new SortDataListener()).sheet().doRead(); EasyExcel.read(file, SortData.class, new SortDataListener()).sheet().doRead();
} }

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataListener.java

@ -3,15 +3,15 @@ package com.alibaba.easyexcel.test.core.style;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.core.simple.SimpleDataListener; import com.alibaba.easyexcel.test.core.simple.SimpleDataListener;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -26,9 +26,9 @@ public class StyleDataListener extends AnalysisEventListener<StyleData> {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 2); Assertions.assertEquals(list.size(), 2);
Assert.assertEquals(list.get(0).getString(), "字符串0"); Assertions.assertEquals(list.get(0).getString(), "字符串0");
Assert.assertEquals(list.get(1).getString(), "字符串1"); Assertions.assertEquals(list.get(1).getString(), "字符串1");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

44
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java

@ -33,16 +33,16 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class StyleDataTest { public class StyleDataTest {
private static File file07; private static File file07;
@ -51,7 +51,7 @@ public class StyleDataTest {
private static File fileVerticalCellStyleStrategy207; private static File fileVerticalCellStyleStrategy207;
private static File fileLoopMergeStrategy; private static File fileLoopMergeStrategy;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("style07.xlsx"); file07 = TestFileUtil.createNewFile("style07.xlsx");
file03 = TestFileUtil.createNewFile("style03.xls"); file03 = TestFileUtil.createNewFile("style03.xls");
@ -209,30 +209,30 @@ public class StyleDataTest {
Workbook workbook = WorkbookFactory.create(file); Workbook workbook = WorkbookFactory.create(file);
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
Assert.assertEquals(50 * 256, sheet.getColumnWidth(0), 0); Assertions.assertEquals(50 * 256, sheet.getColumnWidth(0), 0);
Row row0 = sheet.getRow(0); Row row0 = sheet.getRow(0);
Assert.assertEquals(800, row0.getHeight(), 0); Assertions.assertEquals(800, row0.getHeight(), 0);
Cell cell00 = row0.getCell(0); Cell cell00 = row0.getCell(0);
Assert.assertArrayEquals(new byte[] {-1, -1, 0}, StyleTestUtils.getFillForegroundColor(cell00)); Assertions.assertArrayEquals(new byte[] {-1, -1, 0}, StyleTestUtils.getFillForegroundColor(cell00));
Assert.assertArrayEquals(new byte[] {-128, -128, 0}, StyleTestUtils.getFontColor(cell00, workbook)); Assertions.assertArrayEquals(new byte[] {-128, -128, 0}, StyleTestUtils.getFontColor(cell00, workbook));
Assert.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell00, workbook)); Assertions.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell00, workbook));
Cell cell01 = row0.getCell(1); Cell cell01 = row0.getCell(1);
Assert.assertArrayEquals(new byte[] {-1, -1, 0}, StyleTestUtils.getFillForegroundColor(cell01)); Assertions.assertArrayEquals(new byte[] {-1, -1, 0}, StyleTestUtils.getFillForegroundColor(cell01));
Assert.assertArrayEquals(new byte[] {-128, -128, 0}, StyleTestUtils.getFontColor(cell01, workbook)); Assertions.assertArrayEquals(new byte[] {-128, -128, 0}, StyleTestUtils.getFontColor(cell01, workbook));
Assert.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell01, workbook)); Assertions.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell01, workbook));
Row row1 = sheet.getRow(1); Row row1 = sheet.getRow(1);
Assert.assertEquals(1000, row1.getHeight(), 0); Assertions.assertEquals(1000, row1.getHeight(), 0);
Cell cell10 = row1.getCell(0); Cell cell10 = row1.getCell(0);
Assert.assertArrayEquals(new byte[] {0, -128, -128}, StyleTestUtils.getFillForegroundColor(cell10)); Assertions.assertArrayEquals(new byte[] {0, -128, -128}, StyleTestUtils.getFillForegroundColor(cell10));
Assert.assertArrayEquals(new byte[] {0, 51, 102}, StyleTestUtils.getFontColor(cell10, workbook)); Assertions.assertArrayEquals(new byte[] {0, 51, 102}, StyleTestUtils.getFontColor(cell10, workbook));
Assert.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell10, workbook)); Assertions.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell10, workbook));
Cell cell11 = row1.getCell(1); Cell cell11 = row1.getCell(1);
Assert.assertArrayEquals(new byte[] {0, -128, -128}, StyleTestUtils.getFillForegroundColor(cell11)); Assertions.assertArrayEquals(new byte[] {0, -128, -128}, StyleTestUtils.getFillForegroundColor(cell11));
Assert.assertArrayEquals(new byte[] {0, 51, 102}, StyleTestUtils.getFontColor(cell11, workbook)); Assertions.assertArrayEquals(new byte[] {0, 51, 102}, StyleTestUtils.getFontColor(cell11, workbook));
Assert.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell11, workbook)); Assertions.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell11, workbook));
} }
private List<StyleData> data() { private List<StyleData> data() {

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataListener.java

@ -3,15 +3,15 @@ package com.alibaba.easyexcel.test.core.template;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.core.simple.SimpleDataListener; import com.alibaba.easyexcel.test.core.simple.SimpleDataListener;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -26,9 +26,9 @@ public class TemplateDataListener extends AnalysisEventListener<TemplateData> {
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(list.size(), 2); Assertions.assertEquals(list.size(), 2);
Assert.assertEquals(list.get(0).getString0(), "字符串0"); Assertions.assertEquals(list.get(0).getString0(), "字符串0");
Assert.assertEquals(list.get(1).getString0(), "字符串1"); Assertions.assertEquals(list.get(1).getString0(), "字符串1");
LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0))); LOGGER.debug("First row:{}", JSON.toJSONString(list.get(0)));
} }
} }

14
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java

@ -7,23 +7,21 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.FixMethodOrder; import org.junit.jupiter.api.MethodOrderer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runners.MethodSorters; import org.junit.jupiter.api.TestMethodOrder;
/** /**
*
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @TestMethodOrder(MethodOrderer.MethodName.class)
public class TemplateDataTest { public class TemplateDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
@BeforeAll
@BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("template07.xlsx"); file07 = TestFileUtil.createNewFile("template07.xlsx");
file03 = TestFileUtil.createNewFile("template03.xls"); file03 = TestFileUtil.createNewFile("template03.xls");

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java

@ -16,8 +16,7 @@ import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig; import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.excel.write.metadata.fill.FillWrapper;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
/** /**
* 写的填充写法 * 写的填充写法
@ -25,7 +24,7 @@ import org.junit.Test;
* @author Jiaju Zhuang * @author Jiaju Zhuang
* @since 2.1.1 * @since 2.1.1
*/ */
@Ignore
public class FillTest { public class FillTest {
/** /**
* 最简单的填充 * 最简单的填充

7
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/rare/WriteTest.java

@ -11,10 +11,8 @@ import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.util.FileUtils; import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.util.ListUtils; import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.handler.RowWriteHandler; import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.WorkbookWriteHandler; import com.alibaba.excel.write.handler.WorkbookWriteHandler;
import com.alibaba.excel.write.handler.context.RowWriteHandlerContext; import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext;
import com.alibaba.excel.write.handler.context.WorkbookWriteHandlerContext; import com.alibaba.excel.write.handler.context.WorkbookWriteHandlerContext;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
@ -24,15 +22,14 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
/** /**
* 记录一些不太常见的案例 * 记录一些不太常见的案例
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Ignore
@Slf4j @Slf4j
public class WriteTest { public class WriteTest {

7
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/DemoExtraListener.java

@ -6,7 +6,7 @@ import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
/** /**
* 读取单元格的批注 * 读取单元格的批注
@ -27,7 +27,8 @@ public class DemoExtraListener implements ReadListener<DemoExtraData> {
log.info("读取到了一条额外信息:{}", JSON.toJSONString(extra)); log.info("读取到了一条额外信息:{}", JSON.toJSONString(extra));
switch (extra.getType()) { switch (extra.getType()) {
case COMMENT: case COMMENT:
log.info("额外信息是批注,在rowIndex:{},columnIndex;{},内容是:{}", extra.getRowIndex(), extra.getColumnIndex(), log.info("额外信息是批注,在rowIndex:{},columnIndex;{},内容是:{}", extra.getRowIndex(),
extra.getColumnIndex(),
extra.getText()); extra.getText());
break; break;
case HYPERLINK: case HYPERLINK:
@ -41,7 +42,7 @@ public class DemoExtraListener implements ReadListener<DemoExtraData> {
extra.getFirstRowIndex(), extra.getFirstColumnIndex(), extra.getLastRowIndex(), extra.getFirstRowIndex(), extra.getFirstColumnIndex(), extra.getLastRowIndex(),
extra.getLastColumnIndex(), extra.getText()); extra.getLastColumnIndex(), extra.getText());
} else { } else {
Assert.fail("Unknown hyperlink!"); Assertions.fail("Unknown hyperlink!");
} }
break; break;
case MERGE: case MERGE:

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java

@ -20,15 +20,14 @@ import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
/** /**
* 读的常见写法 * 读的常见写法
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Ignore
@Slf4j @Slf4j
public class ReadTest { public class ReadTest {

1
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/ImageDataWithAnnotation.java

@ -15,7 +15,6 @@ import lombok.Setter;
/** /**
* 图片导出类 * 图片导出类
*
*/ */
@Getter @Getter
@Setter @Setter

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

@ -46,15 +46,14 @@ import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
/** /**
* 写的常见写法 * 写的常见写法
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Ignore
public class WriteTest { public class WriteTest {
/** /**

2
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/DemoData3.java

@ -1,9 +1,7 @@
package com.alibaba.easyexcel.test.temp; package com.alibaba.easyexcel.test.temp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java

@ -5,9 +5,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
import com.alibaba.easyexcel.test.demo.fill.FillData; import com.alibaba.easyexcel.test.demo.fill.FillData;
import com.alibaba.easyexcel.test.temp.fill.FillData2; import com.alibaba.easyexcel.test.temp.fill.FillData2;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
@ -16,13 +13,15 @@ import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy; import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import org.junit.jupiter.api.Test;
/** /**
* 写的填充写法 * 写的填充写法
* *
* @since 2.1.1
* @author Jiaju Zhuang * @author Jiaju Zhuang
* @since 2.1.1
*/ */
@Ignore
public class FillTempTest { public class FillTempTest {
/** /**
@ -37,7 +36,8 @@ public class FillTempTest {
OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy = new OnceAbsoluteMergeStrategy(2, 2, 0, 1); OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy = new OnceAbsoluteMergeStrategy(2, 2, 0, 1);
String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).registerWriteHandler(onceAbsoluteMergeStrategy).withTemplate(TestFileUtil.readUserHomeFile("test/simple.xlsx")).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).registerWriteHandler(onceAbsoluteMergeStrategy)
.withTemplate(TestFileUtil.readUserHomeFile("test/simple.xlsx")).build();
WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build(); WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build();
WriteSheet writeSheet1 = EasyExcel.writerSheet(1).build(); WriteSheet writeSheet1 = EasyExcel.writerSheet(1).build();

19
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java

@ -18,8 +18,6 @@ import com.alibaba.easyexcel.test.demo.write.DemoData;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.util.NumberDataFormatterUtils;
import com.alibaba.excel.util.NumberUtils;
import com.alibaba.excel.util.PositionUtils; import com.alibaba.excel.util.PositionUtils;
import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont; import com.alibaba.excel.write.metadata.style.WriteFont;
@ -32,11 +30,10 @@ import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.IndexedColors;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
/** /**
* 临时测试 * 临时测试
@ -55,7 +52,8 @@ public class Lock2Test {
File file = new File("/Users/zhuangjiaju/IdeaProjects/easyexcel/src/test/resources/converter/converter07.xlsx"); File file = new File("/Users/zhuangjiaju/IdeaProjects/easyexcel/src/test/resources/converter/converter07.xlsx");
List<Object> list = EasyExcel.read( List<Object> list = EasyExcel.read(
"/Users/zhuangjiaju/IdeaProjects/easyexcel/easyexcel-test/target/test-classes/simpleWrite1674051907397.xlsx") "/Users/zhuangjiaju/IdeaProjects/easyexcel/easyexcel-test/target/test-classes"
+ "/simpleWrite1674051907397.xlsx")
//.useDefaultListener(false) //.useDefaultListener(false)
.sheet(0) .sheet(0)
.headRowNumber(0).doReadSync(); .headRowNumber(0).doReadSync();
@ -266,9 +264,9 @@ public class Lock2Test {
Date date = new Date(dateTime); Date date = new Date(dateTime);
double excelDate = DateUtil.getExcelDate(date); double excelDate = DateUtil.getExcelDate(date);
Assert.assertEquals("测试基本转换错误" + dateTime, format.format(date), Assertions.assertEquals("测试基本转换错误" + dateTime, format.format(date),
format.format(DateUtil.getJavaDate(excelDate, false))); format.format(DateUtil.getJavaDate(excelDate, false)));
Assert.assertEquals("测试精度5转换错误" + dateTime, format.format(date), Assertions.assertEquals("测试精度5转换错误" + dateTime, format.format(date),
format.format(DateUtil.getJavaDate(BigDecimal.valueOf(excelDate) format.format(DateUtil.getJavaDate(BigDecimal.valueOf(excelDate)
.setScale(10, RoundingMode.HALF_UP).doubleValue(), false))); .setScale(10, RoundingMode.HALF_UP).doubleValue(), false)));
LOGGER.info("date:{}", format2.format(DateUtil.getJavaDate(BigDecimal.valueOf(excelDate) LOGGER.info("date:{}", format2.format(DateUtil.getJavaDate(BigDecimal.valueOf(excelDate)
@ -353,9 +351,8 @@ public class Lock2Test {
@Test @Test
public void numberforamt99() throws Exception { public void numberforamt99() throws Exception {
LocalDateTime localDateTime=LocalDateTime.of(2023, 1, 1, 0, 0, 0, 995000000); LocalDateTime localDateTime = LocalDateTime.of(2023, 1, 1, 0, 0, 0, 995000000);
log.info("date:{}",localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))); log.info("date:{}", localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
} }

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.temp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.demo.read.DemoDataListener; import com.alibaba.easyexcel.test.demo.read.DemoDataListener;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 模板的读取类 * 模板的读取类
* *

8
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java

@ -7,8 +7,7 @@ import java.util.Map;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -17,14 +16,15 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class LockTest { public class LockTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LockTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(LockTest.class);
@Test @Test
public void test() throws Exception { public void test() throws Exception {
List<Object> list = List<Object> list =
EasyExcel.read(new FileInputStream("/Users/zhuangjiaju/Downloads/-0304.2.xlsx")).useDefaultListener(false).doReadAllSync(); EasyExcel.read(new FileInputStream("/Users/zhuangjiaju/Downloads/-0304.2.xlsx")).useDefaultListener(false)
.doReadAllSync();
for (Object data : list) { for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data)); LOGGER.info("返回数据:{}", JSON.toJSONString(data));
} }

1
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleData.java

@ -7,7 +7,6 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
/** /**
*
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Getter @Getter

11
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java

@ -7,6 +7,9 @@ import java.lang.reflect.Field;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson2.JSON;
import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
@ -22,20 +25,16 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson2.JSON;
/** /**
* 临时测试 * 临时测试
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class StyleTest { public class StyleTest {
private static final Logger LOGGER = LoggerFactory.getLogger(StyleTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(StyleTest.class);

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java

@ -14,8 +14,7 @@ import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.IndexedColors;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -24,7 +23,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class WriteLargeTest { public class WriteLargeTest {
private static final Logger LOGGER = LoggerFactory.getLogger(WriteLargeTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(WriteLargeTest.class);

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteV33Test.java

@ -16,8 +16,7 @@ import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -26,7 +25,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class WriteV33Test { public class WriteV33Test {
private static final Logger LOGGER = LoggerFactory.getLogger(WriteV33Test.class); private static final Logger LOGGER = LoggerFactory.getLogger(WriteV33Test.class);

23
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteV34Test.java

@ -3,13 +3,6 @@ package com.alibaba.easyexcel.test.temp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.demo.write.DemoData; import com.alibaba.easyexcel.test.demo.write.DemoData;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
@ -17,12 +10,18 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont; import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 临时测试 * 临时测试
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class WriteV34Test { public class WriteV34Test {
private static final Logger LOGGER = LoggerFactory.getLogger(WriteV34Test.class); private static final Logger LOGGER = LoggerFactory.getLogger(WriteV34Test.class);
@ -52,11 +51,11 @@ public class WriteV34Test {
new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(fileName,DemoData.class).head(head()).registerWriteHandler(horizontalCellStyleStrategy).sheet("模板") EasyExcel.write(fileName, DemoData.class).head(head()).registerWriteHandler(horizontalCellStyleStrategy).sheet(
"模板")
.doWrite(data(1)); .doWrite(data(1));
} }
private List<List<String>> head() { private List<List<String>> head() {
List<List<String>> list = new ArrayList<List<String>>(); List<List<String>> list = new ArrayList<List<String>>();
List<String> head0 = new ArrayList<String>(); List<String> head0 = new ArrayList<String>();
@ -70,8 +69,8 @@ public class WriteV34Test {
head3.add("日期" + System.currentTimeMillis()); head3.add("日期" + System.currentTimeMillis());
list.add(head0); list.add(head0);
list.add(head1); list.add(head1);
list.add(head2); list.add(head3); list.add(head2);
list.add(head3);
return list; return list;
} }

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Xls03Test.java

@ -6,8 +6,7 @@ import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.BeanMapUtils; import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanMap; import org.springframework.cglib.beans.BeanMap;
@ -18,7 +17,7 @@ import org.springframework.cglib.core.DebuggingClassWriter;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class Xls03Test { public class Xls03Test {
private static final Logger LOGGER = LoggerFactory.getLogger(Xls03Test.class); private static final Logger LOGGER = LoggerFactory.getLogger(Xls03Test.class);

9
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/bug/ExcelCreat.java

@ -1,14 +1,14 @@
package com.alibaba.easyexcel.test.temp.bug; package com.alibaba.easyexcel.test.temp.bug;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
/** /**
* @author jiaosong * @author jiaosong
* @desc * @desc
@ -16,7 +16,6 @@ import java.util.List;
*/ */
public class ExcelCreat { public class ExcelCreat {
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
List<DataType> data = getData(); List<DataType> data = getData();
ExcelWriter excelWriter = null; ExcelWriter excelWriter = null;

2
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/bug/HeadType.java

@ -16,14 +16,12 @@ import lombok.Setter;
@EqualsAndHashCode @EqualsAndHashCode
public class HeadType { public class HeadType {
/** /**
* 任务id * 任务id
*/ */
@ExcelProperty("任务ID") @ExcelProperty("任务ID")
private Integer id; private Integer id;
@ExcelProperty(value = "备注1") @ExcelProperty(value = "备注1")
private String firstRemark; private String firstRemark;

13
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/cache/CacheTest.java vendored

@ -4,26 +4,23 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import com.alibaba.easyexcel.test.temp.poi.Poi2Test;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.fastjson2.JSON;
import org.ehcache.Cache; import org.ehcache.Cache;
import org.ehcache.PersistentCacheManager; import org.ehcache.PersistentCacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder; import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder; import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder; import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit; import org.ehcache.config.units.MemoryUnit;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.temp.poi.Poi2Test;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.fastjson2.JSON;
/** /**
*
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class CacheTest { public class CacheTest {
private static final Logger LOGGER = LoggerFactory.getLogger(Poi2Test.class); private static final Logger LOGGER = LoggerFactory.getLogger(Poi2Test.class);

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java

@ -18,10 +18,8 @@ import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter; import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord; import org.apache.commons.csv.CSVRecord;
import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.poifs.filesystem.FileMagic;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
@Ignore
@Slf4j @Slf4j
public class CsvReadTest { public class CsvReadTest {

2
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/data/HeadType.java

@ -11,14 +11,12 @@ import lombok.Setter;
@EqualsAndHashCode @EqualsAndHashCode
public class HeadType { public class HeadType {
/** /**
* 任务id * 任务id
*/ */
@ExcelProperty("任务ID") @ExcelProperty("任务ID")
private Integer id; private Integer id;
@ExcelProperty(value = "备注1") @ExcelProperty(value = "备注1")
private String firstRemark; private String firstRemark;

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java

@ -22,8 +22,7 @@ import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,7 +31,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class DataFormatTest { public class DataFormatTest {
private static final Logger LOGGER = LoggerFactory.getLogger(Lock2Test.class); private static final Logger LOGGER = LoggerFactory.getLogger(Lock2Test.class);

162
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java

@ -120,16 +120,24 @@ import org.apache.poi.util.POILogger;
public class DataFormatter1 implements Observer { public class DataFormatter1 implements Observer {
private static final String defaultFractionWholePartFormat = "#"; private static final String defaultFractionWholePartFormat = "#";
private static final String defaultFractionFractionPartFormat = "#/##"; private static final String defaultFractionFractionPartFormat = "#/##";
/** Pattern to find a number format: "0" or "#" */ /**
* Pattern to find a number format: "0" or "#"
*/
private static final Pattern numPattern = Pattern.compile("[0#]+"); private static final Pattern numPattern = Pattern.compile("[0#]+");
/** Pattern to find days of week as text "ddd...." */ /**
* Pattern to find days of week as text "ddd...."
*/
private static final Pattern daysAsText = Pattern.compile("([d]{3,})", Pattern.CASE_INSENSITIVE); private static final Pattern daysAsText = Pattern.compile("([d]{3,})", Pattern.CASE_INSENSITIVE);
/** Pattern to find "AM/PM" marker */ /**
* Pattern to find "AM/PM" marker
*/
private static final Pattern amPmPattern = Pattern.compile("((A|P)[M/P]*)", Pattern.CASE_INSENSITIVE); private static final Pattern amPmPattern = Pattern.compile("((A|P)[M/P]*)", Pattern.CASE_INSENSITIVE);
/** Pattern to find formats with condition ranges e.g. [>=100] */ /**
* Pattern to find formats with condition ranges e.g. [>=100]
*/
private static final Pattern rangeConditionalPattern = private static final Pattern rangeConditionalPattern =
Pattern.compile(".*\\[\\s*(>|>=|<|<=|=)\\s*[0-9]*\\.*[0-9].*"); Pattern.compile(".*\\[\\s*(>|>=|<|<=|=)\\s*[0-9]*\\.*[0-9].*");
@ -167,10 +175,10 @@ public class DataFormatter1 implements Observer {
* ("#"). * ("#").
*/ */
private static final String invalidDateTimeString; private static final String invalidDateTimeString;
static { static {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
for (int i = 0; i < 255; i++) for (int i = 0; i < 255; i++) {buf.append('#');}
buf.append('#');
invalidDateTimeString = buf.toString(); invalidDateTimeString = buf.toString();
} }
@ -189,10 +197,14 @@ public class DataFormatter1 implements Observer {
*/ */
private DateFormat defaultDateformat; private DateFormat defaultDateformat;
/** <em>General</em> format for numbers. */ /**
* <em>General</em> format for numbers.
*/
private Format generalNumberFormat; private Format generalNumberFormat;
/** A default format to use when a number pattern cannot be parsed. */ /**
* A default format to use when a number pattern cannot be parsed.
*/
private Format defaultNumFormat; private Format defaultNumFormat;
/** /**
@ -202,10 +214,14 @@ public class DataFormatter1 implements Observer {
private final boolean emulateCSV; private final boolean emulateCSV;
/** stores the locale valid it the last formatting call */ /**
* stores the locale valid it the last formatting call
*/
private Locale locale; private Locale locale;
/** stores if the locale should change according to {@link LocaleUtil#getUserLocale()} */ /**
* stores if the locale should change according to {@link LocaleUtil#getUserLocale()}
*/
private boolean localeIsAdapting; private boolean localeIsAdapting;
private class LocaleChangeObservable extends Observable { private class LocaleChangeObservable extends Observable {
@ -214,19 +230,21 @@ public class DataFormatter1 implements Observer {
} }
void checkForLocaleChange(Locale newLocale) { void checkForLocaleChange(Locale newLocale) {
if (!localeIsAdapting) if (!localeIsAdapting) {return;}
return; if (newLocale.equals(locale)) {return;}
if (newLocale.equals(locale))
return;
super.setChanged(); super.setChanged();
notifyObservers(newLocale); notifyObservers(newLocale);
} }
} }
/** the Observable to notify, when the locale has been changed */ /**
* the Observable to notify, when the locale has been changed
*/
private final LocaleChangeObservable localeChangedObservable = new LocaleChangeObservable(); private final LocaleChangeObservable localeChangedObservable = new LocaleChangeObservable();
/** For logging any problems we find */ /**
* For logging any problems we find
*/
private static POILogger logger = POILogFactory.getLogger(DataFormatter.class); private static POILogger logger = POILogFactory.getLogger(DataFormatter.class);
/** /**
@ -239,8 +257,7 @@ public class DataFormatter1 implements Observer {
/** /**
* Creates a formatter using the {@link Locale#getDefault() default locale}. * Creates a formatter using the {@link Locale#getDefault() default locale}.
* *
* @param emulateCSV * @param emulateCSV whether to emulate CSV output.
* whether to emulate CSV output.
*/ */
public DataFormatter1(boolean emulateCSV) { public DataFormatter1(boolean emulateCSV) {
this(LocaleUtil.getUserLocale(), true, emulateCSV); this(LocaleUtil.getUserLocale(), true, emulateCSV);
@ -256,8 +273,7 @@ public class DataFormatter1 implements Observer {
/** /**
* Creates a formatter using the given locale. * Creates a formatter using the given locale.
* *
* @param emulateCSV * @param emulateCSV whether to emulate CSV output.
* whether to emulate CSV output.
*/ */
public DataFormatter1(Locale locale, boolean emulateCSV) { public DataFormatter1(Locale locale, boolean emulateCSV) {
this(locale, false, emulateCSV); this(locale, false, emulateCSV);
@ -266,10 +282,8 @@ public class DataFormatter1 implements Observer {
/** /**
* Creates a formatter using the given locale. * Creates a formatter using the given locale.
* *
* @param localeIsAdapting * @param localeIsAdapting (true only if locale is not user-specified)
* (true only if locale is not user-specified) * @param emulateCSV whether to emulate CSV output.
* @param emulateCSV
* whether to emulate CSV output.
*/ */
private DataFormatter1(Locale locale, boolean localeIsAdapting, boolean emulateCSV) { private DataFormatter1(Locale locale, boolean localeIsAdapting, boolean emulateCSV) {
this.localeIsAdapting = true; this.localeIsAdapting = true;
@ -292,13 +306,11 @@ public class DataFormatter1 implements Observer {
* <li>the format string cannot be recognized as either a number or date</li> * <li>the format string cannot be recognized as either a number or date</li>
* </ul> * </ul>
* *
* @param cell * @param cell The cell to retrieve a Format for
* The cell to retrieve a Format for
* @return A Format for the format String * @return A Format for the format String
*/ */
private Format getFormat(Cell cell, ConditionalFormattingEvaluator cfEvaluator) { private Format getFormat(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
if (cell == null) if (cell == null) {return null;}
return null;
ExcelNumberFormat numFmt = ExcelNumberFormat.from(cell, cfEvaluator); ExcelNumberFormat numFmt = ExcelNumberFormat.from(cell, cfEvaluator);
@ -339,7 +351,7 @@ public class DataFormatter1 implements Observer {
// CellFormat requires callers to identify date vs not, so do so // CellFormat requires callers to identify date vs not, so do so
Object cellValueO = Double.valueOf(cellValue); Object cellValueO = Double.valueOf(cellValue);
if (DateUtil.isADateFormat(formatIndex, formatStr) && if (DateUtil.isADateFormat(formatIndex, formatStr) &&
// don't try to handle Date value 0, let a 3 or 4-part format take care of it // don't try to handle Date value 0, let a 3 or 4-part format take care of it
((Double)cellValueO).doubleValue() != 0.0) { ((Double)cellValueO).doubleValue() != 0.0) {
cellValueO = DateUtil.getJavaDate(cellValue); cellValueO = DateUtil.getJavaDate(cellValue);
} }
@ -376,8 +388,7 @@ public class DataFormatter1 implements Observer {
* Create and return a Format based on the format string from a cell's style. If the pattern cannot be parsed, * Create and return a Format based on the format string from a cell's style. If the pattern cannot be parsed,
* return a default pattern. * return a default pattern.
* *
* @param cell * @param cell The Excel cell
* The Excel cell
* @return A Format representing the excel format. May return null. * @return A Format representing the excel format. May return null.
*/ */
public Format createFormat(Cell cell) { public Format createFormat(Cell cell) {
@ -399,11 +410,9 @@ public class DataFormatter1 implements Observer {
// Paranoid replacement... // Paranoid replacement...
int at = formatStr.indexOf(colour); int at = formatStr.indexOf(colour);
if (at == -1) if (at == -1) {break;}
break;
String nFormatStr = formatStr.substring(0, at) + formatStr.substring(at + colour.length()); String nFormatStr = formatStr.substring(0, at) + formatStr.substring(at + colour.length());
if (nFormatStr.equals(formatStr)) if (nFormatStr.equals(formatStr)) {break;}
break;
// Try again in case there's multiple // Try again in case there's multiple
formatStr = nFormatStr; formatStr = nFormatStr;
@ -432,7 +441,7 @@ public class DataFormatter1 implements Observer {
return generalNumberFormat; return generalNumberFormat;
} }
if ("".equals("")||(DateUtil.isADateFormat(formatIndex, formatStr) && DateUtil.isValidExcelDate(cellValue))) { if ("".equals("") || (DateUtil.isADateFormat(formatIndex, formatStr) && DateUtil.isValidExcelDate(cellValue))) {
return createDateFormat(formatStr, cellValue); return createDateFormat(formatStr, cellValue);
} }
// Excel supports fractions in format strings, which Java doesn't // Excel supports fractions in format strings, which Java doesn't
@ -760,8 +769,7 @@ public class DataFormatter1 implements Observer {
/** /**
* Returns a default format for a cell. * Returns a default format for a cell.
* *
* @param cell * @param cell The cell
* The cell
* @return a default format * @return a default format
*/ */
public Format getDefaultFormat(Cell cell) { public Format getDefaultFormat(Cell cell) {
@ -795,10 +803,8 @@ public class DataFormatter1 implements Observer {
* number format, or no rules apply, the cell's style format is used. If the style does not have a format, the * number format, or no rules apply, the cell's style format is used. If the style does not have a format, the
* default date format is applied. * default date format is applied.
* *
* @param cell * @param cell to format
* to format * @param cfEvaluator ConditionalFormattingEvaluator (if available)
* @param cfEvaluator
* ConditionalFormattingEvaluator (if available)
* @return Formatted value * @return Formatted value
*/ */
private String getFormattedDateString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) { private String getFormattedDateString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
@ -819,10 +825,8 @@ public class DataFormatter1 implements Observer {
* Format comes from either the highest priority conditional format rule with a specified format, or from the cell * Format comes from either the highest priority conditional format rule with a specified format, or from the cell
* style. * style.
* *
* @param cell * @param cell The cell
* The cell * @param cfEvaluator if available, or null
* @param cfEvaluator
* if available, or null
* @return a formatted number string * @return a formatted number string
*/ */
private String getFormattedNumberString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) { private String getFormattedNumberString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
@ -905,8 +909,7 @@ public class DataFormatter1 implements Observer {
* will not be evaluated. * will not be evaluated.
* </p> * </p>
* *
* @param cell * @param cell The cell
* The cell
* @return the formatted cell value as a String * @return the formatted cell value as a String
*/ */
public String formatCellValue(Cell cell) { public String formatCellValue(Cell cell) {
@ -924,10 +927,8 @@ public class DataFormatter1 implements Observer {
* String will be returned. The caller is responsible for setting the currentRow on the evaluator * String will be returned. The caller is responsible for setting the currentRow on the evaluator
* </p> * </p>
* *
* @param cell * @param cell The cell (can be null)
* The cell (can be null) * @param evaluator The FormulaEvaluator (can be null)
* @param evaluator
* The FormulaEvaluator (can be null)
* @return a string value of the cell * @return a string value of the cell
*/ */
public String formatCellValue(Cell cell, FormulaEvaluator evaluator) { public String formatCellValue(Cell cell, FormulaEvaluator evaluator) {
@ -953,12 +954,9 @@ public class DataFormatter1 implements Observer {
* The two evaluators should be from the same context, to avoid inconsistencies in cached values. * The two evaluators should be from the same context, to avoid inconsistencies in cached values.
* </p> * </p>
* *
* @param cell * @param cell The cell (can be null)
* The cell (can be null) * @param evaluator The FormulaEvaluator (can be null)
* @param evaluator * @param cfEvaluator ConditionalFormattingEvaluator (can be null)
* The FormulaEvaluator (can be null)
* @param cfEvaluator
* ConditionalFormattingEvaluator (can be null)
* @return a string value of the cell * @return a string value of the cell
*/ */
public String formatCellValue(Cell cell, FormulaEvaluator evaluator, ConditionalFormattingEvaluator cfEvaluator) { public String formatCellValue(Cell cell, FormulaEvaluator evaluator, ConditionalFormattingEvaluator cfEvaluator) {
@ -978,10 +976,10 @@ public class DataFormatter1 implements Observer {
switch (cellType) { switch (cellType) {
case NUMERIC: case NUMERIC:
// if (DateUtil.isCellDateFormatted(cell, cfEvaluator)) { // if (DateUtil.isCellDateFormatted(cell, cfEvaluator)) {
return getFormattedDateString(cell, cfEvaluator); return getFormattedDateString(cell, cfEvaluator);
// } // }
// return getFormattedNumberString(cell, cfEvaluator); // return getFormattedNumberString(cell, cfEvaluator);
case STRING: case STRING:
return cell.getRichStringCellValue().getString(); return cell.getRichStringCellValue().getString();
@ -1009,8 +1007,7 @@ public class DataFormatter1 implements Observer {
* <code>Number</code> value. * <code>Number</code> value.
* </p> * </p>
* *
* @param format * @param format A Format instance to be used as a default
* A Format instance to be used as a default
* @see java.text.Format#format * @see java.text.Format#format
*/ */
public void setDefaultNumberFormat(Format format) { public void setDefaultNumberFormat(Format format) {
@ -1030,10 +1027,8 @@ public class DataFormatter1 implements Observer {
* <code>Number</code> value. * <code>Number</code> value.
* </p> * </p>
* *
* @param excelFormatStr * @param excelFormatStr The data format string
* The data format string * @param format A Format instance
* @param format
* A Format instance
*/ */
public void addFormat(String excelFormatStr, Format format) { public void addFormat(String excelFormatStr, Format format) {
formats.put(excelFormatStr, format); formats.put(excelFormatStr, format);
@ -1061,10 +1056,8 @@ public class DataFormatter1 implements Observer {
/** /**
* Enables custom rounding mode on the given Decimal Format. * Enables custom rounding mode on the given Decimal Format.
* *
* @param format * @param format DecimalFormat
* DecimalFormat * @param roundingMode RoundingMode
* @param roundingMode
* RoundingMode
*/ */
public static void setExcelStyleRoundingMode(DecimalFormat format, RoundingMode roundingMode) { public static void setExcelStyleRoundingMode(DecimalFormat format, RoundingMode roundingMode) {
format.setRoundingMode(roundingMode); format.setRoundingMode(roundingMode);
@ -1086,17 +1079,13 @@ public class DataFormatter1 implements Observer {
/** /**
* Update formats when locale has been changed * Update formats when locale has been changed
* *
* @param observable * @param observable usually this is our own Observable instance
* usually this is our own Observable instance * @param localeObj only reacts on Locale objects
* @param localeObj
* only reacts on Locale objects
*/ */
public void update(Observable observable, Object localeObj) { public void update(Observable observable, Object localeObj) {
if (!(localeObj instanceof Locale)) if (!(localeObj instanceof Locale)) {return;}
return;
Locale newLocale = (Locale)localeObj; Locale newLocale = (Locale)localeObj;
if (!localeIsAdapting || newLocale.equals(locale)) if (!localeIsAdapting || newLocale.equals(locale)) {return;}
return;
locale = newLocale; locale = newLocale;
@ -1141,7 +1130,9 @@ public class DataFormatter1 implements Observer {
// enforce singleton // enforce singleton
} }
/** Format a number as an SSN */ /**
* Format a number as an SSN
*/
public static String format(Number num) { public static String format(Number num) {
String result = df.format(num); String result = df.format(num);
return result.substring(0, 3) + '-' + result.substring(3, 5) + '-' + result.substring(5, 9); return result.substring(0, 3) + '-' + result.substring(3, 5) + '-' + result.substring(5, 9);
@ -1172,7 +1163,9 @@ public class DataFormatter1 implements Observer {
// enforce singleton // enforce singleton
} }
/** Format a number as Zip + 4 */ /**
* Format a number as Zip + 4
*/
public static String format(Number num) { public static String format(Number num) {
String result = df.format(num); String result = df.format(num);
return result.substring(0, 5) + '-' + result.substring(5, 9); return result.substring(0, 5) + '-' + result.substring(5, 9);
@ -1203,7 +1196,9 @@ public class DataFormatter1 implements Observer {
// enforce singleton // enforce singleton
} }
/** Format a number as a phone number */ /**
* Format a number as a phone number
*/
public static String format(Number num) { public static String format(Number num) {
String result = df.format(num); String result = df.format(num);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -1243,7 +1238,6 @@ public class DataFormatter1 implements Observer {
* *
* This format is used to simulate Excel's handling of a format string of all # when the value is 0. Excel will * This format is used to simulate Excel's handling of a format string of all # when the value is 0. Excel will
* output "", Java will output "0". * output "", Java will output "0".
*
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
private static final class ConstantStringFormat extends Format { private static final class ConstantStringFormat extends Format {

9
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java

@ -16,16 +16,15 @@ import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig; import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.excel.write.metadata.fill.FillWrapper;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
/** /**
* 写的填充写法 * 写的填充写法
* *
* @since 2.1.1
* @author Jiaju Zhuang * @author Jiaju Zhuang
* @since 2.1.1
*/ */
@Ignore
public class FillTempTest { public class FillTempTest {
/** /**
* 最简单的填充 * 最简单的填充
@ -35,7 +34,7 @@ public class FillTempTest {
@Test @Test
public void simpleFill() { public void simpleFill() {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
String templateFileName ="/Users/zhuangjiaju/Downloads/simple.xlsx"; String templateFileName = "/Users/zhuangjiaju/Downloads/simple.xlsx";
// 方案1 根据对象填充 // 方案1 根据对象填充
String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx";

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java

@ -7,10 +7,8 @@ import java.util.List;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
@Ignore
public class Issue1662Test { public class Issue1662Test {
@Test @Test
public void test1662() { public void test1662() {
@ -19,7 +17,6 @@ public class Issue1662Test {
EasyExcel.write(fileName).head(head()).sheet("模板").doWrite(dataList()); EasyExcel.write(fileName).head(head()).sheet("模板").doWrite(dataList());
} }
private List<List<String>> head() { private List<List<String>> head() {
List<List<String>> list = new ArrayList<List<String>>(); List<List<String>> list = new ArrayList<List<String>>();
List<String> head0 = new ArrayList<String>(); List<String> head0 = new ArrayList<String>();

10
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java

@ -15,13 +15,11 @@ import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig; import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.excel.write.metadata.fill.FillWrapper;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
@Ignore
public class FillTest { public class FillTest {
@Test @Test
public void TestFillNullPoint(){ public void TestFillNullPoint() {
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "temp/issue1663" + File.separator + "template.xlsx"; TestFileUtil.getPath() + "temp/issue1663" + File.separator + "template.xlsx";
@ -37,8 +35,10 @@ public class FillTest {
excelWriter.fill(map, writeSheet); excelWriter.fill(map, writeSheet);
excelWriter.finish(); excelWriter.finish();
} }
private List<com.alibaba.easyexcel.test.demo.fill.FillData> data() { private List<com.alibaba.easyexcel.test.demo.fill.FillData> data() {
List<com.alibaba.easyexcel.test.demo.fill.FillData> list = new ArrayList<com.alibaba.easyexcel.test.demo.fill.FillData>(); List<com.alibaba.easyexcel.test.demo.fill.FillData> list
= new ArrayList<com.alibaba.easyexcel.test.demo.fill.FillData>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
com.alibaba.easyexcel.test.demo.fill.FillData fillData = new FillData(); com.alibaba.easyexcel.test.demo.fill.FillData fillData = new FillData();
list.add(fillData); list.add(fillData);

26
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue2443/Issue2443Test.java

@ -1,19 +1,20 @@
package com.alibaba.easyexcel.test.temp.issue2443; package com.alibaba.easyexcel.test.temp.issue2443;
import java.io.File;
import java.text.ParseException;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.read.listener.PageReadListener; import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.util.NumberUtils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Ignore; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.*;
import java.io.File;
import java.text.ParseException;
@Ignore
@Slf4j @Slf4j
public class Issue2443Test { public class Issue2443Test {
//CS304 (manually written) Issue link: https://github.com/alibaba/easyexcel/issues/2443 //CS304 (manually written) Issue link: https://github.com/alibaba/easyexcel/issues/2443
@ -26,6 +27,7 @@ public class Issue2443Test {
} }
})).sheet().doRead(); })).sheet().doRead();
} }
//CS304 (manually written) Issue link: https://github.com/alibaba/easyexcel/issues/2443 //CS304 (manually written) Issue link: https://github.com/alibaba/easyexcel/issues/2443
@Test @Test
public void IssueTest2() { public void IssueTest2() {
@ -41,16 +43,16 @@ public class Issue2443Test {
public void parseIntegerTest1() throws ParseException { public void parseIntegerTest1() throws ParseException {
String string = "1.00"; String string = "1.00";
ExcelContentProperty contentProperty = null; ExcelContentProperty contentProperty = null;
int Int = NumberUtils.parseInteger(string,contentProperty); int Int = NumberUtils.parseInteger(string, contentProperty);
assertEquals(1, Int); Assertions.assertEquals(1, Int);
} }
@Test @Test
public void parseIntegerTest2() throws ParseException { public void parseIntegerTest2() throws ParseException {
String string = "2.00"; String string = "2.00";
ExcelContentProperty contentProperty = null; ExcelContentProperty contentProperty = null;
int Int = NumberUtils.parseInteger(string,contentProperty); int Int = NumberUtils.parseInteger(string, contentProperty);
assertEquals(2, Int); Assertions.assertEquals(2, Int);
} }
} }

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/LargeDataListener.java

@ -1,12 +1,12 @@
package com.alibaba.easyexcel.test.temp.large; package com.alibaba.easyexcel.test.temp.large;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/NoModelLargeDataListener.java

@ -2,13 +2,13 @@ package com.alibaba.easyexcel.test.temp.large;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */

19
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java

@ -19,17 +19,16 @@ import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow; import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Ignore
public class TempLargeDataTest { public class TempLargeDataTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataTest.class);
@ -42,7 +41,7 @@ public class TempLargeDataTest {
private static File fileWriteTemp07; private static File fileWriteTemp07;
private static File fileWritePoi07; private static File fileWritePoi07;
@BeforeClass @BeforeAll
public static void init() { public static void init() {
fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx"); fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx");
fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx"); fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx");
@ -124,7 +123,7 @@ public class TempLargeDataTest {
long costPoi = System.currentTimeMillis() - start; long costPoi = System.currentTimeMillis() - start;
LOGGER.info("poi write cost:{}", System.currentTimeMillis() - start); LOGGER.info("poi write cost:{}", System.currentTimeMillis() - start);
LOGGER.info("{} vs {}", cost, costPoi); LOGGER.info("{} vs {}", cost, costPoi);
Assert.assertTrue(costPoi * 2 > cost); Assertions.assertTrue(costPoi * 2 > cost);
} }
@Test @Test
@ -167,9 +166,9 @@ public class TempLargeDataTest {
for (int j = 0; j < 25; j++) { for (int j = 0; j < 25; j++) {
String str = "str-" + j + "-" + i; String str = "str-" + j + "-" + i;
//if (i + 10000 == j) { //if (i + 10000 == j) {
SXSSFCell cell = row.createCell(j); SXSSFCell cell = row.createCell(j);
cell.setCellValue(str); cell.setCellValue(str);
//System.out.println(str); //System.out.println(str);
//} //}
} }
if (i % 5000 == 0) { if (i % 5000 == 0) {

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi2Test.java

@ -8,8 +8,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -18,7 +17,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class Poi2Test { public class Poi2Test {
private static final Logger LOGGER = LoggerFactory.getLogger(Poi2Test.class); private static final Logger LOGGER = LoggerFactory.getLogger(Poi2Test.class);

9
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java

@ -4,6 +4,8 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
@ -12,19 +14,16 @@ import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.crypt.EncryptionMode; import org.apache.poi.poifs.crypt.EncryptionMode;
import org.apache.poi.poifs.crypt.Encryptor; import org.apache.poi.poifs.crypt.Encryptor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.util.TestFileUtil;
/** /**
* 测试poi * 测试poi
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class Poi3Test { public class Poi3Test {
private static final Logger LOGGER = LoggerFactory.getLogger(Poi3Test.class); private static final Logger LOGGER = LoggerFactory.getLogger(Poi3Test.class);

10
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiEncryptTest.java

@ -17,28 +17,24 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
/** /**
* TODO * TODO
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Ignore
public class PoiEncryptTest { public class PoiEncryptTest {
@Test @Test
public void encrypt() throws Exception { public void encrypt() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFWorkbook workbook = new XSSFWorkbook();
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(workbook); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(workbook);
Sheet sheet = sxssfWorkbook.createSheet("sheet1"); Sheet sheet = sxssfWorkbook.createSheet("sheet1");
sheet.createRow(0).createCell(0).setCellValue("T2"); sheet.createRow(0).createCell(0).setCellValue("T2");
POIFSFileSystem fs = new POIFSFileSystem(); POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
@ -62,7 +58,7 @@ public class PoiEncryptTest {
@Test @Test
public void encryptExcel() throws Exception { public void encryptExcel() throws Exception {
EasyExcel.write(TestFileUtil.createNewFile("encryptv2" + System.currentTimeMillis() + ".xlsx"), EasyExcel.write(TestFileUtil.createNewFile("encryptv2" + System.currentTimeMillis() + ".xlsx"),
EncryptData.class).password("123456") EncryptData.class).password("123456")
.sheet().doWrite(data()); .sheet().doWrite(data());
} }

5
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiFormatTest.java

@ -11,8 +11,7 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,7 +20,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class PoiFormatTest { public class PoiFormatTest {
private static final Logger LOGGER = LoggerFactory.getLogger(PoiFormatTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(PoiFormatTest.class);

9
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java

@ -28,8 +28,7 @@ import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -38,7 +37,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class PoiTest { public class PoiTest {
private static final Logger LOGGER = LoggerFactory.getLogger(PoiTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(PoiTest.class);
@ -84,7 +83,6 @@ public class PoiTest {
LOGGER.info("bbb:{}", cellStyle1.getFont().getBold()); LOGGER.info("bbb:{}", cellStyle1.getFont().getBold());
LOGGER.info("bbb:{}", cellStyle1.getFont().getFontName()); LOGGER.info("bbb:{}", cellStyle1.getFont().getFontName());
XSSFFont xssfFont = xssfWorkbook.createFont(); XSSFFont xssfFont = xssfWorkbook.createFont();
xssfFont.setColor(myColor); xssfFont.setColor(myColor);
@ -94,7 +92,6 @@ public class PoiTest {
cellStyle1.setFont(xssfFont); cellStyle1.setFont(xssfFont);
cellStyle1.setFillForegroundColor(IndexedColors.PINK.getIndex()); cellStyle1.setFillForegroundColor(IndexedColors.PINK.getIndex());
LOGGER.info("aaa:{}", cellStyle1.getFont().getColor()); LOGGER.info("aaa:{}", cellStyle1.getFont().getColor());
row.getCell(1).setCellStyle(cellStyle1); row.getCell(1).setCellStyle(cellStyle1);
@ -118,7 +115,6 @@ public class PoiTest {
xssfWorkbook.close(); xssfWorkbook.close();
} }
@Test @Test
public void lastRowNumXSSFv22() throws IOException { public void lastRowNumXSSFv22() throws IOException {
@ -142,7 +138,6 @@ public class PoiTest {
LOGGER.info("bbb:{}", cellStyle1.getFont(xssfWorkbook).getColor()); LOGGER.info("bbb:{}", cellStyle1.getFont(xssfWorkbook).getColor());
HSSFFont xssfFont = xssfWorkbook.createFont(); HSSFFont xssfFont = xssfWorkbook.createFont();
xssfFont.setColor(cellStyle1.getFont(xssfWorkbook).getColor()); xssfFont.setColor(cellStyle1.getFont(xssfWorkbook).getColor());

10
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java

@ -14,8 +14,7 @@ import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow; import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -24,7 +23,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class PoiWriteTest { public class PoiWriteTest {
private static final Logger LOGGER = LoggerFactory.getLogger(PoiWriteTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(PoiWriteTest.class);
@ -110,11 +109,12 @@ public class PoiWriteTest {
@Test @Test
public void part4() throws IOException { public void part4() throws IOException {
//URL url=new URL("http://120.55.161.4/group1/M00/00/00/i8QJ8WFfwMiAXKYrAAACqC1MFiY641.png"); //URL url=new URL("http://120.55.161.4/group1/M00/00/00/i8QJ8WFfwMiAXKYrAAACqC1MFiY641.png");
URL url=new URL("https://img-blog.csdn.net/20160729002743309?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center"); URL url = new URL(
"https://img-blog.csdn.net/20160729002743309?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T"
+ "/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center");
InputStream in = new BufferedInputStream(url.openStream()); InputStream in = new BufferedInputStream(url.openStream());
} }
} }

11
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/CommentTest.java

@ -4,21 +4,20 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.data.CellData; import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 临时测试 * 临时测试
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class CommentTest { public class CommentTest {
private static final Logger LOGGER = LoggerFactory.getLogger(CommentTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(CommentTest.class);

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HDListener.java

@ -2,13 +2,13 @@ package com.alibaba.easyexcel.test.temp.read;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 模板的读取类 * 模板的读取类
* *

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadListener.java

@ -2,13 +2,13 @@ package com.alibaba.easyexcel.test.temp.read;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 模板的读取类 * 模板的读取类
* *

2
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadData.java

@ -15,7 +15,7 @@ import lombok.Setter;
@Setter @Setter
@EqualsAndHashCode @EqualsAndHashCode
public class HeadReadData { public class HeadReadData {
@ExcelProperty({"主标题","数据1"}) @ExcelProperty({"主标题", "数据1"})
private String h1; private String h1;
@ExcelProperty({"主标题", "数据2"}) @ExcelProperty({"主标题", "数据2"})
private String h2; private String h2;

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java

@ -6,8 +6,7 @@ import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.cache.Ehcache; import com.alibaba.excel.cache.Ehcache;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,7 +15,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class HeadReadTest { public class HeadReadTest {
private static final Logger LOGGER = LoggerFactory.getLogger(HeadReadTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(HeadReadTest.class);
@ -38,5 +37,4 @@ public class HeadReadTest {
EasyExcel.read(file, HeadReadData.class, new HDListener()).readCache(new Ehcache(20)).sheet(0).doRead(); EasyExcel.read(file, HeadReadData.class, new HDListener()).readCache(new Ehcache(20)).sheet(0).doRead();
} }
} }

23
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java

@ -6,27 +6,27 @@ import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 测试poi * 测试poi
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Ignore
public class HgTest { public class HgTest {
private static final Logger LOGGER = LoggerFactory.getLogger(HgTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(HgTest.class);
@Test @Test
public void hh() throws IOException { public void hh() throws IOException {
List<Object> list = List<Object> list =
EasyExcel.read(new FileInputStream("D:\\test\\201909301017rule.xlsx")).headRowNumber(2).sheet().doReadSync(); EasyExcel.read(new FileInputStream("D:\\test\\201909301017rule.xlsx")).headRowNumber(2).sheet()
.doReadSync();
for (Object data : list) { for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data)); LOGGER.info("返回数据:{}", JSON.toJSONString(data));
} }
@ -34,7 +34,11 @@ public class HgTest {
@Test @Test
public void hh5() throws IOException { public void hh5() throws IOException {
URL url = new URL("http://hotelcontractfil.oss-cn-beijing.aliyuncs.com/2019/%E5%98%89%E6%83%A0-%E4%B8%AD%E4%BA%A4%E5%BB%BA_2019-09-01_2019-09-30_1569055677522.xlsx?Expires=1884415681&OSSAccessKeyId=LTAIGZDkqZfPArBr&Signature=Rf0gbO8vl3l%2Brj1KdyzHHMsUhCE%3D"); URL url = new URL(
"http://hotelcontractfil.oss-cn-beijing.aliyuncs"
+ ".com/2019/%E5%98%89%E6%83%A0-%E4%B8%AD%E4%BA%A4%E5%BB%BA_2019-09-01_2019-09-30_1569055677522"
+ ".xlsx?Expires=1884415681&OSSAccessKeyId=LTAIGZDkqZfPArBr&Signature=Rf0gbO8vl3l%2Brj1KdyzHHMsUhCE"
+ "%3D");
InputStream is = url.openStream(); InputStream is = url.openStream();
List<Object> list = List<Object> list =
EasyExcel.read(is).headRowNumber(0).sheet().doReadSync(); EasyExcel.read(is).headRowNumber(0).sheet().doReadSync();
@ -45,7 +49,8 @@ public class HgTest {
@Test @Test
public void hh2() throws IOException { public void hh2() throws IOException {
EasyExcel.read(new FileInputStream("D:\\test\\商户不匹配工单信息收集表格.xlsx")).registerReadListener(new HgListener()) EasyExcel.read(new FileInputStream("D:\\test\\商户不匹配工单信息收集表格.xlsx")).registerReadListener(
new HgListener())
.headRowNumber(0).sheet().doRead(); .headRowNumber(0).sheet().doRead();
} }

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/simple/RepeatListener.java

@ -3,15 +3,15 @@ package com.alibaba.easyexcel.test.temp.simple;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.demo.read.DemoDataListener; import com.alibaba.easyexcel.test.demo.read.DemoDataListener;
import com.alibaba.easyexcel.test.temp.LockData; import com.alibaba.easyexcel.test.temp.LockData;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* 模板的读取类 * 模板的读取类
* *

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save