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; package com.alibaba.excel.metadata;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import com.alibaba.excel.converters.Converter; import com.alibaba.excel.converters.Converter;
@ -55,19 +54,16 @@ public abstract class AbstractHolder implements ConfigurationHolder {
} }
this.globalConfiguration = new GlobalConfiguration(); this.globalConfiguration = new GlobalConfiguration();
if (basicParameter.getAutoTrim() == null) { if (basicParameter.getAutoTrim() == null) {
if (prentAbstractHolder == null) { if (prentAbstractHolder != null) {
globalConfiguration.setAutoTrim(Boolean.TRUE);
} else {
globalConfiguration.setAutoTrim(prentAbstractHolder.getGlobalConfiguration().getAutoTrim()); globalConfiguration.setAutoTrim(prentAbstractHolder.getGlobalConfiguration().getAutoTrim());
} }
} else { } else {
globalConfiguration.setAutoTrim(basicParameter.getAutoTrim()); globalConfiguration.setAutoTrim(basicParameter.getAutoTrim());
} }
if (basicParameter.getLocale() == null) { if (basicParameter.getLocale() == null) {
if (prentAbstractHolder == null) { if (prentAbstractHolder != null) {
globalConfiguration.setLocale(Locale.getDefault());
} else {
globalConfiguration.setLocale(prentAbstractHolder.getGlobalConfiguration().getLocale()); globalConfiguration.setLocale(prentAbstractHolder.getGlobalConfiguration().getLocale());
} }
} else { } 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 java.util.Locale;
import lombok.Data;
/** /**
* Global configuration * Global configuration
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Data
public class GlobalConfiguration { public class GlobalConfiguration {
/** /**
* Automatic trim includes sheet name and content * Automatic trim includes sheet name and content
@ -32,35 +35,10 @@ public class GlobalConfiguration {
*/ */
private Boolean useScientificFormat; private Boolean useScientificFormat;
public Boolean getUse1904windowing() { public GlobalConfiguration() {
return use1904windowing; this.autoTrim = Boolean.TRUE;
} this.use1904windowing = Boolean.FALSE;
this.locale = Locale.getDefault();
public void setUse1904windowing(Boolean use1904windowing) { this.useScientificFormat = Boolean.FALSE;
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;
} }
} }

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, public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder,
Boolean convertAllFiled) { Boolean convertAllFiled) {
super(readBasicParameter, parentAbstractReadHolder); super(readBasicParameter, parentAbstractReadHolder);
if (readBasicParameter.getUse1904windowing() == null && parentAbstractReadHolder != null) {
if (readBasicParameter.getUse1904windowing() == null) {
if (parentAbstractReadHolder != null) {
getGlobalConfiguration() getGlobalConfiguration()
.setUse1904windowing(parentAbstractReadHolder.getGlobalConfiguration().getUse1904windowing()); .setUse1904windowing(parentAbstractReadHolder.getGlobalConfiguration().getUse1904windowing());
}
} else { } else {
getGlobalConfiguration().setUse1904windowing(readBasicParameter.getUse1904windowing()); getGlobalConfiguration().setUse1904windowing(readBasicParameter.getUse1904windowing());
} }
if (readBasicParameter.getUseScientificFormat() == null) { if (readBasicParameter.getUseScientificFormat() == null) {
if (parentAbstractReadHolder == null) { if (parentAbstractReadHolder != null) {
getGlobalConfiguration().setUseScientificFormat(Boolean.FALSE); getGlobalConfiguration().setUseScientificFormat(
} else { parentAbstractReadHolder.getGlobalConfiguration().getUseScientificFormat());
getGlobalConfiguration()
.setUseScientificFormat(parentAbstractReadHolder.getGlobalConfiguration().getUseScientificFormat());
} }
} else { } else {
getGlobalConfiguration().setUseScientificFormat(readBasicParameter.getUseScientificFormat()); getGlobalConfiguration().setUseScientificFormat(readBasicParameter.getUseScientificFormat());
@ -114,7 +115,6 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
} }
} }
@Override @Override
public List<ReadListener<?>> readListenerList() { public List<ReadListener<?>> readListenerList() {
return getReadListenerList(); 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, public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder,
Boolean convertAllField) { Boolean convertAllField) {
super(writeBasicParameter, parentAbstractWriteHolder); super(writeBasicParameter, parentAbstractWriteHolder);
if (writeBasicParameter.getUse1904windowing() == null) { if (writeBasicParameter.getUse1904windowing() == null) {
if (parentAbstractWriteHolder == null) { if (parentAbstractWriteHolder != null) {
getGlobalConfiguration().setUse1904windowing(Boolean.FALSE);
} else {
getGlobalConfiguration() getGlobalConfiguration()
.setUse1904windowing(parentAbstractWriteHolder.getGlobalConfiguration().getUse1904windowing()); .setUse1904windowing(parentAbstractWriteHolder.getGlobalConfiguration().getUse1904windowing());
} }
@ -210,7 +209,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
} }
} }
protected void initAnnotationConfig(List<WriteHandler> handlerList, WriteBasicParameter writeBasicParameter) { protected void initAnnotationConfig(List<WriteHandler> handlerList, WriteBasicParameter writeBasicParameter) {
if (!HeadKindEnum.CLASS.equals(getExcelWriteHeadProperty().getHeadKind())) { if (!HeadKindEnum.CLASS.equals(getExcelWriteHeadProperty().getHeadKind())) {
return; return;
@ -310,7 +308,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
handlerList.add(columnWidthStyleStrategy); handlerList.add(columnWidthStyleStrategy);
} }
protected Map<Class<? extends WriteHandler>, List<WriteHandler>> sortAndClearUpAllHandler( protected Map<Class<? extends WriteHandler>, List<WriteHandler>> sortAndClearUpAllHandler(
List<WriteHandler> handlerList, Map<Class<? extends WriteHandler>, List<WriteHandler>> parentHandlerMap) { List<WriteHandler> handlerList, Map<Class<? extends WriteHandler>, List<WriteHandler>> parentHandlerMap) {
// add // add

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

@ -39,7 +39,7 @@ public class AnnotationIndexAndNameDataTest {
} }
@Test @Test
public void t03ReadAndWrite03() { public void t03ReadAndWriteCsv() {
readAndWrite(fileCsv); 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 file07;
private static File file03; private static File file03;
private static File fileCsv;
@BeforeClass @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");
fileCsv = TestFileUtil.createNewFile("cellDataCsv.csv");
} }
@Test @Test
@ -42,6 +45,12 @@ public class CellDataDataTest {
readAndWrite(file03); readAndWrite(file03);
} }
@Test
public void t03ReadAndWriteCsv() throws Exception {
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();

Loading…
Cancel
Save