@NotNull // mock behavior except for get/setErrorMessage() to simplify code private CloudLineBreakpoint mockCloudLineBreakpoint( CloudDebugProcess spyDebugProcess, String errorMessage, XLineBreakpointImpl xLineBreakpoint) { CloudLineBreakpoint breakpoint = mock(CloudLineBreakpoint.class); when(breakpoint.getSetIcon(anyBoolean())).thenReturn(mock(Icon.class)); doAnswer(invocationOnMock -> xLineBreakpoint).when(spyDebugProcess).getXBreakpoint(any()); when(breakpoint.getErrorMessage()).thenReturn(errorMessage); return breakpoint; } }
public void testRegisterBreakpointErrorShouldSetErrorMessageAndCallUpdateBreakpointPresentation2() { registerMockBreakpoint( psiJavaFile, new String[] {"foowatch1"}, "condition == true", 123, "foo.java", "com.google", false, ""); ArgumentCaptor<CloudLineBreakpoint> breakpointArgumentCaptor = ArgumentCaptor.forClass(CloudLineBreakpoint.class); verify(process).updateBreakpointPresentation(breakpointArgumentCaptor.capture()); assertThat( breakpointArgumentCaptor.getValue().getErrorMessage(), equalTo("The snapshot location could not be set.")); }
public void testRegisterBreakpointErrorShouldSetErrorMessageAndCallUpdateBreakpointPresentation() { registrationShouldSucceed = false; registerMockBreakpoint( psiJavaFile, new String[] {"foowatch1"}, "condition == true", 123, "foo.java", "com.google", false, "b_id"); ArgumentCaptor<CloudLineBreakpoint> breakpointArgumentCaptor = ArgumentCaptor.forClass(CloudLineBreakpoint.class); verify(process).updateBreakpointPresentation(breakpointArgumentCaptor.capture()); assertThat( breakpointArgumentCaptor.getValue().getErrorMessage(), equalTo("Registration failed")); }
verify(process, times(1)).getXBreakpoint(cloudLineBreakpoint); verify(cloudLineBreakpoint).getSetIcon(anyBoolean()); verify(cloudLineBreakpoint).getErrorMessage(); verify(breakpointManager) .updateBreakpointPresentation(
public void testSimpleKotlinFileBreakpointRegister() { KtFile ktFile = mock(KtFile.class); when(ktFile.getFileType()).thenReturn(KotlinFileType.INSTANCE); registerMockBreakpoint( ktFile, new String[] {"foowatch1"}, "condition == true", 123, "foo.java", "com.google", false, "b_id"); assertNull(removedBp.get()); assertNotNull(addedBp.get()); assertContainsElements(addedBp.get().getExpressions(), "foowatch1"); assertTrue(addedBp.get().getLocation().getLine() == 124); assertTrue(addedBp.get().getLocation().getPath().equals("com/google/foo.java")); assertTrue(addedBp.get().getCondition().equals("condition == true")); ArgumentCaptor<CloudLineBreakpoint> breakpointArgumentCaptor = ArgumentCaptor.forClass(CloudLineBreakpoint.class); verify(process).updateBreakpointPresentation(breakpointArgumentCaptor.capture()); assertThat(breakpointArgumentCaptor.getValue().getErrorMessage(), nullValue()); }
public void testSimpleJavaFileBreakpointRegister() { registerMockBreakpoint( psiJavaFile, new String[] {"foowatch1"}, "condition == true", 123, "foo.java", "com.google", false, "b_id"); assertNull(removedBp.get()); assertNotNull(addedBp.get()); assertContainsElements(addedBp.get().getExpressions(), "foowatch1"); assertTrue(addedBp.get().getLocation().getLine() == 124); assertTrue(addedBp.get().getLocation().getPath().equals("com/google/foo.java")); assertTrue(addedBp.get().getCondition().equals("condition == true")); ArgumentCaptor<CloudLineBreakpoint> breakpointArgumentCaptor = ArgumentCaptor.forClass(CloudLineBreakpoint.class); verify(process).updateBreakpointPresentation(breakpointArgumentCaptor.capture()); assertThat(breakpointArgumentCaptor.getValue().getErrorMessage(), nullValue()); }
@Override public void loadFrom(@NotNull XLineBreakpoint<CloudLineBreakpointProperties> breakpoint) { XBreakpointBase lineBreakpointImpl = breakpoint instanceof XBreakpointBase ? (XBreakpointBase) breakpoint : null; Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint); CloudLineBreakpoint cloudBreakpoint = null; if (javaBreakpoint instanceof CloudLineBreakpoint) { cloudBreakpoint = (CloudLineBreakpoint) javaBreakpoint; } if (cloudBreakpoint == null || lineBreakpointImpl == null) { return; } errorPanel.setVisible(cloudBreakpoint.hasError()); if (cloudBreakpoint.hasError()) { errorLabel.setForeground(JBColor.RED); errorDescription.setText(cloudBreakpoint.getErrorMessage()); } }
@Test public void testUpdateBreakpointRepresentationUsesBreakpointErrorMsgAndIcon() { XBreakpointManager breakpointManager = mock(XBreakpointManager.class); CloudDebugProcess cloudDebugProcess = mockCloudDebugProcess(breakpointManager, mock(XDebugSession.class)); XLineBreakpointImpl xBreakpoint = mock(XLineBreakpointImpl.class); CloudLineBreakpoint breakpoint = mockCloudLineBreakpoint(cloudDebugProcess, "mock error message", xBreakpoint); Icon icon = mock(Icon.class); when(breakpoint.getSetIcon(anyBoolean())).thenReturn(icon); cloudDebugProcess.updateBreakpointPresentation(breakpoint); verify(cloudDebugProcess, times(1)).getXBreakpoint(breakpoint); verify(breakpoint).getSetIcon(anyBoolean()); verify(breakpoint).getErrorMessage(); verify(breakpointManager).updateBreakpointPresentation(xBreakpoint, icon, "mock error message"); }
public void testCreateIdeRepresentationsIfNecessaryVerifiesNonFinalIdeBreakpoint() throws Exception { XLineBreakpointImpl breakpoint = registerMockBreakpoint( psiJavaFile, NO_WATCHES, NO_CONDITION, 13, "fileName", "packageName", false, "12abc"); CloudLineBreakpoint cloudLineBreakpoint = (CloudLineBreakpoint) breakpoint.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY); assertNotNull(cloudLineBreakpoint); Assert.assertFalse(cloudLineBreakpoint.isVerified()); handler.createIdeRepresentationsIfNecessary( Lists.newArrayList(new Breakpoint().setId("12abc"))); assertThat(cloudLineBreakpoint.getErrorMessage(), nullValue()); Assert.assertTrue(cloudLineBreakpoint.isVerified()); }
public boolean hasError() { return !Strings.isNullOrEmpty(getErrorMessage()); }
void updateBreakpointPresentation(CloudLineBreakpoint cloudLineBreakpoint) { final XBreakpointManager manager = getXBreakpointManager(getXDebugSession().getProject()); manager.updateBreakpointPresentation( getXBreakpoint(cloudLineBreakpoint), cloudLineBreakpoint.getSetIcon(areBreakpointsMuted()), cloudLineBreakpoint.getErrorMessage()); }