Browse Source

单元测试

pull/1/head
richie 5 years ago
parent
commit
6d5cd48d44
  1. 4
      src/test/java/com/fanruan/api/Prepare.java
  2. 68
      src/test/java/com/fanruan/api/data/TableDataKitTest.java
  3. 59
      src/test/java/com/fanruan/api/data/TestTD.java

4
src/test/java/com/fanruan/api/Prepare.java

@ -8,6 +8,8 @@ import com.fr.runtime.FineRuntime;
import com.fr.store.StateHubManager;
import com.fr.store.impl.MemoryLock;
import com.fr.store.impl.MemoryStore;
import com.fr.transaction.Configurations;
import com.fr.transaction.LocalConfigurationHelper;
import org.junit.After;
import org.junit.Before;
@ -24,6 +26,7 @@ public class Prepare {
DaoContext.setEntityDao(new LocalEntityDao());
DaoContext.setClassHelperDao(new LocalClassHelperDao());
DaoContext.setXmlEntityDao(new LocalXmlEntityDao());
Configurations.setHelper(new LocalConfigurationHelper());
StateHubManager.setStorage(new MemoryStore());
StateHubManager.setLock(new MemoryLock());
}
@ -33,6 +36,7 @@ public class Prepare {
DaoContext.setEntityDao(null);
DaoContext.setClassHelperDao(null);
DaoContext.setXmlEntityDao(null);
Configurations.setHelper(null);
StateHubManager.setStorage(null);
StateHubManager.setLock(null);
}

68
src/test/java/com/fanruan/api/data/TableDataKitTest.java

@ -1,24 +1,17 @@
package com.fanruan.api.data;
import com.fanruan.api.Prepare;
import com.fr.base.AbstractTableData;
import com.fr.base.TableData;
import com.fr.config.Configuration;
import com.fr.data.TableDataSource;
import com.fr.file.TableDataConfig;
import com.fr.general.data.DataModel;
import com.fr.main.impl.WorkBook;
import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.transaction.Configurations;
import com.fr.transaction.Worker;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
/**
* @author richie
* @version 10.0
@ -28,54 +21,33 @@ public class TableDataKitTest extends Prepare {
@Test
public void getTableData() {
Map<String, TableData> map = new HashMap<>();
map.put("test", TD);
TableDataConfig.getInstance().setTableDatas(map);
TestTD td = new TestTD();
Configurations.update(new Worker() {
@Override
public void run() {
TableDataConfig.getInstance().addTableData("first", td);
}
@Override
public Class<? extends Configuration>[] targets() {
return new Class[]{TableDataConfig.class};
}
});
Calculator calculator = Calculator.createCalculator();
calculator.setAttribute(TableDataSource.KEY, new WorkBook());
TableData r = TableDataKit.getTableData(calculator, "test");
Assert.assertEquals(TD, r);
TableData r = TableDataKit.getTableData(calculator, "first");
Assert.assertEquals(td, r);
}
@Test
public void testGetTableData() {
TestTD td = new TestTD();
Calculator calculator = Calculator.createCalculator();
WorkBook workBook = new WorkBook();
workBook.putTableData("test", TD);
workBook.putTableData("test", td);
calculator.setAttribute(TableDataSource.KEY, workBook);
TableData r = TableDataKit.getTableData(calculator, "test");
Assert.assertEquals(TD, r);
}
private static final TableData TD = new AbstractTableData() {
@Override
public ParameterProvider[] getParameters(Calculator calculator) {
return new ParameterProvider[0];
}
@Override
public DataModel createDataModel(Calculator calculator) {
return null;
Assert.assertEquals(td, r);
}
@Override
public DataModel createDataModel(Calculator calculator, String s) {
return null;
}
@Override
public DataModel createDataModel(Calculator calculator, int i) {
return null;
}
@Override
public void readXML(XMLableReader xmLableReader) {
}
@Override
public void writeXML(XMLPrintWriter xmlPrintWriter) {
}
};
}

59
src/test/java/com/fanruan/api/data/TestTD.java

@ -0,0 +1,59 @@
package com.fanruan.api.data;
import com.fanruan.api.conf.HolderKit;
import com.fr.base.AbstractTableData;
import com.fr.config.holder.Conf;
import com.fr.general.data.DataModel;
import com.fr.script.Calculator;
import com.fr.stable.ParameterProvider;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-19
*/
public class TestTD extends AbstractTableData {
private Conf<Integer> count = HolderKit.simple(10);
public TestTD() {
}
@Override
public ParameterProvider[] getParameters(Calculator calculator) {
return new ParameterProvider[0];
}
@Override
public DataModel createDataModel(Calculator calculator) {
return DataModel.EMPTY_DATAMODEL;
}
@Override
public DataModel createDataModel(Calculator calculator, String s) {
return DataModel.EMPTY_DATAMODEL;
}
@Override
public DataModel createDataModel(Calculator calculator, int i) {
return DataModel.EMPTY_DATAMODEL;
}
@Override
public void readXML(XMLableReader xmLableReader) {
}
@Override
public void writeXML(XMLPrintWriter xmlPrintWriter) {
}
@Override
public boolean equals(Object obj) {
return obj instanceof TestTD;
}
}
Loading…
Cancel
Save