Search in sources :

Example 1 with MockApplicationEx

use of com.intellij.mock.MockApplicationEx 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 MockApplicationEx

use of com.intellij.mock.MockApplicationEx 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 3 with MockApplicationEx

use of com.intellij.mock.MockApplicationEx in project intellij-community by JetBrains.

the class PlatformLiteFixture method initApplication.

public void initApplication() {
    //if (ApplicationManager.getApplication() instanceof MockApplicationEx) return;
    final MockApplicationEx instance = new MockApplicationEx(getTestRootDisposable());
    ApplicationManager.setApplication(instance, () -> FileTypeManager.getInstance(), getTestRootDisposable());
    getApplication().registerService(EncodingManager.class, EncodingManagerImpl.class);
}
Also used : MockApplicationEx(com.intellij.mock.MockApplicationEx)

Example 4 with MockApplicationEx

use of com.intellij.mock.MockApplicationEx 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 MockApplicationEx

use of com.intellij.mock.MockApplicationEx 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

MockApplicationEx (com.intellij.mock.MockApplicationEx)9 MockDisposable (com.facebook.buck.intellij.ideabuck.test.util.MockDisposable)5 MockApplication (com.intellij.mock.MockApplication)5 MockProjectEx (com.intellij.mock.MockProjectEx)5 Test (org.junit.Test)4 Project (com.intellij.openapi.project.Project)3 MockSession (com.facebook.buck.intellij.ideabuck.test.util.MockSession)2 Disposable (com.intellij.openapi.Disposable)2 Revision (com.android.repository.Revision)1 RepoManagerImpl (com.android.repository.impl.manager.RepoManagerImpl)1 MyMockApplication (com.facebook.buck.intellij.ideabuck.test.util.MyMockApplication)1 ImmutableList (com.google.common.collect.ImmutableList)1 ProjectPropertiesComponentImpl (com.intellij.ide.util.ProjectPropertiesComponentImpl)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 FileTypeRegistry (com.intellij.openapi.fileTypes.FileTypeRegistry)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1