public void willDetectSaveDoneByAnotherUserAndCurrentUserHasUnsavedChange() {
// Given: coming client id is NOT current user
EditorClientId currentUser = new EditorClientId("session1", 1);
when(translatorService.getCurrentEditorClientId()).thenReturn(
currentUser);
TransUnit updatedTransUnit = TestFixture.makeTransUnit(1);
presenter.setStateForTesting(updatedTransUnit.getId());
when(messages.concurrentEdit()).thenReturn("concurrent edit detected");
when(messages.concurrentEditTitle()).thenReturn(
"please resolve conflict");
// current user does not have unsaved change
when(targetContentsPresenter.currentEditorContentHasChanged())
.thenReturn(true);
// When: update type is save
presenter.refreshRow(updatedTransUnit,
new EditorClientId("session2", 2),
TransUnitUpdated.UpdateType.WebEditorSave);
// Then:
ArgumentCaptor<NotificationEvent> eventCaptor =
ArgumentCaptor.forClass(NotificationEvent.class);
verify(eventBus).fireEvent(eventCaptor.capture());
assertThat(eventCaptor.getValue().getMessage(),
Matchers.equalTo("concurrent edit detected"));
ArgumentCaptor<TransHistoryItem> transHistoryCaptor =
ArgumentCaptor.forClass(TransHistoryItem.class);
InOrder inOrder =
Mockito.inOrder(targetContentsPresenter,
translationHistoryPresenter);
inOrder.verify(translationHistoryPresenter).popupAndShowLoading(
"please resolve conflict");
inOrder.verify(translationHistoryPresenter).displayEntries(
transHistoryCaptor.capture(),
eq(Collections.<TransHistoryItem> emptyList()),
eq(Collections.<ReviewComment> emptyList()));
assertThat(transHistoryCaptor.getValue().getVersionNum(),
Matchers.equalTo(updatedTransUnit.getVerNum().toString()));
assertThat(transHistoryCaptor.getValue().getContents(),
Matchers.equalTo(updatedTransUnit.getTargets()));
inOrder.verify(targetContentsPresenter).updateRow(updatedTransUnit);
}