Search in sources :

Example 1 with MockApplication

use of com.intellij.mock.MockApplication in project buck by facebook.

the class BuckClientTest method hasBuckDisconnectedThenWeReconnectIfSoSpecified.

@Test
public void hasBuckDisconnectedThenWeReconnectIfSoSpecified() {
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    MockDisposable mockDisposable = new MockDisposable();
    MockApplication application = new MockApplicationEx(mockDisposable);
    ApplicationManager.setApplication(application, mockDisposable);
    Project project = new MockProjectEx(new MockDisposable());
    TestBuckEventHandler handler = new TestBuckEventHandler();
    BuckSocket buckSocket = new BuckSocket(handler);
    BuckClientManager.getOrCreateClient(project, handler).setBuckSocket(buckSocket);
    BuckClientManager.getOrCreateClient(project, handler).connect();
    buckSocket.onConnect(new MockSession());
    BuckClientManager.getOrCreateClient(project, handler).disconnectWithRetry();
    buckSocket.onClose(0, "FOO");
    buckSocket.onConnect(new MockSession());
    assertTrue(BuckClientManager.getOrCreateClient(project, handler).isConnected());
}
Also used : Project(com.intellij.openapi.project.Project) MockApplicationEx(com.intellij.mock.MockApplicationEx) MockSession(com.facebook.buck.intellij.ideabuck.test.util.MockSession) MockApplication(com.intellij.mock.MockApplication) MockDisposable(com.facebook.buck.intellij.ideabuck.test.util.MockDisposable) MockProjectEx(com.intellij.mock.MockProjectEx) Test(org.junit.Test)

Example 2 with MockApplication

use of com.intellij.mock.MockApplication in project buck by facebook.

the class BuckEventsConsumerTest method initialiseEventsConsumer.

public BuckEventsConsumer initialiseEventsConsumer() {
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    MockDisposable mockDisposable = new MockDisposable();
    MockProject project = new MockProjectEx(new MockDisposable());
    MockApplication application = new MyMockApplication(mockDisposable);
    ApplicationManager.setApplication(application, mockDisposable);
    final BuckEventsConsumer buckEventsConsumer = new BuckEventsConsumer(project);
    project.registerService(BuckUIManager.class, new BuckUIManager());
    project.registerService(ToolWindowManager.class, new Mock.MyToolWindowManager());
    application.registerService(FileDocumentManager.class, new MockFileDocumentManagerImpl(null, null));
    application.registerService(VirtualFileManager.class, EasyMock.createMock(VirtualFileManager.class));
    return buckEventsConsumer;
}
Also used : MockProject(com.intellij.mock.MockProject) MockFileDocumentManagerImpl(com.intellij.mock.MockFileDocumentManagerImpl) MockApplication(com.intellij.mock.MockApplication) MyMockApplication(com.facebook.buck.intellij.ideabuck.test.util.MyMockApplication) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) MockDisposable(com.facebook.buck.intellij.ideabuck.test.util.MockDisposable) MyMockApplication(com.facebook.buck.intellij.ideabuck.test.util.MyMockApplication) MockProjectEx(com.intellij.mock.MockProjectEx) EasyMock(org.easymock.EasyMock) Mock(com.intellij.mock.Mock)

Example 3 with MockApplication

use of com.intellij.mock.MockApplication in project buck by facebook.

the class BuckClientTest method testMessages.

