Search in sources :

Example 6 with XDebuggerManager

use of com.intellij.xdebugger.XDebuggerManager 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 7 with XDebuggerManager

use of com.intellij.xdebugger.XDebuggerManager in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateCollectorTest method createMockXDebuggerManager.

void createMockXDebuggerManager(Project project, XDebugSession[] value) {
    XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
    when(debuggerManager.getDebugSessions()).thenReturn(value);
    when(project.getComponent(XDebuggerManager.class)).thenReturn(debuggerManager);
}
Also used : XDebuggerManager(com.intellij.xdebugger.XDebuggerManager)

Example 8 with XDebuggerManager

use of com.intellij.xdebugger.XDebuggerManager in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessTest method testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation.

public void testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation() throws Exception {
    // override the default XBreakpointManager implementation with mock to use Mockito.verify()
    XBreakpointManager breakpointManager = mock(XBreakpointManager.class);
    XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
    when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
    ((ProjectImpl) getProject()).registerComponentInstance(XDebuggerManager.class, debuggerManager);
    ArrayList<Breakpoint> breakpoints = new ArrayList<Breakpoint>();
    Breakpoint breakpoint = new Breakpoint();
    breakpoint.setId("breakpointId").setIsFinalState(Boolean.TRUE).setStatus(new StatusMessage().setIsError(Boolean.TRUE));
    breakpoints.add(breakpoint);
    CloudDebugProcessState processState = mock(CloudDebugProcessState.class);
    when(processState.getCurrentServerBreakpointList()).thenReturn(ContainerUtil.immutableList(breakpoints));
    XLineBreakpointImpl xLineBreakpointImpl = mock(XLineBreakpointImpl.class);
    CloudLineBreakpoint cloudLineBreakpoint = mockCloudLineBreakpoint("mock error message", xLineBreakpointImpl);
    when(xLineBreakpointImpl.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY)).thenReturn(cloudLineBreakpoint);
    CloudBreakpointHandler breakpointHandler = mock(CloudBreakpointHandler.class);
    when(breakpointHandler.getEnabledXBreakpoint(breakpoint)).thenReturn(xLineBreakpointImpl);
    process.setBreakpointHandler(breakpointHandler);
    process.initialize(processState);
    process.onBreakpointListChanged(mock(CloudDebugProcessState.class));
    verify(cloudLineBreakpoint).setErrorMessage(eq("General error"));
    verify(cloudLineBreakpoint).getXBreakpoint();
    verify(cloudLineBreakpoint).getSetIcon(Matchers.anyBoolean());
    verify(cloudLineBreakpoint).getErrorMessage();
    verify(breakpointManager).updateBreakpointPresentation(same(xLineBreakpointImpl), any(Icon.class), eq("General error"));
    process.getStateController().stopBackgroundListening();
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) ProjectImpl(com.intellij.openapi.project.impl.ProjectImpl) ArrayList(java.util.ArrayList) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) Icon(javax.swing.Icon) StatusMessage(com.google.api.services.clouddebugger.v2.model.StatusMessage)

Example 9 with XDebuggerManager

use of com.intellij.xdebugger.XDebuggerManager in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessTest method mockCloudDebugProcess.

@NotNull
private CloudDebugProcess mockCloudDebugProcess(XBreakpointManager breakpointManager, XDebugSession debugSession) {
    Project project = mock(Project.class);
    when(debugSession.getProject()).thenReturn(project);
    XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
    when(project.getComponent(XDebuggerManager.class)).thenReturn(debuggerManager);
    when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
    return new CloudDebugProcess(debugSession);
}
Also used : Project(com.intellij.openapi.project.Project) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)9 XDebugSession (com.intellij.xdebugger.XDebugSession)6 NotNull (org.jetbrains.annotations.NotNull)5 XDebugProcess (com.intellij.xdebugger.XDebugProcess)3 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)3 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)3 Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)2 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)2 ExecutionResult (com.intellij.execution.ExecutionResult)2 RunProfile (com.intellij.execution.configurations.RunProfile)2 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)2 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)2 ArrayList (java.util.ArrayList)2 StatusMessage (com.google.api.services.clouddebugger.v2.model.StatusMessage)1 SetBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RunManager (com.intellij.execution.RunManager)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 MockProjectEx (com.intellij.mock.MockProjectEx)1