Search in sources :

Example 6 with MockProjectEx

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

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

Example 8 with MockProjectEx

use of com.intellij.mock.MockProjectEx 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 9 with MockProjectEx

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

the class CloudBreakpointHandlerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    fixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture();
    fixture.setUp();
    project = new MockProjectEx(getTestRootDisposable());
    psiManager = mock(PsiManager.class);
    project.registerService(PsiManager.class, psiManager);
    XDebugSession session = mock(XDebugSession.class);
    when(session.getProject()).thenReturn(project);
    process = mock(CloudDebugProcess.class);
    when(process.getXDebugSession()).thenReturn(session);
    CloudDebugProcessState processState = mock(CloudDebugProcessState.class);
    existingBreakpoints = new ArrayList<Breakpoint>();
    when(processState.getCurrentServerBreakpointList()).thenReturn(ContainerUtil.immutableList(existingBreakpoints));
    when(process.getProcessState()).thenReturn(processState);
    stateController = mock(CloudDebugProcessStateController.class);
    when(process.getStateController()).thenReturn(stateController);
    registrationShouldSucceed = true;
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            addedBp.set((Breakpoint) invocation.getArguments()[0]);
            SetBreakpointHandler handler = (SetBreakpointHandler) invocation.getArguments()[1];
            if (registrationShouldSucceed) {
                handler.onSuccess(desiredResultId);
            } else {
                handler.onError("Registration failed");
            }
            return null;
        }
    }).when(stateController).setBreakpointAsync(any(Breakpoint.class), any(SetBreakpointHandler.class));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            removedBp.set((String) invocation.getArguments()[0]);
            return null;
        }
    }).when(stateController).deleteBreakpointAsync(anyString());
    fileResolver = mock(ServerToIdeFileResolver.class);
    handler = new CloudBreakpointHandler(process, fileResolver);
    XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
    project.addComponent(XDebuggerManager.class, debuggerManager);
    breakpointManager = mock(XBreakpointManager.class);
    when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) PsiManager(com.intellij.psi.PsiManager) SetBreakpointHandler(com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) Matchers.anyString(org.mockito.Matchers.anyString) MockProjectEx(com.intellij.mock.MockProjectEx) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 10 with MockProjectEx

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

the class CloudDebugProcessStateTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    fixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture();
    fixture.setUp();
    project = new MockProjectEx(getTestRootDisposable());
    PsiManager psiManager = Mockito.mock(PsiManager.class);
    project.registerService(PsiManager.class, psiManager);
    IntegratedGoogleLoginService mockLoginService = TestUtils.installMockService(IntegratedGoogleLoginService.class);
    GoogleLoginState googleLoginState = Mockito.mock(GoogleLoginState.class);
    CredentialedUser user = Mockito.mock(CredentialedUser.class);
    LinkedHashMap<String, CredentialedUser> allusers = new LinkedHashMap<String, CredentialedUser>();
    when(user.getEmail()).thenReturn(USER);
    when(user.getGoogleLoginState()).thenReturn(googleLoginState);
    when(googleLoginState.fetchAccessToken()).thenReturn(PASSWORD);
    when(mockLoginService.getAllUsers()).thenReturn(allusers);
    allusers.put(USER, user);
}
Also used : IntegratedGoogleLoginService(com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService) GoogleLoginState(com.google.gdt.eclipse.login.common.GoogleLoginState) PsiManager(com.intellij.psi.PsiManager) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) MockProjectEx(com.intellij.mock.MockProjectEx) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MockProjectEx (com.intellij.mock.MockProjectEx)10 MockDisposable (com.facebook.buck.intellij.ideabuck.test.util.MockDisposable)6 MockApplication (com.intellij.mock.MockApplication)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 MockProject (com.intellij.mock.MockProject)2 PsiManager (com.intellij.psi.PsiManager)2 Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)1 SetBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler)1 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)1 CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)1 IntegratedGoogleLoginService (com.google.cloud.tools.intellij.login.IntegratedGoogleLoginService)1 GoogleLoginState (com.google.gdt.eclipse.login.common.GoogleLoginState)1 ProjectPropertiesComponentImpl (com.intellij.ide.util.ProjectPropertiesComponentImpl)1 Mock (com.intellij.mock.Mock)1 MockFileDocumentManagerImpl (com.intellij.mock.MockFileDocumentManagerImpl)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1