@Test
public void testMessages() {
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    MockDisposable mockDisposable = new MockDisposable();
    MockApplication application = new MockApplicationEx(mockDisposable);
    ApplicationManager.setApplication(application, mockDisposable);
    Project project = new MockProjectEx(new MockDisposable());
    TestBuckEventHandler handler = new TestBuckEventHandler();
    BuckClient client = BuckClientManager.getOrCreateClient(project, handler);
    // Set the socket we control
    BuckSocket socket = new BuckSocket(handler);
    client.setBuckSocket(socket);
    client.connect();
    assertEquals("", handler.getLastMessage());
    socket.onMessage("some text");
    assertEquals("some text", handler.getLastMessage());
    socket.onMessage("some text 1");
    socket.onMessage("some text 2");
    socket.onMessage("some text 3");
    socket.onMessage("some text 4");
    assertEquals("some text 4", handler.getLastMessage());
}
Also used : Project(com.intellij.openapi.project.Project) MockApplicationEx(com.intellij.mock.MockApplicationEx) MockApplication(com.intellij.mock.MockApplication) MockDisposable(com.facebook.buck.intellij.ideabuck.test.util.MockDisposable) MockProjectEx(com.intellij.mock.MockProjectEx) Test(org.junit.Test)

Example 4 with MockApplication

use of com.intellij.mock.MockApplication in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugHistoricalSnapshotsTest method setUp.

@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);
    application.registerService(UISettings.class);
    ApplicationManager.setApplication(application, parent);
    XDebugSession session = Mockito.mock(XDebugSession.class);
    Mockito.when(handler.getProcess()).thenReturn(mockProcess);
    Mockito.when(mockProcess.getXDebugSession()).thenReturn(session);
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) MockApplication(com.intellij.mock.MockApplication) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) JComponent(javax.swing.JComponent) ActionToolbar(com.intellij.openapi.actionSystem.ActionToolbar) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx) Before(org.junit.Before)

Example 5 with MockApplication

use of com.intellij.mock.MockApplication in project buck by facebook.

the class BuckModuleTest method initBuckModule.

public Project initBuckModule() {
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    MockDisposable mockDisposable = new MockDisposable();
    MockProjectEx project = new MockProjectEx(mockDisposable);
    MockApplication application = new MockApplicationEx(mockDisposable);
    ApplicationManager.setApplication(application, mockDisposable);
    application.registerService(UISettings.class, UISettings.getShadowInstance());
    application.registerService(PropertiesComponent.class, new ProjectPropertiesComponentImpl());
    FileTypeManager fileTypeManager = EasyMock.createMock(FileTypeManager.class);
    EasyMock.expect(fileTypeManager.getFileTypeByFileName(BuckFileType.INSTANCE.getDefaultExtension())).andReturn(BuckFileType.INSTANCE).times(3);
    EasyMock.replay(fileTypeManager);
    application.registerService(FileTypeManager.class, fileTypeManager);
    project.addComponent(PsiDocumentManager.class, EasyMock.createMock(PsiDocumentManager.class));
    return project;
}
Also used : MockApplicationEx(com.intellij.mock.MockApplicationEx) MockApplication(com.intellij.mock.MockApplication) MockDisposable(com.facebook.buck.intellij.ideabuck.test.util.MockDisposable) ProjectPropertiesComponentImpl(com.intellij.ide.util.ProjectPropertiesComponentImpl) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) MockProjectEx(com.intellij.mock.MockProjectEx) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Aggregations

MockApplication (com.intellij.mock.MockApplication)8 MockDisposable (com.facebook.buck.intellij.ideabuck.test.util.MockDisposable)6 MockProjectEx (com.intellij.mock.MockProjectEx)6 MockApplicationEx (com.intellij.mock.MockApplicationEx)5 Test (org.junit.Test)4 Project (com.intellij.openapi.project.Project)3 MockSession (com.facebook.buck.intellij.ideabuck.test.util.MockSession)2 MyMockApplication (com.facebook.buck.intellij.ideabuck.test.util.MyMockApplication)2 ProjectPropertiesComponentImpl (com.intellij.ide.util.ProjectPropertiesComponentImpl)1 Mock (com.intellij.mock.Mock)1 MockFileDocumentManagerImpl (com.intellij.mock.MockFileDocumentManagerImpl)1 MockProject (com.intellij.mock.MockProject)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 ActionToolbar (com.intellij.openapi.actionSystem.ActionToolbar)1 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)1 Application (com.intellij.openapi.application.Application)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1