verify(keyShortcutPresenter, times(3)).register(
keyShortcutCaptor.capture());
List<KeyShortcut> shortcuts = keyShortcutCaptor.getAllValues();
// testing keys
KeyShortcut docListKey = shortcuts.get(0);
KeyShortcut editorKey = shortcuts.get(1);
KeyShortcut searchKey = shortcuts.get(2);
// testing handlers
// doc key handler
HistoryToken docToken = new HistoryToken();
when(history.getHistoryToken()).thenReturn(docToken);
docListKey.getHandler().onKeyShortcut(null);
assertThat(docToken.getView(), Matchers.is(MainView.Documents));
verify(history).newItem(docToken.toTokenString());
// editor key handler on selected doc is null
when(messages.noDocumentSelected()).thenReturn("no doc selected");
editorKey.getHandler().onKeyShortcut(null);
verify(eventBus).fireEvent(isA(NotificationEvent.class));
// editor key handler on selected doc is NOT null
HistoryToken editorToken = new HistoryToken();
when(history.getHistoryToken()).thenReturn(editorToken);
DocumentInfo selectedDocument = mock(DocumentInfo.class);
presenter.setStatesForTest(null, null, MainView.Documents,
selectedDocument);
editorKey.getHandler().onKeyShortcut(null);
assertThat(editorToken.getView(), Matchers.is(MainView.Editor));
verify(history).newItem(editorToken.toTokenString());
// search key handler
HistoryToken searchToken = new HistoryToken();
when(history.getHistoryToken()).thenReturn(searchToken);
searchKey.getHandler().onKeyShortcut(null);
assertThat(searchToken.getView(), Matchers.is(MainView.Search));
verify(history).newItem(searchToken.toTokenString());
}