diff --git a/designer-base/src/test/java/com/fr/design/actions/help/TutorialActionTest.java b/designer-base/src/test/java/com/fr/design/actions/help/TutorialActionTest.java index 7e4dad651a..dc1e871b4b 100644 --- a/designer-base/src/test/java/com/fr/design/actions/help/TutorialActionTest.java +++ b/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.UUID; -public class TutorialActionTest extends TestCase{ +public class TutorialActionTest extends TestCase { public void testCreateKey() { TutorialAction action = new TutorialAction(); @@ -24,6 +24,7 @@ public class TutorialActionTest extends TestCase{ GeneralContext.setLocale(pt); String ptKey = action.createDocKey(); assertTrue(ptKey.contains(pt.toString())); + GeneralContext.setLocale(Locale.CHINA); } public void testServerOnline() { diff --git a/designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java b/designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java index 75c9c9e5ba..b53d47780c 100644 --- a/designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java +++ b/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.invoke.Reflect; +import com.fr.log.FineLoggerFactory; import org.easymock.EasyMock; import org.junit.Test; 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.modules.junit4.PowerMockRunner; -import static junit.framework.Assert.fail; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; /** * Created by plough on 2018/12/7. @@ -20,6 +21,7 @@ import static org.junit.Assert.assertFalse; @RunWith(PowerMockRunner.class) @PrepareForTest(GeneralUtils.class) public class FunctionConstantsTest { + @Test public void testNewInstanceFail() throws Exception { try { @@ -31,7 +33,7 @@ public class FunctionConstantsTest { } @Test - public void testEmbedFuntionsAfterStaticInit() { + public void testEmbedFunctionsAfterStaticInit() { NameAndTypeAndFunctionList[] embFunctionLists = FunctionConstants.EMBFUNCTIONS; // 一共有 8 个分类 assertEquals(8, embFunctionLists.length); @@ -43,13 +45,17 @@ public class FunctionConstantsTest { } @Test - public void testCommonFuntionsAfterStaticInit() { + public void testCommonFunctionsAfterStaticInit() { NameAndFunctionList commonFunctionList = FunctionConstants.COMMON; assertEquals(9, commonFunctionList.getDescriptions().length); } @Test public void testIsCustomFormulaPathRunWithCode() { + // mock 的 GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes() + // 会影响 FunctionConstants.class 静态代码块 loadEmbededFunctions 执行,先加载这个类,执行静态代码块 + FineLoggerFactory.getLogger().info(String.valueOf(FunctionConstants.EMBFUNCTIONS.length)); + PowerMock.mockStatic(GeneralUtils.class); EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes(); PowerMock.replayAll(); @@ -63,6 +69,10 @@ public class FunctionConstantsTest { @Test public void testIsCustomFormulaPathRunWithJar() { + // mock 的 GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes() + // 会影响 FunctionConstants.class 静态代码块 loadEmbededFunctions 执行,先加载这个类,执行静态代码块 + FineLoggerFactory.getLogger().info(String.valueOf(FunctionConstants.EMBFUNCTIONS.length)); + PowerMock.mockStatic(GeneralUtils.class); EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("Build#release-2018.12.10.12.11.09.95").anyTimes(); PowerMock.replayAll(); diff --git a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java index e83a523fc4..d93a7476a9 100644 --- a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java +++ b/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"); Reflect.on(TemplateInfoCollector.class).set("instance", null); + // 后执行 testReadXML 用例时,之前保留的单例会造成影响 + Reflect.on(DesignerOpenHistory.class).set("singleton", null); } @After @@ -89,7 +91,7 @@ public class TemplateInfoCollectorTest { assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":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\"," + "\"jar_time\":\"不是安装版本\",\"create_time\":\"2019-03-26 16:13\"," + @@ -118,7 +120,7 @@ public class TemplateInfoCollectorTest { assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":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 consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); assertEquals(templateID, consumingMap.get("templateID"));