mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add test
This commit is contained in:
parent
6b3fc153d7
commit
3ed26fe761
@ -0,0 +1,46 @@
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class CellEditorTest {
|
||||
|
||||
@org.junit.Test
|
||||
public void readTest(){
|
||||
ExcelReader excelReader= ExcelUtil.getReader("cell_editor_test.xlsx");
|
||||
excelReader.setCellEditor(new ExcelHandler());
|
||||
List<Test> excelReaderObjects=excelReader.readAll(Test.class);
|
||||
|
||||
Assert.assertEquals("0", excelReaderObjects.get(0).getTest1());
|
||||
Assert.assertEquals("b", excelReaderObjects.get(0).getTest2());
|
||||
Assert.assertEquals("0", excelReaderObjects.get(1).getTest1());
|
||||
Assert.assertEquals("b1", excelReaderObjects.get(1).getTest2());
|
||||
Assert.assertEquals("0", excelReaderObjects.get(2).getTest1());
|
||||
Assert.assertEquals("c2", excelReaderObjects.get(2).getTest2());
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public static class Test implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String test1;
|
||||
private String test2;
|
||||
}
|
||||
|
||||
public static class ExcelHandler implements CellEditor {
|
||||
@ Override
|
||||
public Object edit(Cell cell, Object o) {
|
||||
if (cell.getColumnIndex()==0 && cell.getRowIndex() != 0){
|
||||
o="0";
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
||||
}
|
BIN
hutool-poi/src/test/resources/cell_editor_test.xlsx
Normal file
BIN
hutool-poi/src/test/resources/cell_editor_test.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user