Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
minor unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Apr 5, 2012
1 parent 9b811c1 commit bf49ad8
Showing 1 changed file with 12 additions and 16 deletions.
Expand Up @@ -207,16 +207,16 @@ public void canCopySource()
@Test
public void toggleViewIsDeferredExecuted()
{
//given current display is at row 1
ArgumentCaptor<Scheduler.ScheduledCommand> 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
Expand All @@ -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<String> result = presenter.getNewTargets();
Expand Down Expand Up @@ -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());
Expand All @@ -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<ToggleEditor> 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
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -340,7 +336,7 @@ public void onCancelCanSetTextBackToNull()
public void testOnInsertString()
{
when(tableEditorMessages.notifyCopied()).thenReturn("copied");
givenCurrentEditorAs(editor);
givenCurrentEditorsAs(editor);

presenter.onInsertString(new InsertStringInEditorEvent("", "suggestion"));

Expand Down Expand Up @@ -369,7 +365,7 @@ private <T> T findEvent(ArgumentCaptor<GwtEvent> eventArgumentCaptor, Class<T> c
public void testOnTransMemoryCopy()
{
when(tableEditorMessages.notifyCopied()).thenReturn("copied");
givenCurrentEditorAs(editor);
givenCurrentEditorsAs(editor);

// TODO update for plurals
presenter.onTransMemoryCopy(new CopyDataToEditorEvent(Arrays.asList("target")));
Expand Down

0 comments on commit bf49ad8

Please sign in to comment.