Browse Source

修改单元测试

developing
Jiaju Zhuang 3 years ago
parent
commit
06d3b4bba4
  1. 10
      src/main/java/com/alibaba/excel/metadata/AbstractHolder.java
  2. 38
      src/main/java/com/alibaba/excel/metadata/GlobalConfiguration.java
  3. 14
      src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
  4. 7
      src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
  5. 2
      src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java
  6. 9
      src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java

10
src/main/java/com/alibaba/excel/metadata/AbstractHolder.java

@ -1,7 +1,6 @@
package com.alibaba.excel.metadata;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.alibaba.excel.converters.Converter;
@ -55,19 +54,16 @@ public abstract class AbstractHolder implements ConfigurationHolder {
}
this.globalConfiguration = new GlobalConfiguration();
if (basicParameter.getAutoTrim() == null) {
if (prentAbstractHolder == null) {
globalConfiguration.setAutoTrim(Boolean.TRUE);
} else {
if (prentAbstractHolder != null) {
globalConfiguration.setAutoTrim(prentAbstractHolder.getGlobalConfiguration().getAutoTrim());
}
} else {
globalConfiguration.setAutoTrim(basicParameter.getAutoTrim());
}
if (basicParameter.getLocale() == null) {
if (prentAbstractHolder == null) {
globalConfiguration.setLocale(Locale.getDefault());
} else {
if (prentAbstractHolder != null) {
globalConfiguration.setLocale(prentAbstractHolder.getGlobalConfiguration().getLocale());
}
} else {

38
src/main/java/com/alibaba/excel/metadata/GlobalConfiguration.java

@ -2,11 +2,14 @@ package com.alibaba.excel.metadata;
import java.util.Locale;
import lombok.Data;
/**
* Global configuration
*
* @author Jiaju Zhuang
*/
@Data
public class GlobalConfiguration {
/**
* Automatic trim includes sheet name and content
@ -32,35 +35,10 @@ public class GlobalConfiguration {
*/
private Boolean useScientificFormat;
public Boolean getUse1904windowing() {
return use1904windowing;
}
public void setUse1904windowing(Boolean use1904windowing) {
this.use1904windowing = use1904windowing;
}
public Boolean getAutoTrim() {
return autoTrim;
}
public void setAutoTrim(Boolean autoTrim) {
this.autoTrim = autoTrim;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public Boolean getUseScientificFormat() {
return useScientificFormat;
}
public void setUseScientificFormat(Boolean useScientificFormat) {
this.useScientificFormat = useScientificFormat;
public GlobalConfiguration() {
this.autoTrim = Boolean.TRUE;
this.use1904windowing = Boolean.FALSE;
this.locale = Locale.getDefault();
this.useScientificFormat = Boolean.FALSE;
}
}

14
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java

@ -49,19 +49,20 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder,
Boolean convertAllFiled) {
super(readBasicParameter, parentAbstractReadHolder);
if (readBasicParameter.getUse1904windowing() == null && parentAbstractReadHolder != null) {
if (readBasicParameter.getUse1904windowing() == null) {
if (parentAbstractReadHolder != null) {
getGlobalConfiguration()
.setUse1904windowing(parentAbstractReadHolder.getGlobalConfiguration().getUse1904windowing());
}
} else {
getGlobalConfiguration().setUse1904windowing(readBasicParameter.getUse1904windowing());
}
if (readBasicParameter.getUseScientificFormat() == null) {
if (parentAbstractReadHolder == null) {
getGlobalConfiguration().setUseScientificFormat(Boolean.FALSE);
} else {
getGlobalConfiguration()
.setUseScientificFormat(parentAbstractReadHolder.getGlobalConfiguration().getUseScientificFormat());
if (parentAbstractReadHolder != null) {
getGlobalConfiguration().setUseScientificFormat(
parentAbstractReadHolder.getGlobalConfiguration().getUseScientificFormat());
}
} else {
getGlobalConfiguration().setUseScientificFormat(readBasicParameter.getUseScientificFormat());
@ -114,7 +115,6 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
}
}
@Override
public List<ReadListener<?>> readListenerList() {
return getReadListenerList();

7
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java

@ -96,10 +96,9 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder,
Boolean convertAllField) {
super(writeBasicParameter, parentAbstractWriteHolder);
if (writeBasicParameter.getUse1904windowing() == null) {
if (parentAbstractWriteHolder == null) {
getGlobalConfiguration().setUse1904windowing(Boolean.FALSE);
} else {
if (parentAbstractWriteHolder != null) {
getGlobalConfiguration()
.setUse1904windowing(parentAbstractWriteHolder.getGlobalConfiguration().getUse1904windowing());
}
@ -210,7 +209,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
}
}
protected void initAnnotationConfig(List<WriteHandler> handlerList, WriteBasicParameter writeBasicParameter) {
if (!HeadKindEnum.CLASS.equals(getExcelWriteHeadProperty().getHeadKind())) {
return;
@ -310,7 +308,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
handlerList.add(columnWidthStyleStrategy);
}
protected Map<Class<? extends WriteHandler>, List<WriteHandler>> sortAndClearUpAllHandler(
List<WriteHandler> handlerList, Map<Class<? extends WriteHandler>, List<WriteHandler>> parentHandlerMap) {
// add

2
src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java

@ -39,7 +39,7 @@ public class AnnotationIndexAndNameDataTest {
}
@Test
public void t03ReadAndWrite03() {
public void t03ReadAndWriteCsv() {
readAndWrite(fileCsv);
}

9
src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java

@ -25,11 +25,14 @@ public class CellDataDataTest {
private static File file07;
private static File file03;
private static File fileCsv;
@BeforeClass
public static void init() {
file07 = TestFileUtil.createNewFile("cellData07.xlsx");
file03 = TestFileUtil.createNewFile("cellData03.xls");
fileCsv = TestFileUtil.createNewFile("cellDataCsv.csv");
}
@Test
@ -42,6 +45,12 @@ public class CellDataDataTest {
readAndWrite(file03);
}
@Test
public void t03ReadAndWriteCsv() throws Exception {
readAndWrite(fileCsv);
}
private void readAndWrite(File file) throws Exception {
EasyExcel.write(file, CellDataWriteData.class).sheet().doWrite(data());
EasyExcel.read(file, CellDataReadData.class, new CellDataDataListener()).sheet().doRead();

Loading…
Cancel
Save