Commit 3d4fb17e by zhongmh

update test code

parent f8bb7e43
......@@ -3,7 +3,6 @@ package cn.yunmaozj.tools.excel.core;
import cn.yunmaozj.tools.excel.core.utils.ExcelRowDataModel;
import cn.yunmaozj.tools.excel.core.utils.ExcelRowTitleModel;
import cn.yunmaozj.tools.excel.model.ModelPropertyDescriptor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
......@@ -13,7 +12,6 @@ import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* 默认的excel导入工具
......@@ -22,7 +20,7 @@ import java.util.Map;
* @email zhongmh@yunmaozj.com
* @create 2020-06-24 15:04
*/
public class DefaultExcelImport<T> {
public class DefaultExcelImport {
private Workbook workbook;
......@@ -38,13 +36,13 @@ public class DefaultExcelImport<T> {
this.workbook = new XSSFWorkbook(inputStream);
}
public List<T> getData(ImportSheet<T> sheet) throws IOException {
public <T>List<T> getData(ImportSheet<T> sheet) throws IOException {
return sheet.getData(workbook);
}
public List<T> getData(String sheetName,ImportSheet<T> sheet) throws IOException {
public <T>List<T> getData(String sheetName,ImportSheet<T> sheet) throws IOException {
return sheet.getData(sheetName,workbook);
}
public List<T> getData(int index,ImportSheet<T> sheet) throws IOException {
public <T>List<T> getData(int index,ImportSheet<T> sheet) throws IOException {
return sheet.getData(index,workbook);
}
......
......@@ -37,51 +37,10 @@ public class OpusModel {
@ExcelFieldRow("话题")
private String topics;
public String getTitle() {
return title;
}
@ExcelFieldRow("browseNumber")
private Integer browseNumber;
public void setTitle(String title) {
this.title = title;
}
@ExcelFieldRow("like number")
private int likeNumber;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getResource() {
return resource;
}
public void setResource(String resource) {
this.resource = resource;
}
public String getOpusType() {
return opusType;
}
public void setOpusType(String opusType) {
this.opusType = opusType;
}
public String getTopics() {
return topics;
}
public void setTopics(String topics) {
this.topics = topics;
}
}
......@@ -2,6 +2,7 @@ package com.yunmaozj.excel.opus;
import cn.yunmaozj.tools.excel.core.DefaultExcelExport;
import com.yunmaozj.excel.model.OpusModel;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
......@@ -9,6 +10,16 @@ import java.util.Arrays;
public class DefaultExcelExportTest {
private String excelFile;
@Before
public void generate() {
excelFile = new StringBuilder()
.append("/tmp/")
.append(System.currentTimeMillis())
.append(".xlsx").toString();
}
@Test
public void writeFileTest() throws IOException {
......@@ -19,11 +30,13 @@ public class DefaultExcelExportTest {
model.setResource("/2020/22/2/2/2.jpg");
model.setOpusType("video");
model.setTopics("test");
model.setBrowseNumber(0);
model.setLikeNumber(100);
DefaultExcelExport excelExport = new DefaultExcelExport();
excelExport.writeData(new DefaultExcelExport.ExportSheet(OpusModel.class, Arrays.asList(model)));
excelExport.writeData(new DefaultExcelExport.ExportSheet(OpusModel.class,"sheet 2", Arrays.asList(model)));
excelExport.writeData(new DefaultExcelExport.ExportSheet(OpusModel.class, "sheet 2", Arrays.asList(model)));
excelExport.writeFile("/tmp/test.xlsx");
excelExport.writeFile(excelFile);
}
}
......@@ -60,5 +60,10 @@ public class DefaultExcelImportTest {
Assert.assertTrue(list.size() == 1);
opusModel = list.get(0);
Assert.assertEquals("test1",opusModel.getTopics());
list = defaultExcelImport.getData(new DefaultExcelImport.ImportSheet(OpusModel.class));
Assert.assertTrue(list.size() == 1);
opusModel = list.get(0);
Assert.assertEquals("test",opusModel.getTopics());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment