Browse Source

Pull request #12248: REPORT-94637 单元测试修复

Merge in DESIGN/design from ~YVAN/design:release/11.0 to release/11.0

* commit 'f95f54514a34e6bd0ebd6c56b70601456f09f839':
  REPORT-94637 单元测试修复 【问题原因】com.fr.design部分单测修复 【改动思路】详见https://kms.fineres.com/pages/viewpage.action?pageId=742496063 【review建议】
release/11.0
Yvan-欧阳帆 1 year ago
parent
commit
693cce0ebe
  1. 20
      designer-base/src/test/java/com/fr/design/actions/help/TutorialActionTest.java
  2. 12
      designer-base/src/test/java/com/fr/design/base/clipboard/DesignerClipboardTest.java
  3. 17
      designer-base/src/test/java/com/fr/design/data/DesignTableDataManagerTest.java
  4. 20
      designer-base/src/test/java/com/fr/design/data/datapane/TableDataPaneListPaneTest.java
  5. 6
      designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java
  6. 128
      designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java

20
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);

12
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));
}
}
}

17
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<TableDataSource, Map<String, String[]>> 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")));
}
}

20
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());
}
}
}

6
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];
}
}
}
}

128
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);
}
}

Loading…
Cancel
Save