From f95f54514a34e6bd0ebd6c56b70601456f09f839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvan-=E6=AC=A7=E9=98=B3=E5=B8=86?= Date: Tue, 20 Jun 2023 13:58:21 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-94637=20=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BF=AE=E5=A4=8D=20=E3=80=90=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=E3=80=91com.fr.design=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=8D=95=E6=B5=8B=E4=BF=AE=E5=A4=8D=20=E3=80=90=E6=94=B9?= =?UTF-8?q?=E5=8A=A8=E6=80=9D=E8=B7=AF=E3=80=91=E8=AF=A6=E8=A7=81https://k?= =?UTF-8?q?ms.fineres.com/pages/viewpage.action=3FpageId=3D742496063=20?= =?UTF-8?q?=E3=80=90review=E5=BB=BA=E8=AE=AE=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/help/TutorialActionTest.java | 20 +++ .../base/clipboard/DesignerClipboardTest.java | 12 +- .../data/DesignTableDataManagerTest.java | 17 +-- .../datapane/TableDataPaneListPaneTest.java | 20 ++- .../TableDataFollowingPasteUtilsTest.java | 6 +- .../toolbar/ToolBarMenuDockTest.java | 128 ++++++++++++------ 6 files changed, 146 insertions(+), 57 deletions(-) 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 dc1e871b4b..5ae51d380f 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 @@ -1,14 +1,34 @@ package com.fr.design.actions.help; +import com.fr.base.svg.SystemScaleUtils; +import com.fr.design.i18n.Toolkit; import com.fr.general.GeneralContext; import com.fr.stable.ProductConstants; import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import java.util.Locale; import java.util.UUID; +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"javax.management.*","javax.net.ssl.*"}) +@PrepareForTest({Toolkit.class, SystemScaleUtils.class}) public class TutorialActionTest extends TestCase { + public void setUp() { + PowerMock.mockStatic(Toolkit.class); + EasyMock.expect(Toolkit.i18nText(EasyMock.anyString())).andReturn("test").anyTimes(); + PowerMock.mockStatic(SystemScaleUtils.class); + EasyMock.expect(SystemScaleUtils.sysScale()).andReturn(1F).anyTimes(); + EasyMock.expect(SystemScaleUtils.isJreHiDPIEnabled()).andReturn(false).anyTimes(); + PowerMock.replayAll(); + } + public void testCreateKey() { TutorialAction action = new TutorialAction(); GeneralContext.setLocale(Locale.US); diff --git a/designer-base/src/test/java/com/fr/design/base/clipboard/DesignerClipboardTest.java b/designer-base/src/test/java/com/fr/design/base/clipboard/DesignerClipboardTest.java index 36cdc54f04..bc4a11d6a9 100644 --- a/designer-base/src/test/java/com/fr/design/base/clipboard/DesignerClipboardTest.java +++ b/designer-base/src/test/java/com/fr/design/base/clipboard/DesignerClipboardTest.java @@ -1,5 +1,6 @@ package com.fr.design.base.clipboard; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.ClipboardHandlerProvider; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.dnd.ArrayListTransferable; @@ -41,11 +42,20 @@ public class DesignerClipboardTest { .andReturn(providers) .anyTimes(); EasyMock.replay(formClassManager); + + ExtraDesignClassManager designClassManager = EasyMock.mock(ExtraDesignClassManager.class); + EasyMock.expect(designClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) + .andReturn(providers) + .anyTimes(); + EasyMock.replay(designClassManager); PowerMock.mockStatic(PluginModule.class); EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) .andReturn(formClassManager) .anyTimes(); + EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraDesign)) + .andReturn(designClassManager) + .anyTimes(); PowerMock.replayAll(); } @@ -72,4 +82,4 @@ public class DesignerClipboardTest { Assert.assertEquals(transferData.get(0), transferData2.get(0)); } -} \ No newline at end of file +} diff --git a/designer-base/src/test/java/com/fr/design/data/DesignTableDataManagerTest.java b/designer-base/src/test/java/com/fr/design/data/DesignTableDataManagerTest.java index 1a23555f61..3b3f8cad8e 100644 --- a/designer-base/src/test/java/com/fr/design/data/DesignTableDataManagerTest.java +++ b/designer-base/src/test/java/com/fr/design/data/DesignTableDataManagerTest.java @@ -141,18 +141,15 @@ public class DesignTableDataManagerTest { } @Test - public void testAddDsColumnNames() { - DesignTableDataManager.addDsColumnNames("ds1", new String[]{"a", "b", "c"}); - Map> map = Reflect.on(DesignTableDataManager.class).field( - "columnCache").get(); - Assert.assertEquals(new String[]{"a", "b", "c"}, map.get(null).get("ds1")); - } - - @Test - public void testGetDsColumnNames() { - Assert.assertTrue(ArrayUtils.isEmpty(DesignTableDataManager.getDsColumnNames("ds1"))); + public void testOperateDsColumnNames() { String[] columnNames = new String[]{"a", "b", "c"}; + Assert.assertTrue(ArrayUtils.isEmpty(DesignTableDataManager.getDsColumnNames("ds1"))); + // 测试Add DesignTableDataManager.addDsColumnNames("ds1", new String[]{"a", "b", "c"}); + // 测试Get Assert.assertEquals(columnNames, DesignTableDataManager.getDsColumnNames("ds1")); + // 测试Remove + DesignTableDataManager.removeSelectedColumnNames("ds1"); + Assert.assertTrue(ArrayUtils.isEmpty(DesignTableDataManager.getDsColumnNames("ds1"))); } } diff --git a/designer-base/src/test/java/com/fr/design/data/datapane/TableDataPaneListPaneTest.java b/designer-base/src/test/java/com/fr/design/data/datapane/TableDataPaneListPaneTest.java index dd5e5bc5ce..48b11be333 100644 --- a/designer-base/src/test/java/com/fr/design/data/datapane/TableDataPaneListPaneTest.java +++ b/designer-base/src/test/java/com/fr/design/data/datapane/TableDataPaneListPaneTest.java @@ -1,6 +1,14 @@ package com.fr.design.data.datapane; +import com.fr.design.i18n.Toolkit; +import org.easymock.EasyMock; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import java.util.Map; @@ -11,8 +19,18 @@ import static org.junit.Assert.*; * @version 10.0 * Created by Yyming on 2020/9/29 */ +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"javax.management.*", "javax.swing.*"}) +@PrepareForTest(Toolkit.class) public class TableDataPaneListPaneTest { + @Before + public void setUp() { + PowerMock.mockStatic(Toolkit.class); + EasyMock.expect(Toolkit.i18nText(EasyMock.anyString())).andReturn("test").anyTimes(); + PowerMock.replayAll(); + } + @Test public void rename() { TableDataPaneListPane listPane = new TableDataPaneListPane(); @@ -23,4 +41,4 @@ public class TableDataPaneListPaneTest { listPane.rename("333","111"); assertEquals(0, dsNameChangedMap.size()); } -} \ No newline at end of file +} diff --git a/designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java b/designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java index 2435f363fc..b82857c98e 100644 --- a/designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java +++ b/designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java @@ -62,6 +62,7 @@ public class TableDataFollowingPasteUtilsTest extends TestCase { PowerMock.mockStatic(DesignTableDataManager.class); EasyMock.expect(DesignTableDataManager.getEditingTableDataSource()).andReturn(tableDataSource).anyTimes(); EasyMock.expect(DesignTableDataManager.getEditingDataSet(tableDataSource)).andReturn(list).anyTimes(); + EasyMock.expect(DesignTableDataManager.getAllDataSetIncludingProcedure(templateDataMap)).andReturn(templateDataMap).anyTimes(); PowerMock.replayAll(); } @@ -107,6 +108,7 @@ public class TableDataFollowingPasteUtilsTest extends TestCase { set.add("ds3"); MockWidget widget1 = EasyMock.mock(MockWidget.class); EasyMock.expect(widget1.getUsedTableDataSets()).andReturn(set).anyTimes(); + EasyMock.expect(widget1.getChartCollections()).andReturn(new ArrayList<>()).anyTimes(); EasyMock.replay(widget1); DataBinding dataBinding = new DataBinding("ds4", ""); @@ -114,6 +116,7 @@ public class TableDataFollowingPasteUtilsTest extends TestCase { widgetValue2.setValue(dataBinding); AbstractDataControl widget2 = EasyMock.mock(AbstractDataControl.class); EasyMock.expect(widget2.getWidgetValue()).andReturn(widgetValue2).anyTimes(); + EasyMock.expect(widget2.getChartCollections()).andReturn(new ArrayList<>()).anyTimes(); EasyMock.replay(widget2); DataTableConfig dataTableConfig = EasyMock.mock(DataTableConfig.class); @@ -122,6 +125,7 @@ public class TableDataFollowingPasteUtilsTest extends TestCase { widgetValue3.setValue(dataTableConfig); AbstractDataControl widget3 = EasyMock.mock(AbstractDataControl.class); EasyMock.expect(widget3.getWidgetValue()).andReturn(widgetValue3).anyTimes(); + EasyMock.expect(widget3.getChartCollections()).andReturn(new ArrayList<>()).anyTimes(); EasyMock.replay(dataTableConfig, widget3); Widget[] widgets = new Widget[3]; @@ -198,4 +202,4 @@ public class TableDataFollowingPasteUtilsTest extends TestCase { return new String[0]; } } -} \ No newline at end of file +} diff --git a/designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java b/designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java index c5f9f0a700..a198dace8f 100644 --- a/designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java +++ b/designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java @@ -1,30 +1,35 @@ package com.fr.design.mainfarme.toolbar; +import java.util.HashMap; import java.util.Locale; +import com.fr.base.svg.SystemScaleUtils; import com.fr.design.DesignerEnvManager; +import com.fr.design.actions.community.TechSupportAction; import com.fr.design.actions.community.VideoAction; import com.fr.design.actions.help.AboutAction; -import com.fr.design.actions.help.FineUIAction; import com.fr.design.actions.help.TutorialAction; import com.fr.design.actions.help.WebDemoAction; import com.fr.design.actions.help.alphafine.AlphaFineAction; import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.platform.ServicePlatformAction; import com.fr.design.mainframe.toolbar.ToolBarMenuDock; import com.fr.design.menu.SeparatorDef; import com.fr.design.menu.ShortCut; import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.update.actions.SoftwareUpdateAction; +import com.fr.env.detect.ui.EnvDetectorAction; import com.fr.general.GeneralContext; import com.fr.workspace.WorkContext; import com.fr.workspace.Workspace; import org.easymock.EasyMock; -import org.easymock.Mock; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; @@ -42,66 +47,99 @@ import org.powermock.reflect.Whitebox; Locale.class, WorkContext.class, DesignerEnvManager.class, + Toolkit.class, + SystemScaleUtils.class, AlphaFineConfigManager.class}) +@PowerMockIgnore({"javax.management.*"}) public class ToolBarMenuDockTest { - @Mock - VideoAction videoAction; - @Mock - TutorialAction tutorialAction; - @Mock - WebDemoAction webDemoAction; - @Mock - SoftwareUpdateAction softwareUpdateAction; - @Mock - AlphaFineAction alphaFineAction; - @Mock - FineUIAction fineUIAction; - @Mock - AboutAction aboutAction; - @Before public void testCreateHelpShortCutsBefore() { - try { - PowerMock.expectNew(VideoAction.class).andReturn(videoAction).anyTimes(); - PowerMock.expectNew(TutorialAction.class).andReturn(tutorialAction).anyTimes(); - PowerMock.expectNew(WebDemoAction.class).andReturn(webDemoAction).anyTimes(); - PowerMock.expectNew(SoftwareUpdateAction.class).andReturn(softwareUpdateAction).anyTimes(); - PowerMock.expectNew(AlphaFineAction.class).andReturn(alphaFineAction).anyTimes(); - PowerMock.expectNew(FineUIAction.class).andReturn(fineUIAction).anyTimes(); - PowerMock.expectNew(AboutAction.class).andReturn(aboutAction).anyTimes(); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } + PowerMock.mockStatic(Toolkit.class); + EasyMock.expect(Toolkit.i18nText(EasyMock.anyString())).andReturn("test").anyTimes(); + PowerMock.mockStatic(SystemScaleUtils.class); + EasyMock.expect(SystemScaleUtils.sysScale()).andReturn(1F).anyTimes(); + EasyMock.expect(SystemScaleUtils.isJreHiDPIEnabled()).andReturn(false).anyTimes(); + PowerMock.replay(); } @Test - public void testCreateHelpShortCuts() { + public void testCreateHelpShortCutsWithLocaleChina() { // 处理判断条件 GeneralContext context = EasyMock.createMock(GeneralContext.class); PowerMock.mockStatic(GeneralContext.class); - EasyMock.expect(GeneralContext.getLocale()).andReturn(Locale.CHINA).once(); - EasyMock.expect(GeneralContext.getLocale()).andReturn(Locale.US).once(); + EasyMock.expect(GeneralContext.getLocale()).andReturn(Locale.CHINA).anyTimes(); + Workspace workspace = EasyMock.createMock(Workspace.class); PowerMock.mockStatic(WorkContext.class); EasyMock.expect(WorkContext.getCurrent()).andReturn(workspace).anyTimes(); - - EasyMock.expect(workspace.isLocal()).andReturn(false).once(); - EasyMock.expect(workspace.isLocal()).andReturn(true).once(); + EasyMock.expect(workspace.isLocal()).andReturn(true).anyTimes(); DesignerEnvManager envManager = EasyMock.createMock(DesignerEnvManager.class); PowerMock.mockStatic(DesignerEnvManager.class); EasyMock.expect(DesignerEnvManager.getEnvManager()).andReturn(envManager).anyTimes(); + EasyMock.expect(envManager.isOpenDebug()).andReturn(true).anyTimes(); + + AlphaFineConfigManager configManager = EasyMock.createMock(AlphaFineConfigManager.class); + PowerMock.mockStatic(AlphaFineConfigManager.class); + EasyMock.expect(AlphaFineConfigManager.getInstance()).andReturn(configManager).anyTimes(); + EasyMock.expect(configManager.isALPHALicAvailable()).andReturn(true).anyTimes(); + EasyMock.expect(configManager.getActionSearchTextCache()).andReturn(new HashMap<>()).anyTimes(); + EasyMock.expect(configManager.getCacheBuildNO()).andReturn("").anyTimes(); + + SupportOSImpl osImpl = EasyMock.createMock(SupportOSImpl.class); + Whitebox.setInternalState(SupportOSImpl.class, "FINEUI", osImpl); + EasyMock.expect(osImpl.support()).andReturn(false).anyTimes(); + + EasyMock.replay(context, workspace, envManager, configManager, osImpl); + PowerMock.replayAll(); + + ToolBarMenuDock menuDock = new ToolBarMenuDock() { + @Override + public ShortCut[] createNewFileShortCuts() { + return new ShortCut[0]; + } + }; + + ShortCut[] shortCuts = new ShortCut[] { + new WebDemoAction(), + new SoftwareUpdateAction(), + new AlphaFineAction(), + new EnvDetectorAction(), + new ServicePlatformAction(), + SeparatorDef.DEFAULT, + new AboutAction()}; + Assert.assertEquals(menuDock.createHelpShortCuts(), shortCuts); + + } + + @Test + public void testCreateHelpShortCutsWithLocaleUS() { + + // 处理判断条件 + GeneralContext context = EasyMock.createMock(GeneralContext.class); + PowerMock.mockStatic(GeneralContext.class); + EasyMock.expect(GeneralContext.getLocale()).andReturn(Locale.US).anyTimes(); - EasyMock.expect(envManager.isOpenDebug()).andReturn(false).once(); - EasyMock.expect(envManager.isOpenDebug()).andReturn(true).once(); + + Workspace workspace = EasyMock.createMock(Workspace.class); + PowerMock.mockStatic(WorkContext.class); + EasyMock.expect(WorkContext.getCurrent()).andReturn(workspace).anyTimes(); + EasyMock.expect(workspace.isLocal()).andReturn(false).anyTimes(); + + DesignerEnvManager envManager = EasyMock.createMock(DesignerEnvManager.class); + PowerMock.mockStatic(DesignerEnvManager.class); + EasyMock.expect(DesignerEnvManager.getEnvManager()).andReturn(envManager).anyTimes(); + EasyMock.expect(envManager.isOpenDebug()).andReturn(false).anyTimes(); AlphaFineConfigManager configManager = EasyMock.createMock(AlphaFineConfigManager.class); PowerMock.mockStatic(AlphaFineConfigManager.class); - EasyMock.expect(AlphaFineConfigManager.isALPHALicAvailable()).andReturn(false).once(); - EasyMock.expect(AlphaFineConfigManager.isALPHALicAvailable()).andReturn(true).once(); + EasyMock.expect(configManager.isALPHALicAvailable()).andReturn(false).anyTimes(); + EasyMock.expect(configManager.getActionSearchTextCache()).andReturn(new HashMap<>()).anyTimes(); + EasyMock.expect(configManager.getCacheBuildNO()).andReturn("").anyTimes(); + EasyMock.expect(AlphaFineConfigManager.getInstance()).andReturn(configManager).anyTimes(); SupportOSImpl osImpl = EasyMock.createMock(SupportOSImpl.class); Whitebox.setInternalState(SupportOSImpl.class, "FINEUI", osImpl); @@ -118,12 +156,14 @@ public class ToolBarMenuDockTest { } }; - ShortCut[] shortCuts1 = new ShortCut[] {SeparatorDef.DEFAULT, aboutAction}; - ShortCut[] shortCuts2 = new ShortCut[] {videoAction, tutorialAction, webDemoAction, - softwareUpdateAction, alphaFineAction, SeparatorDef.DEFAULT, aboutAction}; - - Assert.assertEquals(menuDock.createHelpShortCuts(), shortCuts1); - Assert.assertEquals(menuDock.createHelpShortCuts(), shortCuts2); + ShortCut[] shortCuts = new ShortCut[] { + new VideoAction(), + new TutorialAction(), + new TechSupportAction(), + new EnvDetectorAction(), + SeparatorDef.DEFAULT, + new AboutAction()}; + Assert.assertEquals(menuDock.createHelpShortCuts(), shortCuts); } }