@ -1,30 +1,35 @@
package com.fr.design.mainfarme.toolbar ;
package com.fr.design.mainfarme.toolbar ;
import java.util.HashMap ;
import java.util.Locale ;
import java.util.Locale ;
import com.fr.base.svg.SystemScaleUtils ;
import com.fr.design.DesignerEnvManager ;
import com.fr.design.DesignerEnvManager ;
import com.fr.design.actions.community.TechSupportAction ;
import com.fr.design.actions.community.VideoAction ;
import com.fr.design.actions.community.VideoAction ;
import com.fr.design.actions.help.AboutAction ;
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.TutorialAction ;
import com.fr.design.actions.help.WebDemoAction ;
import com.fr.design.actions.help.WebDemoAction ;
import com.fr.design.actions.help.alphafine.AlphaFineAction ;
import com.fr.design.actions.help.alphafine.AlphaFineAction ;
import com.fr.design.actions.help.alphafine.AlphaFineConfigManager ;
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.mainframe.toolbar.ToolBarMenuDock ;
import com.fr.design.menu.SeparatorDef ;
import com.fr.design.menu.SeparatorDef ;
import com.fr.design.menu.ShortCut ;
import com.fr.design.menu.ShortCut ;
import com.fr.design.os.impl.SupportOSImpl ;
import com.fr.design.os.impl.SupportOSImpl ;
import com.fr.design.update.actions.SoftwareUpdateAction ;
import com.fr.design.update.actions.SoftwareUpdateAction ;
import com.fr.env.detect.ui.EnvDetectorAction ;
import com.fr.general.GeneralContext ;
import com.fr.general.GeneralContext ;
import com.fr.workspace.WorkContext ;
import com.fr.workspace.WorkContext ;
import com.fr.workspace.Workspace ;
import com.fr.workspace.Workspace ;
import org.easymock.EasyMock ;
import org.easymock.EasyMock ;
import org.easymock.Mock ;
import org.junit.Assert ;
import org.junit.Assert ;
import org.junit.Before ;
import org.junit.Before ;
import org.junit.Test ;
import org.junit.Test ;
import org.junit.runner.RunWith ;
import org.junit.runner.RunWith ;
import org.powermock.api.easymock.PowerMock ;
import org.powermock.api.easymock.PowerMock ;
import org.powermock.core.classloader.annotations.PowerMockIgnore ;
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 org.powermock.reflect.Whitebox ;
import org.powermock.reflect.Whitebox ;
@ -42,66 +47,99 @@ import org.powermock.reflect.Whitebox;
Locale . class ,
Locale . class ,
WorkContext . class ,
WorkContext . class ,
DesignerEnvManager . class ,
DesignerEnvManager . class ,
Toolkit . class ,
SystemScaleUtils . class ,
AlphaFineConfigManager . class } )
AlphaFineConfigManager . class } )
@PowerMockIgnore ( { "javax.management.*" } )
public class ToolBarMenuDockTest {
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
@Before
public void testCreateHelpShortCutsBefore ( ) {
public void testCreateHelpShortCutsBefore ( ) {
try {
PowerMock . mockStatic ( Toolkit . class ) ;
PowerMock . expectNew ( VideoAction . class ) . andReturn ( videoAction ) . anyTimes ( ) ;
EasyMock . expect ( Toolkit . i18nText ( EasyMock . anyString ( ) ) ) . andReturn ( "test" ) . anyTimes ( ) ;
PowerMock . expectNew ( TutorialAction . class ) . andReturn ( tutorialAction ) . anyTimes ( ) ;
PowerMock . mockStatic ( SystemScaleUtils . class ) ;
PowerMock . expectNew ( WebDemoAction . class ) . andReturn ( webDemoAction ) . anyTimes ( ) ;
EasyMock . expect ( SystemScaleUtils . sysScale ( ) ) . andReturn ( 1F ) . anyTimes ( ) ;
PowerMock . expectNew ( SoftwareUpdateAction . class ) . andReturn ( softwareUpdateAction ) . anyTimes ( ) ;
EasyMock . expect ( SystemScaleUtils . isJreHiDPIEnabled ( ) ) . andReturn ( false ) . anyTimes ( ) ;
PowerMock . expectNew ( AlphaFineAction . class ) . andReturn ( alphaFineAction ) . anyTimes ( ) ;
PowerMock . replay ( ) ;
PowerMock . expectNew ( FineUIAction . class ) . andReturn ( fineUIAction ) . anyTimes ( ) ;
PowerMock . expectNew ( AboutAction . class ) . andReturn ( aboutAction ) . anyTimes ( ) ;
} catch ( Exception e ) {
Assert . fail ( e . getMessage ( ) ) ;
}
}
}
@Test
@Test
public void testCreateHelpShortCuts ( ) {
public void testCreateHelpShortCutsWithLocaleChina ( ) {
// 处理判断条件
// 处理判断条件
GeneralContext context = EasyMock . createMock ( GeneralContext . class ) ;
GeneralContext context = EasyMock . createMock ( GeneralContext . class ) ;
PowerMock . mockStatic ( GeneralContext . class ) ;
PowerMock . mockStatic ( GeneralContext . class ) ;
EasyMock . expect ( GeneralContext . getLocale ( ) ) . andReturn ( Locale . CHINA ) . once ( ) ;
EasyMock . expect ( GeneralContext . getLocale ( ) ) . andReturn ( Locale . CHINA ) . anyTimes ( ) ;
EasyMock . expect ( GeneralContext . getLocale ( ) ) . andReturn ( Locale . US ) . once ( ) ;
Workspace workspace = EasyMock . createMock ( Workspace . class ) ;
Workspace workspace = EasyMock . createMock ( Workspace . class ) ;
PowerMock . mockStatic ( WorkContext . class ) ;
PowerMock . mockStatic ( WorkContext . class ) ;
EasyMock . expect ( WorkContext . getCurrent ( ) ) . andReturn ( workspace ) . anyTimes ( ) ;
EasyMock . expect ( WorkContext . getCurrent ( ) ) . andReturn ( workspace ) . anyTimes ( ) ;
EasyMock . expect ( workspace . isLocal ( ) ) . andReturn ( true ) . anyTimes ( ) ;
EasyMock . expect ( workspace . isLocal ( ) ) . andReturn ( false ) . once ( ) ;
EasyMock . expect ( workspace . isLocal ( ) ) . andReturn ( true ) . once ( ) ;
DesignerEnvManager envManager = EasyMock . createMock ( DesignerEnvManager . class ) ;
DesignerEnvManager envManager = EasyMock . createMock ( DesignerEnvManager . class ) ;
PowerMock . mockStatic ( DesignerEnvManager . class ) ;
PowerMock . mockStatic ( DesignerEnvManager . class ) ;
EasyMock . expect ( DesignerEnvManager . getEnvManager ( ) ) . andReturn ( envManager ) . anyTimes ( ) ;
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 ) ;
AlphaFineConfigManager configManager = EasyMock . createMock ( AlphaFineConfigManager . class ) ;
PowerMock . mockStatic ( AlphaFineConfigManager . class ) ;
PowerMock . mockStatic ( AlphaFineConfigManager . class ) ;
EasyMock . expect ( AlphaFineConfigManager . isALPHALicAvailable ( ) ) . andReturn ( false ) . once ( ) ;
EasyMock . expect ( configManager . isALPHALicAvailable ( ) ) . andReturn ( false ) . anyTimes ( ) ;
EasyMock . expect ( AlphaFineConfigManager . isALPHALicAvailable ( ) ) . andReturn ( true ) . once ( ) ;
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 ) ;
SupportOSImpl osImpl = EasyMock . createMock ( SupportOSImpl . class ) ;
Whitebox . setInternalState ( SupportOSImpl . class , "FINEUI" , osImpl ) ;
Whitebox . setInternalState ( SupportOSImpl . class , "FINEUI" , osImpl ) ;
@ -118,12 +156,14 @@ public class ToolBarMenuDockTest {
}
}
} ;
} ;
ShortCut [ ] shortCuts1 = new ShortCut [ ] { SeparatorDef . DEFAULT , aboutAction } ;
ShortCut [ ] shortCuts = new ShortCut [ ] {
ShortCut [ ] shortCuts2 = new ShortCut [ ] { videoAction , tutorialAction , webDemoAction ,
new VideoAction ( ) ,
softwareUpdateAction , alphaFineAction , SeparatorDef . DEFAULT , aboutAction } ;
new TutorialAction ( ) ,
new TechSupportAction ( ) ,
Assert . assertEquals ( menuDock . createHelpShortCuts ( ) , shortCuts1 ) ;
new EnvDetectorAction ( ) ,
Assert . assertEquals ( menuDock . createHelpShortCuts ( ) , shortCuts2 ) ;
SeparatorDef . DEFAULT ,
new AboutAction ( ) } ;
Assert . assertEquals ( menuDock . createHelpShortCuts ( ) , shortCuts ) ;
}
}
}
}