Browse Source

Merge pull request #963 in DESIGN/design from ~YAOH.WU/design:feature/10.0 to feature/10.0

* commit '215703525ac1bad0c62f02ff690ba8872f2b58c9':
  无任务,单元测试
  无任务,单元测试
research/10.0
yaoh.wu 5 years ago
parent
commit
0806e3ada9
  1. 3
      designer-base/src/test/java/com/fr/design/actions/help/TutorialActionTest.java
  2. 16
      designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java
  3. 6
      designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java

3
designer-base/src/test/java/com/fr/design/actions/help/TutorialActionTest.java

@ -7,7 +7,7 @@ import junit.framework.TestCase;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.UUID;
public class TutorialActionTest extends TestCase{ public class TutorialActionTest extends TestCase {
public void testCreateKey() { public void testCreateKey() {
TutorialAction action = new TutorialAction(); TutorialAction action = new TutorialAction();
@ -24,6 +24,7 @@ public class TutorialActionTest extends TestCase{
GeneralContext.setLocale(pt); GeneralContext.setLocale(pt);
String ptKey = action.createDocKey(); String ptKey = action.createDocKey();
assertTrue(ptKey.contains(pt.toString())); assertTrue(ptKey.contains(pt.toString()));
GeneralContext.setLocale(Locale.CHINA);
} }
public void testServerOnline() { public void testServerOnline() {

16
designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java

@ -2,6 +2,7 @@ package com.fr.design.formula;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import com.fr.invoke.Reflect; import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -9,10 +10,10 @@ import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import static junit.framework.Assert.fail;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
/** /**
* Created by plough on 2018/12/7. * Created by plough on 2018/12/7.
@ -20,6 +21,7 @@ import static org.junit.Assert.assertFalse;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest(GeneralUtils.class) @PrepareForTest(GeneralUtils.class)
public class FunctionConstantsTest { public class FunctionConstantsTest {
@Test @Test
public void testNewInstanceFail() throws Exception { public void testNewInstanceFail() throws Exception {
try { try {
@ -31,7 +33,7 @@ public class FunctionConstantsTest {
} }
@Test @Test
public void testEmbedFuntionsAfterStaticInit() { public void testEmbedFunctionsAfterStaticInit() {
NameAndTypeAndFunctionList[] embFunctionLists = FunctionConstants.EMBFUNCTIONS; NameAndTypeAndFunctionList[] embFunctionLists = FunctionConstants.EMBFUNCTIONS;
// 一共有 8 个分类 // 一共有 8 个分类
assertEquals(8, embFunctionLists.length); assertEquals(8, embFunctionLists.length);
@ -43,13 +45,17 @@ public class FunctionConstantsTest {
} }
@Test @Test
public void testCommonFuntionsAfterStaticInit() { public void testCommonFunctionsAfterStaticInit() {
NameAndFunctionList commonFunctionList = FunctionConstants.COMMON; NameAndFunctionList commonFunctionList = FunctionConstants.COMMON;
assertEquals(9, commonFunctionList.getDescriptions().length); assertEquals(9, commonFunctionList.getDescriptions().length);
} }
@Test @Test
public void testIsCustomFormulaPathRunWithCode() { public void testIsCustomFormulaPathRunWithCode() {
// mock 的 GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes()
// 会影响 FunctionConstants.class 静态代码块 loadEmbededFunctions 执行,先加载这个类,执行静态代码块
FineLoggerFactory.getLogger().info(String.valueOf(FunctionConstants.EMBFUNCTIONS.length));
PowerMock.mockStatic(GeneralUtils.class); PowerMock.mockStatic(GeneralUtils.class);
EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes(); EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes();
PowerMock.replayAll(); PowerMock.replayAll();
@ -63,6 +69,10 @@ public class FunctionConstantsTest {
@Test @Test
public void testIsCustomFormulaPathRunWithJar() { public void testIsCustomFormulaPathRunWithJar() {
// mock 的 GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes()
// 会影响 FunctionConstants.class 静态代码块 loadEmbededFunctions 执行,先加载这个类,执行静态代码块
FineLoggerFactory.getLogger().info(String.valueOf(FunctionConstants.EMBFUNCTIONS.length));
PowerMock.mockStatic(GeneralUtils.class); PowerMock.mockStatic(GeneralUtils.class);
EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("Build#release-2018.12.10.12.11.09.95").anyTimes(); EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("Build#release-2018.12.10.12.11.09.95").anyTimes();
PowerMock.replayAll(); PowerMock.replayAll();

6
designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java

@ -56,6 +56,8 @@ public class TemplateInfoCollectorTest {
initialFileContent = FileUtils.readFileToString(new File(filePath), "utf-8"); initialFileContent = FileUtils.readFileToString(new File(filePath), "utf-8");
Reflect.on(TemplateInfoCollector.class).set("instance", null); Reflect.on(TemplateInfoCollector.class).set("instance", null);
// 后执行 testReadXML 用例时,之前保留的单例会造成影响
Reflect.on(DesignerOpenHistory.class).set("singleton", null);
} }
@After @After
@ -89,7 +91,7 @@ public class TemplateInfoCollectorTest {
assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," +
"\"cell_count\":13,\"block_count\":3,\"report_type\":0," + "\"cell_count\":13,\"block_count\":3,\"report_type\":0," +
"\"templateID\":\"16a988ce-8529-42f5-b17c-2ee849355071\"}",templateInfo.getProcessMapJsonString()); "\"templateID\":\"16a988ce-8529-42f5-b17c-2ee849355071\"}", templateInfo.getProcessMapJsonString());
assertJsonStringEquals("{\"activitykey\":\"2e0ea413-fa9c241e0-9723-4354fce51e81\"," + assertJsonStringEquals("{\"activitykey\":\"2e0ea413-fa9c241e0-9723-4354fce51e81\"," +
"\"jar_time\":\"不是安装版本\",\"create_time\":\"2019-03-26 16:13\"," + "\"jar_time\":\"不是安装版本\",\"create_time\":\"2019-03-26 16:13\"," +
@ -118,7 +120,7 @@ public class TemplateInfoCollectorTest {
assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," +
"\"cell_count\":13,\"block_count\":3,\"report_type\":0," + "\"cell_count\":13,\"block_count\":3,\"report_type\":0," +
"\"templateID\":\"73a97777-8jnk-47cd-b57c-2ee89991279796\"}",templateInfo.getProcessMapJsonString()); "\"templateID\":\"73a97777-8jnk-47cd-b57c-2ee89991279796\"}", templateInfo.getProcessMapJsonString());
Map<String, Object> consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); Map<String, Object> consumingMap = Reflect.on(templateInfo).field("consumingMap").get();
assertEquals(templateID, consumingMap.get("templateID")); assertEquals(templateID, consumingMap.get("templateID"));

Loading…
Cancel
Save