public static void setApplication(
     Application instance,
     Getter<FileTypeRegistry> fileTypeRegistryGetter,
     Getter<EncodingRegistry> encodingRegistryGetter,
     @NotNull Disposable parent) {
   final Application old = ourApplication;
   final Getter<FileTypeRegistry> oldFileTypeRegistry = FileTypeRegistry.ourInstanceGetter;
   final Getter<EncodingRegistry> oldEncodingRegistry = EncodingRegistry.ourInstanceGetter;
   Disposer.register(
       parent,
       new Disposable() {
         @Override
         public void dispose() {
           if (old != null) { // to prevent NPEs in threads still running
             setApplication(old);
             //noinspection AssignmentToStaticFieldFromInstanceMethod
             FileTypeRegistry.ourInstanceGetter = oldFileTypeRegistry;
             EncodingRegistry.ourInstanceGetter = oldEncodingRegistry;
           }
         }
       });
   setApplication(instance);
   FileTypeRegistry.ourInstanceGetter = fileTypeRegistryGetter;
   EncodingRegistry.ourInstanceGetter = encodingRegistryGetter;
 }
 public static void setApplication(Application instance, @NotNull Disposable parent) {
   final Application old = ourApplication;
   Disposer.register(
       parent,
       new Disposable() {
         @Override
         public void dispose() {
           if (old != null) { // to prevent NPEs in threads still running
             setApplication(old);
           }
         }
       });
   setApplication(instance);
 }
  @Before
  public void setUp() {
    MockApplication application = new MyMockApplicationEx(parent);
    ActionManagerEx manager = Mockito.mock(ActionManagerEx.class);
    ActionToolbar actionToolbar = Mockito.mock(ActionToolbar.class);
    Mockito.when(actionToolbar.getComponent()).thenReturn(new JComponent() {});
    Mockito.when(
            manager.createActionToolbar(
                Mockito.anyString(), Mockito.any(ActionGroup.class), Mockito.anyBoolean()))
        .thenReturn(actionToolbar);
    Mockito.when(
            manager.createActionToolbar(
                Mockito.anyString(),
                Mockito.any(ActionGroup.class),
                Mockito.anyBoolean(),
                Mockito.anyBoolean()))
        .thenReturn(actionToolbar);
    application.addComponent(ActionManager.class, manager);
    ApplicationManager.setApplication(application, parent);

    XDebugSession session = Mockito.mock(XDebugSession.class);
    Mockito.when(handler.getProcess()).thenReturn(mockProcess);
    Mockito.when(mockProcess.getXDebugSession()).thenReturn(session);
  }