Browse Source

单元测试

pull/11/head
richie 5 years ago
parent
commit
23383b91aa
  1. 35
      src/main/java/com/fanruan/api/data/TableDataKit.java
  2. 19
      src/test/java/com/fanruan/api/data/TableDataKitTest.java

35
src/main/java/com/fanruan/api/data/TableDataKit.java

@ -3,11 +3,15 @@ package com.fanruan.api.data;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.data.TableDataSource; import com.fr.data.TableDataSource;
import com.fr.data.api.TableDataAssist; import com.fr.data.api.TableDataAssist;
import com.fr.file.TableDataConfig;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.script.CalculatorProvider; import com.fr.stable.script.CalculatorProvider;
import com.fr.third.guava.collect.Maps;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Map;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
@ -26,7 +30,7 @@ public class TableDataKit {
* @param name 数据集名字 * @param name 数据集名字
* @return 数据集 * @return 数据集
*/ */
public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, String name) { public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, @NotNull String name) {
return TableDataAssist.getTableData((Calculator) cal, name); return TableDataAssist.getTableData((Calculator) cal, name);
} }
@ -40,7 +44,34 @@ public class TableDataKit {
* @param name 数据集名字 * @param name 数据集名字
* @return 数据集 * @return 数据集
*/ */
public static @Nullable TableData getTableData(@NotNull TableDataSource source, String name) { public static @Nullable TableData getTableData(@NotNull TableDataSource source, @NotNull String name) {
return TableDataAssist.getTableData(source, name); return TableDataAssist.getTableData(source, name);
} }
/**
* 获取所有的服务器数据集
* @return 所有的服务器数据集组成的键值对集合
*/
public static @NotNull Map<String, TableData> getAllServerTableData() {
Map<String, TableData> maps = TableDataConfig.getInstance().getTableDatas();
return Maps.newHashMap(maps);
}
/**
* 根据名字获取服务器数据集
* @param name 待查找的服务器数据集的名字
* @return 服务器数据集如果没有这个名字的服务器数据集则返回null
*/
public static @Nullable TableData findTableData(@NotNull String name) {
return TableDataConfig.getInstance().getTableData(name);
}
/**
* 重命名数据集
* @param oldName 原来的名字
* @param newName 新名字
*/
public static void renameTableData(@NotNull String oldName, @NotNull String newName) {
TableDataConfig.getInstance().renameTableData(oldName, newName);
}
} }

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

@ -2,13 +2,10 @@ package com.fanruan.api.data;
import com.fanruan.api.Prepare; import com.fanruan.api.Prepare;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.config.Configuration;
import com.fr.data.TableDataSource; import com.fr.data.TableDataSource;
import com.fr.file.TableDataConfig; import com.fr.file.TableDataConfig;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.transaction.Configurations;
import com.fr.transaction.Worker;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -22,17 +19,7 @@ public class TableDataKitTest extends Prepare {
@Test @Test
public void getTableData() { public void getTableData() {
TestTD td = new TestTD(); TestTD td = new TestTD();
Configurations.update(new Worker() { TableDataConfig.getInstance().addTableData("first", td);
@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 calculator = Calculator.createCalculator();
calculator.setAttribute(TableDataSource.KEY, new WorkBook()); calculator.setAttribute(TableDataSource.KEY, new WorkBook());
TableData r = TableDataKit.getTableData(calculator, "first"); TableData r = TableDataKit.getTableData(calculator, "first");
@ -42,11 +29,9 @@ public class TableDataKitTest extends Prepare {
@Test @Test
public void testGetTableData() { public void testGetTableData() {
TestTD td = new TestTD(); TestTD td = new TestTD();
Calculator calculator = Calculator.createCalculator();
WorkBook workBook = new WorkBook(); WorkBook workBook = new WorkBook();
workBook.putTableData("test", td); workBook.putTableData("test", td);
calculator.setAttribute(TableDataSource.KEY, workBook); TableData r = TableDataKit.getTableData(workBook, "test");
TableData r = TableDataKit.getTableData(calculator, "test");
Assert.assertEquals(td, r); Assert.assertEquals(td, r);
} }

Loading…
Cancel
Save