From bf49ad897f5a94e4b9b02c86637dc2954abca41b Mon Sep 17 00:00:00 2001 From: Patrick Huang Date: Thu, 5 Apr 2012 15:03:32 +1000 Subject: [PATCH] minor unit test --- .../table/TargetContentsPresenterTest.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/server/zanata-war/src/test/java/org/zanata/webtrans/client/editor/table/TargetContentsPresenterTest.java b/server/zanata-war/src/test/java/org/zanata/webtrans/client/editor/table/TargetContentsPresenterTest.java index fe18fab255..7a622745d0 100644 --- a/server/zanata-war/src/test/java/org/zanata/webtrans/client/editor/table/TargetContentsPresenterTest.java +++ b/server/zanata-war/src/test/java/org/zanata/webtrans/client/editor/table/TargetContentsPresenterTest.java @@ -207,16 +207,16 @@ public void canCopySource() @Test public void toggleViewIsDeferredExecuted() { - //given current display is at row 1 ArgumentCaptor commandCaptor = ArgumentCaptor.forClass(Scheduler.ScheduledCommand.class); when(editor.getIndex()).thenReturn(99); - presenter.showEditors(0, -1); + presenter.showEditors(0, TargetContentsPresenter.NO_OPEN_EDITOR); presenter.toggleView(editor); verify(scheduler).scheduleDeferred(commandCaptor.capture()); commandCaptor.getValue().execute(); -// verify(display1).openEditorAndCloseOthers(99); + + verify(display1).focusEditor(99); } @Test @@ -232,7 +232,7 @@ public void isDisplayButtonsReturnFromUserConfig() @Test public void canGetNewTargets() { - presenter.showEditors(1, -1); + presenter.showEditors(1, TargetContentsPresenter.NO_OPEN_EDITOR); when(display2.getNewTargets()).thenReturn(targetContents); ArrayList result = presenter.getNewTargets(); @@ -275,7 +275,7 @@ public void onRequestValidationWillNotFireRunValidationEventIfNotEditing() public void onRequestValidationWillFireRunValidationEventIfItsEditing() { //given current display is row 1 and current editor has target content - givenCurrentEditorAs(editor); + givenCurrentEditorsAs(editor); when(editor.getText()).thenReturn("target"); presenter.onRequestValidation(new RequestValidationEvent()); @@ -284,13 +284,11 @@ public void onRequestValidationWillFireRunValidationEventIfItsEditing() MatcherAssert.assertThat(runValidationEventCaptor.getValue().getTarget(), Matchers.equalTo("target")); } - private void givenCurrentEditorAs(ToggleEditor currentEditor) + private void givenCurrentEditorsAs(ToggleEditor... currentEditors) { - ArrayList mockedList = Mockito.mock(ArrayList.class); - when(display1.getEditors()).thenReturn(mockedList); - when(mockedList.get(anyInt())).thenReturn(currentEditor); + when(display1.getEditors()).thenReturn(Lists.newArrayList(currentEditors)); when(display1.isEditing()).thenReturn(true); - presenter.showEditors(0, -1); + presenter.showEditors(0, 0); } @Test @@ -304,8 +302,7 @@ public void canSaveAndMoveRow() @Test public void onCancelCanResetTextBack() { - when(display1.getEditors()).thenReturn(Lists.newArrayList(editor, editor2, editor3)); - presenter.showEditors(0, 1); + givenCurrentEditorsAs(editor, editor2, editor3); when(cellEditor.getTargetCell()).thenReturn(transUnit); when(transUnit.getTargets()).thenReturn(Lists.newArrayList("a", "b", "c")); when(editor.getIndex()).thenReturn(0); @@ -323,8 +320,7 @@ public void onCancelCanResetTextBack() @Test public void onCancelCanSetTextBackToNull() { - when(display1.getEditors()).thenReturn(Lists.newArrayList(editor, editor2, editor3)); - presenter.showEditors(0, 1); + givenCurrentEditorsAs(editor, editor2, editor3); when(cellEditor.getTargetCell()).thenReturn(transUnit); when(transUnit.getTargets()).thenReturn(null); @@ -340,7 +336,7 @@ public void onCancelCanSetTextBackToNull() public void testOnInsertString() { when(tableEditorMessages.notifyCopied()).thenReturn("copied"); - givenCurrentEditorAs(editor); + givenCurrentEditorsAs(editor); presenter.onInsertString(new InsertStringInEditorEvent("", "suggestion")); @@ -369,7 +365,7 @@ private T findEvent(ArgumentCaptor eventArgumentCaptor, Class c public void testOnTransMemoryCopy() { when(tableEditorMessages.notifyCopied()).thenReturn("copied"); - givenCurrentEditorAs(editor); + givenCurrentEditorsAs(editor); // TODO update for plurals presenter.onTransMemoryCopy(new CopyDataToEditorEvent(Arrays.asList("target")));