Search in sources :

Example 6 with MockApplicationEx

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

the class BuckClientTest method testConnectDisconnect.

@Test
public void testConnectDisconnect() {
    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).disconnectWithoutRetry();
    buckSocket.onClose(0, "FOO");
    assertFalse(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 7 with MockApplicationEx

use of com.intellij.mock.MockApplicationEx in project android by JetBrains.

the class SdkComponentSourceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    //noinspection Convert2Lambda Since otherwise it desn't create new instances.
    myDisposable = new Disposable() {

        @Override
        public void dispose() {
        }
    };
    MockApplicationEx instance = new MockApplicationEx(myDisposable);
    instance.registerService(ExternalComponentManager.class, ExternalComponentManagerImpl.class);
    instance.registerService(UpdateSettings.class, UpdateSettings.class);
    ApplicationManager.setApplication(instance, myDisposable);
    myFileOp = new MockFileOp();
    myFileOp.recordExistingFile("/sdk/noRemote/package.xml", getLocalRepoXml("noRemote", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/newerRemote/package.xml", getLocalRepoXml("newerRemote", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/sameRemote/package.xml", getLocalRepoXml("sameRemote", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/olderRemote/package.xml", getLocalRepoXml("olderRemote", new Revision(1, 2)));
    myFileOp.recordExistingFile("/sdk/hasPreview/package.xml", getLocalRepoXml("hasPreview", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/newerPreview/package.xml", getLocalRepoXml("newerPreview", new Revision(1, 0, 0, 1)));
    myFileOp.recordExistingFile("/sdk/samePreview/package.xml", getLocalRepoXml("samePreview", new Revision(1, 0, 0, 1)));
    myFileOp.recordExistingFile("/sdk/olderPreview/package.xml", getLocalRepoXml("olderPreview", new Revision(2)));
    myFileOp.recordExistingFile("/sdk/zNewerInBeta/package.xml", getLocalRepoXml("zNewerInBeta", new Revision(1)));
    final FakeDownloader downloader = new FakeDownloader(myFileOp);
    List<String> remotePaths = Lists.newArrayList();
    List<Revision> remoteRevisions = Lists.newArrayList();
    List<Integer> remoteChannels = Lists.newArrayList();
    remotePaths.add("newerRemote");
    remoteRevisions.add(new Revision(1, 1));
    remoteChannels.add(0);
    remotePaths.add("sameRemote");
    remoteRevisions.add(new Revision(1));
    remoteChannels.add(0);
    remotePaths.add("olderRemote");
    remoteRevisions.add(new Revision(1, 1));
    remoteChannels.add(0);
    remotePaths.add("hasPreview");
    remoteRevisions.add(new Revision(1, 0, 0, 1));
    remoteChannels.add(0);
    remotePaths.add("newerPreview");
    remoteRevisions.add(new Revision(1, 0, 0, 2));
    remoteChannels.add(0);
    remotePaths.add("samePreview");
    remoteRevisions.add(new Revision(1, 0, 0, 1));
    remoteChannels.add(0);
    remotePaths.add("olderPreview");
    remoteRevisions.add(new Revision(1, 0, 0, 1));
    remoteChannels.add(0);
    remotePaths.add("onlyRemote");
    remoteRevisions.add(new Revision(1));
    remoteChannels.add(0);
    remotePaths.add("zNewerInBeta");
    remoteRevisions.add(new Revision(2));
    remoteChannels.add(1);
    String url = "http://example.com/repo";
    downloader.registerUrl(new URL(url), getRepoXml(remotePaths, remoteRevisions, remoteChannels, true).getBytes());
    final RepoManager mgr = new RepoManagerImpl(myFileOp);
    mgr.setLocalPath(new File("/sdk"));
    mgr.registerSchemaModule(AndroidSdkHandler.getRepositoryModule());
    mgr.registerSchemaModule(AndroidSdkHandler.getCommonModule());
    mgr.registerSourceProvider(new FakeRepositorySourceProvider(ImmutableList.<RepositorySource>of(new SimpleRepositorySource(url, "dummy", true, mgr.getSchemaModules(), null))));
    myChannelId = 0;
    myTestComponentSource = new SdkComponentSource() {

        @Nullable
        @Override
        public List<String> getAllChannels() {
            return null;
        }

        @Override
        @NotNull
        RepoManager getRepoManager() {
            return mgr;
        }

        @NotNull
        @Override
        SettingsController getSettingsController() {
            return new FakeSettingsController(false) {

                @Override
                public Channel getChannel() {
                    return Channel.create(myChannelId);
                }
            };
        }

        @NotNull
        @Override
        Downloader getDownloader(@Nullable ProgressIndicator indicator) {
            return downloader;
        }
    };
}
Also used : NotNull(org.jetbrains.annotations.NotNull) URL(java.net.URL) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ImmutableList(com.google.common.collect.ImmutableList) Disposable(com.intellij.openapi.Disposable) MockApplicationEx(com.intellij.mock.MockApplicationEx) RepoManagerImpl(com.android.repository.impl.manager.RepoManagerImpl) Revision(com.android.repository.Revision) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with MockApplicationEx

use of com.intellij.mock.MockApplicationEx in project android by JetBrains.

the class FormFactorApiComboBoxTest method setUp.

@Before
public void setUp() throws Exception {
    //noinspection Convert2Lambda Since otherwise it doesn't create new instances.
    myDisposable = new Disposable() {

        @Override
        public void dispose() {
        }
    };
    MockApplicationEx instance = new MockApplicationEx(myDisposable);
    instance.registerService(PropertiesComponent.class, ProjectPropertiesComponentImpl.class);
    ApplicationManager.setApplication(instance, myDisposable);
}
Also used : Disposable(com.intellij.openapi.Disposable) MockApplicationEx(com.intellij.mock.MockApplicationEx) Before(org.junit.Before)

Example 9 with MockApplicationEx

use of com.intellij.mock.MockApplicationEx in project kotlin by JetBrains.

the class KtPlatformLiteFixture method initApplication.

public void initApplication() {
    MockApplicationEx instance = new MockApplicationEx(getTestRootDisposable());
    ApplicationManager.setApplication(instance, new Getter<FileTypeRegistry>() {

        @Override
        public FileTypeRegistry get() {
            return FileTypeManager.getInstance();
        }
    }, getTestRootDisposable());
    getApplication().registerService(EncodingManager.class, CoreEncodingProjectManager.class);
}
Also used : MockApplicationEx(com.intellij.mock.MockApplicationEx) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry)

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