/** * This is fired when the set of breakpoints from the server changes. We create a new table model * while keeping the selection as it was. Most routines on selection are therefore based on the * breakpoint Id and not a reference to a breakpoint object -- because we never know when the * server instance will get replaced. */ private void onBreakpointsChanged() { // Read the list of breakpoints and show them. // We always snap the current breakpoint list into a local to eliminate threading issues. final List<Breakpoint> breakpointList = process.getCurrentBreakpointList(); // Setting the model must happen on the UI thread, while most of this method executes on the // background. SwingUtilities.invokeLater(new ModelSetter(breakpointList, getSelection())); }
@Override public void run() { getBreakpointHandler().createIdeRepresentationsIfNecessary(getCurrentBreakpointList()); } });
@VisibleForTesting int getSelection() { final List<Breakpoint> breakpointList = process.getCurrentBreakpointList(); int selection = -1; if (breakpointList != null) { for (int i = 0; i < breakpointList.size(); i++) { Breakpoint snapshot = process.getCurrentSnapshot(); if (snapshot != null && breakpointList.get(i).getId().equals(snapshot.getId())) { selection = i; break; } } } return selection; }
private void runModelSetter(CloudDebugHistoricalSnapshots snapshots) { snapshots.new ModelSetter(mockProcess.getCurrentBreakpointList(), snapshots.getSelection()) .run(); }
public void onBreakpointListChanged(CloudDebugProcessState state) { final List<Breakpoint> currentList = getCurrentBreakpointList(); if (currentList != null) { SwingUtilities.invokeLater(
@Test public void testOnBreakpointListChanged() throws InterruptedException { CloudDebugHistoricalSnapshots snapshots = new CloudDebugHistoricalSnapshots(handler); Breakpoint bp1 = new Breakpoint(); bp1.setId("an ID"); bp1.setFinalTime("2015-08-22T05:23:34.123Z"); bp1.setIsFinalState(true); SourceLocation location = new SourceLocation(); location.setPath("foo/bar/baz"); location.setLine(12); bp1.setLocation(location); List<Breakpoint> breakpoints = new ArrayList<Breakpoint>(); breakpoints.add(bp1); Mockito.when(mockProcess.getCurrentBreakpointList()).thenReturn(breakpoints); Mockito.when(mockProcess.getCurrentSnapshot()).thenReturn(bp1); CloudBreakpointHandler breakpointHandler = Mockito.mock(CloudBreakpointHandler.class); Mockito.when(mockProcess.getBreakpointHandler()).thenReturn(breakpointHandler); runModelSetter(snapshots); Assert.assertEquals(0, snapshots.table.getSelectedRow()); }
Mockito.when(mockProcess.getCurrentBreakpointList()).thenReturn(breakpoints1); Mockito.when(mockProcess.getCurrentSnapshot()).thenReturn(bp1); runModelSetter(snapshots); Mockito.when(mockProcess.getCurrentBreakpointList()).thenReturn(breakpoints2); Mockito.when(mockProcess.getCurrentSnapshot()).thenReturn(bp2); runModelSetter(snapshots);