KeyboardOperationInvokeContextMenuForSelectedCell extends BaseKeyboardOperation { @Override @SuppressWarnings("unused") public boolean perform(final GridWidget gridWidget, final boolean isShiftKeyDown, final boolean isControlKeyDown) { final GridData model = gridWidget.getModel(); if (model.getSelectedHeaderCells().size() > 0) { return performHeaderOperation(gridWidget); } else if (model.getSelectedCells().size() > 0) { return performBodyOperation(gridWidget); } return false; } KeyboardOperationInvokeContextMenuForSelectedCell(final GridLayer gridLayer); @Override TriStateBoolean isControlKeyDown(); @Override int getKeyCode(); @Override boolean isExecutable(final GridWidget gridWidget); @Override @SuppressWarnings("unused") boolean perform(final GridWidget gridWidget,
                           final boolean isShiftKeyDown,
                           final boolean isControlKeyDown);  }
@Test public void testPerformWithSelectedHeader() { final int headerRowIndex = 1; final int headerColumnIndex = 2; final int uiColumnIndex = 0; final GridData.SelectedCell selectedCellMock = mock(GridData.SelectedCell.class); doReturn(Collections.singletonList(selectedCellMock)).when(gridDataMock).getSelectedHeaderCells(); doReturn(headerRowIndex).when(selectedCellMock).getRowIndex(); doReturn(headerColumnIndex).when(selectedCellMock).getColumnIndex(); final GridColumn columnMock = mock(GridColumn.class); doReturn(headerColumnIndex).when(columnMock).getIndex(); doReturn(Collections.singletonList(columnMock)).when(gridDataMock).getColumns(); doReturn(true).when(gridWidgetMock).showContextMenuForHeader(headerRowIndex, uiColumnIndex); assertThat(testedOperation.perform(gridWidgetMock, false, true)) .as("Menu should be shown successfully") .isTrue(); verify(gridWidgetMock).showContextMenuForHeader(headerRowIndex, uiColumnIndex); }
@Test public void testPerformWithSelectedCell() { final int rowIndex = 1; final int columnIndex = 2; final int uiColumnIndex = 0; final GridData.SelectedCell selectedCellMock = mock(GridData.SelectedCell.class); doReturn(Collections.singletonList(selectedCellMock)).when(gridDataMock).getSelectedCells(); doReturn(rowIndex).when(selectedCellMock).getRowIndex(); doReturn(columnIndex).when(selectedCellMock).getColumnIndex(); final GridColumn columnMock = mock(GridColumn.class); doReturn(columnIndex).when(columnMock).getIndex(); doReturn(Collections.singletonList(columnMock)).when(gridDataMock).getColumns(); doReturn(selectedCellMock).when(gridDataMock).getSelectedCellsOrigin(); doReturn(true).when(gridWidgetMock).showContextMenuForCell(rowIndex, uiColumnIndex); assertThat(testedOperation.perform(gridWidgetMock, false, true)) .as("Menu should be shown successfully") .isTrue(); verify(gridWidgetMock).showContextMenuForCell(rowIndex, uiColumnIndex); }
@Test public void testPerformNothingSelected() { final int rowIndex = 1; final int columnIndex = 2; final int uiColumnIndex = 0; final GridData.SelectedCell selectedCellMock = mock(GridData.SelectedCell.class); doReturn(rowIndex).when(selectedCellMock).getRowIndex(); doReturn(columnIndex).when(selectedCellMock).getColumnIndex(); final GridColumn columnMock = mock(GridColumn.class); doReturn(columnIndex).when(columnMock).getIndex(); doReturn(Collections.singletonList(columnMock)).when(gridDataMock).getColumns(); doReturn(null).when(gridDataMock).getSelectedCellsOrigin(); doReturn(true).when(gridWidgetMock).showContextMenuForCell(rowIndex, uiColumnIndex); assertThat(testedOperation.perform(gridWidgetMock, false, true)) .as("Menu should not be shown successfully") .isFalse(); verify(gridWidgetMock, never()).showContextMenuForCell(anyInt(), anyInt()); }