CellContextUtilities { public static void editSelectedCell(final GridWidget gridWidget) { editSelectedCell(gridWidget, null); }  static GridBodyCellEditContext makeCellRenderContext(final GridWidget gridWidget,
                                                                final BaseGridRendererHelper.RenderingInformation ri,
                                                                final BaseGridRendererHelper.ColumnInformation ci,
                                                                final int uiRowIndex); static GridBodyCellEditContext makeHeaderCellRenderContext(final GridWidget gridWidget,
                                                                      final BaseGridRendererHelper.RenderingInformation ri,
                                                                      final BaseGridRendererHelper.ColumnInformation ci,
                                                                      final int uiHeaderRowIndex); static GridBodyCellEditContext makeHeaderCellRenderContext(final GridWidget gridWidget,
                                                                      final BaseGridRendererHelper.RenderingInformation ri,
                                                                      final BaseGridRendererHelper.ColumnInformation ci,
                                                                      final Point2D rp,
                                                                      final int uiHeaderRowIndex); static void editSelectedCell(final GridWidget gridWidget); static void editSelectedCell(final GridWidget gridWidget,
                                        final Point2D relativeLocation);  }
@Test public void testEditWhenNoCellSelected() { final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class); final GridColumn<?> gridColumn = mockGridColumn(100.0, Arrays.asList(headerMetaData)); gridWidget.getModel().appendColumn(gridColumn); CellContextUtilities.editSelectedCell(gridWidget); verify(headerMetaData, never()).edit(any(GridBodyCellEditContext.class)); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
@Test public void testEditWhenHeaderCellSelected() { setupHeaderMetadata(); CellContextUtilities.editSelectedCell(gridWidget); verify(headerMetaDataC1, never()).edit(any(GridBodyCellEditContext.class)); verify(headerMetaDataC2).edit(gridBodyCellEditContextCaptor.capture()); final GridBodyCellEditContext gridBodyCellEditContext = gridBodyCellEditContextCaptor.getValue(); assertThat(gridBodyCellEditContext) .hasFieldOrPropertyWithValue("columnIndex", 1) .hasFieldOrPropertyWithValue("rowIndex", 0); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
@Test public void testEditWhenHeaderCellSelectedWithRelativeLocation() { setupHeaderMetadata(); final Point2D relativeLocation = new Point2D(25.0, 35.0); CellContextUtilities.editSelectedCell(gridWidget, relativeLocation); verify(headerMetaDataC1, never()).edit(any(GridBodyCellEditContext.class)); verify(headerMetaDataC2).edit(gridBodyCellEditContextCaptor.capture()); final GridBodyCellEditContext gridBodyCellEditContext = gridBodyCellEditContextCaptor.getValue(); assertThat(gridBodyCellEditContext) .hasFieldOrPropertyWithValue("columnIndex", 1) .hasFieldOrPropertyWithValue("rowIndex", 0) .hasFieldOrPropertyWithValue("relativeLocation", Optional.of(relativeLocation)); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
@Test public void testEditWhenDataCellSelectedSecondRow() { final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class); final GridColumn<?> gridColumn = mockGridColumn(100.0, Arrays.asList(headerMetaData)); doReturn(0).when(gridColumn).getIndex(); gridWidget.getModel().appendColumn(gridColumn); gridWidget.getModel().appendRow(row1); gridWidget.getModel().appendRow(row2); gridWidget.getModel().selectCell(1, 0); CellContextUtilities.editSelectedCell(gridWidget); verify(headerMetaData, never()).edit(any(GridBodyCellEditContext.class)); verify(gridWidget).startEditingCell(1, 0); }
@Test public void testEditWhenDataCellSelectedSecondColumn() { final GridColumn.HeaderMetaData headerMetaDataC1 = mock(GridColumn.HeaderMetaData.class); final GridColumn.HeaderMetaData headerMetaDataC2 = mock(GridColumn.HeaderMetaData.class); final GridColumn<?> gridColumnOne = mockGridColumn(100.0, Arrays.asList(headerMetaDataC1)); final GridColumn<?> gridColumnTwo = mockGridColumn(100.0, Arrays.asList(headerMetaDataC2)); doReturn(0).when(gridColumnOne).getIndex(); doReturn(1).when(gridColumnTwo).getIndex(); gridWidget.getModel().appendColumn(gridColumnOne); gridWidget.getModel().appendColumn(gridColumnTwo); gridWidget.getModel().appendRow(row1); gridWidget.getModel().selectCell(0, 1); CellContextUtilities.editSelectedCell(gridWidget); verify(headerMetaDataC1, never()).edit(any(GridBodyCellEditContext.class)); verify(headerMetaDataC2, never()).edit(any(GridBodyCellEditContext.class)); verify(gridWidget).startEditingCell(0, 1); }