BaseKeyboardOperation implements KeyboardOperation { protected GridData.SelectedCell getSelectedCellOrigin(final GridData gridModel, final boolean isHeaderCellSelected) { if (isHeaderCellSelected) { List<GridData.SelectedCell> selectedHeaderCells = gridModel.getSelectedHeaderCells(); if (KEY_RIGHT == getKeyCode()) { return selectedHeaderCells.get(selectedHeaderCells.size() - 1); } else { return selectedHeaderCells.get(0); } } else { return gridModel.getSelectedCellsOrigin(); } } BaseKeyboardOperation(final GridLayer gridLayer); @Override TriStateBoolean isShiftKeyDown(); @Override TriStateBoolean isControlKeyDown(); @Override boolean isExecutable(final GridWidget gridWidget);  }
@Test public void getSelectedCellOrigin_NotHeaderCell() { when(gridData.getSelectedCellsOrigin()).thenReturn(new GridData.SelectedCell(0, 0)); baseKeyboardOperationSpy.getSelectedCellOrigin(gridData, false); verify(gridData, times(1)).getSelectedCellsOrigin(); verify(gridData, never()).getSelectedHeaderCells(); }
@Test public void getSelectedCellOrigin_SingleHeaderCell_KeyRight() { currentKeyCode = KEY_RIGHT; GridData.SelectedCell headerCell = new GridData.SelectedCell(0, 0); when(gridData.getSelectedHeaderCells()).thenReturn(Collections.singletonList(headerCell)); assertEquals(headerCell, baseKeyboardOperationSpy.getSelectedCellOrigin(gridData, true)); verify(gridData, times(1)).getSelectedHeaderCells(); verify(gridData, never()).getSelectedCellsOrigin(); }
@Test public void getSelectedCellOrigin_SingleHeaderCell_KeyLeft() { currentKeyCode = KEY_LEFT; GridData.SelectedCell headerCell = new GridData.SelectedCell(0, 0); when(gridData.getSelectedHeaderCells()).thenReturn(Collections.singletonList(headerCell)); assertEquals(headerCell, baseKeyboardOperationSpy.getSelectedCellOrigin(gridData, true)); verify(gridData, times(1)).getSelectedHeaderCells(); verify(gridData, never()).getSelectedCellsOrigin(); }
@Test public void getSelectedCellOrigin_MultipleHeaderCell_KeyRight() { currentKeyCode = KEY_RIGHT; GridData.SelectedCell headerCell = new GridData.SelectedCell(0, 0); GridData.SelectedCell headerCell2 = new GridData.SelectedCell(0, 1); when(gridData.getSelectedHeaderCells()).thenReturn(Arrays.asList(headerCell, headerCell2)); assertEquals(headerCell2, baseKeyboardOperationSpy.getSelectedCellOrigin(gridData, true)); verify(gridData, times(1)).getSelectedHeaderCells(); verify(gridData, never()).getSelectedCellsOrigin(); }
@Test public void getSelectedCellOrigin_MultipleHeaderCell_KeyLeft() { currentKeyCode = KEY_LEFT; GridData.SelectedCell headerCell = new GridData.SelectedCell(0, 0); GridData.SelectedCell headerCell2 = new GridData.SelectedCell(0, 1); when(gridData.getSelectedHeaderCells()).thenReturn(Arrays.asList(headerCell, headerCell2)); assertEquals(headerCell, baseKeyboardOperationSpy.getSelectedCellOrigin(gridData, true)); verify(gridData, times(1)).getSelectedHeaderCells(); verify(gridData, never()).getSelectedCellsOrigin(); }