Search in sources :

Example 1 with MockDisposable

use of com.facebook.buck.intellij.ideabuck.test.util.MockDisposable 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 MockDisposable

use of com.facebook.buck.intellij.ideabuck.test.util.MockDisposable 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 MockDisposable

use of com.facebook.buck.intellij.ideabuck.test.util.MockDisposable 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 MockDisposable

use of com.facebook.buck.intellij.ideabuck.test.util.MockDisposable 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)

Example 5 with MockDisposable

use of com.facebook.buck.intellij.ideabuck.test.util.MockDisposable in project buck by facebook.

the class BuckEventsConsumerTest method hasBuckModuleAttachReceivedNullTargetThenWeShowNone.

@Test
public void hasBuckModuleAttachReceivedNullTargetThenWeShowNone() throws NoSuchFieldException, IllegalAccessException {
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    MockDisposable mockDisposable = new MockDisposable();
    MockApplication application = new MockApplicationEx(mockDisposable);
    ApplicationManager.setApplication(application, mockDisposable);
    BuckEventsConsumer buckEventsConsumer = new BuckEventsConsumer(new MockProjectEx(new MockDisposable()));
    buckEventsConsumer.attach(null, new DefaultTreeModel(null));
    Field privateStringField = BuckEventsConsumer.class.getDeclaredField("mTarget");
    privateStringField.setAccessible(true);
    String fieldValue = (String) privateStringField.get(buckEventsConsumer);
    assertEquals(fieldValue, "NONE");
}
Also used : Field(java.lang.reflect.Field) MockApplicationEx(com.intellij.mock.MockApplicationEx) MockApplication(com.intellij.mock.MockApplication) MyMockApplication(com.facebook.buck.intellij.ideabuck.test.util.MyMockApplication) MockDisposable(com.facebook.buck.intellij.ideabuck.test.util.MockDisposable) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) MockProjectEx(com.intellij.mock.MockProjectEx) Test(org.junit.Test)

Aggregations

MockDisposable (com.facebook.buck.intellij.ideabuck.test.util.MockDisposable)6 MockApplication (com.intellij.mock.MockApplication)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 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 Field (java.lang.reflect.Field)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 EasyMock (org.easymock.EasyMock)1