@Test public void hasNoClipboardContents() { when(clipboardHistory.hasContents()).thenReturn(false); action.performAction(nodes); verifyZeroInteractions(clipboard, dialogDisplayer); }
@Test public void hasClipboardContentsAndUserCancels() { when(clipboardHistory.hasContents()).thenReturn(true); when(dialogDisplayer.display(clipboardHistory)).thenReturn(-1); action.performAction(nodes); verifyZeroInteractions(clipboard); }
@Before public void init() { dialogDisplayer = mock(HistoryDialogDisplayer.class); clipboardHistory = mock(ClipboardHistory.class); clipboard = mock(ExClipboard.class); editorPane = new JEditorPane(); actionMap = mock(ActionMap.class); pasteAction = mock(Action.class); editorCookieUtil = mock(EditorCookieUtil.class); action = new PasteFromHistoryAction(); action.setHistoryDialogDisplayer(dialogDisplayer); action.setClipboardHistory(clipboardHistory); action.setClipboard(clipboard); action.setEditorCookieUtil(editorCookieUtil); when(editorCookieUtil.editor(nodes)).thenReturn(editorPane); editorPane.setActionMap(actionMap); }
@Test public void hasClipboardContentsAndUserSelectsSomethingToPaste() { InOrder inOrder = inOrder(clipboardHistory, clipboard, pasteAction); when(clipboardHistory.hasContents()).thenReturn(true); when(dialogDisplayer.display(clipboardHistory)).thenReturn(1); when(clipboardHistory.top()).thenReturn("value"); when(actionMap.get("paste")).thenReturn(pasteAction); action.performAction(nodes); inOrder.verify(clipboardHistory).moveToTop(1); inOrder.verify(clipboard).setContents(isA(StringSelection.class), isA(StringSelection.class)); inOrder.verify(pasteAction).actionPerformed(isA(ActionEvent.class)); }