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