This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
/
AppPresenterTest.java
619 lines (526 loc) · 24.5 KB
/
AppPresenterTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
package org.zanata.webtrans.client.presenter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.PresenterRevealedEvent;
import org.hamcrest.Matchers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.zanata.common.LocaleId;
import org.zanata.common.ProjectType;
import org.zanata.common.TransUnitCount;
import org.zanata.common.TransUnitWords;
import org.zanata.model.TestFixture;
import org.zanata.rest.dto.stats.ContainerTranslationStatistics;
import org.zanata.rest.dto.stats.TranslationStatistics;
import org.zanata.webtrans.client.events.DocumentStatsUpdatedEvent;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.ProjectStatsUpdatedEvent;
import org.zanata.webtrans.client.events.ShowSideMenuEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.history.History;
import org.zanata.webtrans.client.history.HistoryToken;
import org.zanata.webtrans.client.history.Window;
import org.zanata.webtrans.client.keys.KeyShortcut;
import org.zanata.webtrans.client.keys.Keys;
import org.zanata.webtrans.client.keys.ShortcutContext;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.view.AppDisplay;
import org.zanata.webtrans.shared.model.AuditInfo;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.DocumentInfo;
import org.zanata.webtrans.shared.model.UserWorkspaceContext;
import org.zanata.webtrans.shared.model.ValidationAction.State;
import org.zanata.webtrans.shared.model.ValidationId;
import org.zanata.webtrans.shared.model.WorkspaceId;
import org.zanata.webtrans.shared.rpc.HasWorkspaceContextUpdateData;
@Test(groups = { "unit-tests" })
public class AppPresenterTest {
private AppPresenter presenter;
@Mock
private AppDisplay display;
@Mock
private EventBus eventBus;
@Mock
private SideMenuPresenter sideMenuPresenter;
@Mock
private AttentionKeyShortcutPresenter attentionKeyShortcutPresenter;
@Mock
private KeyShortcutPresenter keyShortcutPresenter;
@Mock
private TranslationPresenter translationPresenter;
@Mock
private DocumentListPresenter documentListPresenter;
@Mock
private SearchResultsPresenter searchResultPresenter;
private UserWorkspaceContext userWorkspace = TestFixture
.userWorkspaceContext();
@Mock
private WebTransMessages messages;
@Mock
private History history;
@Mock
private Window window;
@Mock
private Window.Location location;
@Captor
private ArgumentCaptor<ContainerTranslationStatistics> statsCaptor;
private ContainerTranslationStatistics projectStats;
private ContainerTranslationStatistics selectedDocumentStats;
@Captor
private ArgumentCaptor<KeyShortcut> keyShortcutCaptor;
@BeforeMethod
public void beforeMethod() {
selectedDocumentStats = new ContainerTranslationStatistics();
selectedDocumentStats.addStats(new TranslationStatistics(
new TransUnitCount(1, 2, 3), LocaleId.EN_US.getId()));
selectedDocumentStats.addStats(new TranslationStatistics(
new TransUnitWords(4, 5, 6), LocaleId.EN_US.getId()));
projectStats = new ContainerTranslationStatistics();
projectStats.addStats(new TranslationStatistics(new TransUnitCount(7,
8, 9), LocaleId.EN_US.getId()));
projectStats.addStats(new TranslationStatistics(new TransUnitWords(10,
11, 12), LocaleId.EN_US.getId()));
MockitoAnnotations.initMocks(this);
presenter =
new AppPresenter(display, eventBus, sideMenuPresenter,
attentionKeyShortcutPresenter, keyShortcutPresenter,
translationPresenter, documentListPresenter,
searchResultPresenter, userWorkspace, messages,
history, window, location);
verify(display).setListener(presenter);
}
@Test
public void onBind() {
when(location.getParameter("title")).thenReturn("blah");
when(
messages.windowTitle2(userWorkspace.getWorkspaceContext()
.getWorkspaceName(), userWorkspace
.getWorkspaceContext().getLocaleName(), "blah"))
.thenReturn("new title");
presenter.onBind();
verify(keyShortcutPresenter).bind();
verify(documentListPresenter).bind();
verify(translationPresenter).bind();
verify(searchResultPresenter).bind();
verify(sideMenuPresenter).bind();
verify(eventBus).addHandler(ShowSideMenuEvent.getType(), presenter);
verify(eventBus).addHandler(WorkspaceContextUpdateEvent.getType(),
presenter);
verify(eventBus).addHandler(DocumentStatsUpdatedEvent.getType(),
presenter);
verify(eventBus)
.addHandler(PresenterRevealedEvent.getType(), presenter);
verify(eventBus).addHandler(ProjectStatsUpdatedEvent.getType(),
presenter);
WorkspaceId workspaceId =
userWorkspace.getWorkspaceContext().getWorkspaceId();
String localeId = workspaceId.getLocaleId().getId();
verify(display).setProjectLinkLabel(
workspaceId.getProjectIterationId().getProjectSlug());
verify(display).setVersionLinkLabel(
workspaceId.getProjectIterationId().getIterationSlug());
verify(display).setFilesLinkLabel("Documents (" + localeId + ")");
verify(display).setReadOnlyVisible(userWorkspace.hasReadOnlyAccess());
verify(window).setTitle("new title");
verify(keyShortcutPresenter, times(3)).register(
keyShortcutCaptor.capture());
}
@Test
public void testKeyShortcutsKeys() {
when(location.getParameter("title")).thenReturn(null);
when(
messages.windowTitle(userWorkspace.getWorkspaceContext()
.getWorkspaceName(), userWorkspace
.getWorkspaceContext().getLocaleName())).thenReturn(
"title");
when(messages.showDocumentListKeyShortcut()).thenReturn("doc list");
when(messages.showEditorKeyShortcut()).thenReturn("editor");
when(messages.showProjectWideSearch())
.thenReturn("project wide search");
presenter.onBind();
verify(window).setTitle("title");
verify(keyShortcutPresenter, times(3)).register(
keyShortcutCaptor.capture());
List<KeyShortcut> shortcuts = keyShortcutCaptor.getAllValues();
// testing keys
KeyShortcut docListKey = shortcuts.get(0);
assertThat(docListKey.getAllKeys(),
Matchers.contains(new Keys(Keys.ALT_KEY, 'L')));
assertThat(docListKey.getDescription(), Matchers.equalTo("doc list"));
assertThat(docListKey.getContext(),
Matchers.equalTo(ShortcutContext.Application));
KeyShortcut editorKey = shortcuts.get(1);
assertThat(editorKey.getAllKeys(),
Matchers.contains(new Keys(Keys.ALT_KEY, 'O')));
assertThat(editorKey.getDescription(), Matchers.equalTo("editor"));
assertThat(editorKey.getContext(),
Matchers.equalTo(ShortcutContext.Application));
KeyShortcut searchKey = shortcuts.get(2);
assertThat(searchKey.getAllKeys(),
Matchers.contains(new Keys(Keys.ALT_KEY, 'P')));
assertThat(searchKey.getDescription(),
Matchers.equalTo("project wide search"));
assertThat(searchKey.getContext(),
Matchers.equalTo(ShortcutContext.Application));
}
@Test
public void testKeyShortcutHandlers() {
when(messages.showDocumentListKeyShortcut()).thenReturn("doc list");
when(messages.showEditorKeyShortcut()).thenReturn("editor");
when(messages.showProjectWideSearch())
.thenReturn("project wide search");
presenter.onBind();
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());
}
@Test
public void onShowSideMenu() {
presenter.onShowSideMenu(new ShowSideMenuEvent(true));
verify(display).showSideMenu(true);
presenter.onShowSideMenu(new ShowSideMenuEvent(false));
verify(display).showSideMenu(false);
}
@Test
public void onWorkspaceContextUpdateToReadOnly() {
when(messages.notifyReadOnlyWorkspace()).thenReturn(
"readonly workspace");
ArgumentCaptor<NotificationEvent> eventCaptor =
ArgumentCaptor.forClass(NotificationEvent.class);
presenter.onWorkspaceContextUpdated(new WorkspaceContextUpdateEvent(
contextUpdateData(false, ProjectType.Podir)));
verify(eventBus).fireEvent(eventCaptor.capture());
NotificationEvent event = eventCaptor.getValue();
assertThat(event.getMessage(), Matchers.equalTo("readonly workspace"));
verify(display).setReadOnlyVisible(userWorkspace.hasReadOnlyAccess());
}
@Test
public void onWorkspaceContextUpdateToEditable() {
when(messages.notifyEditableWorkspace()).thenReturn(
"editable workspace");
ArgumentCaptor<NotificationEvent> eventCaptor =
ArgumentCaptor.forClass(NotificationEvent.class);
presenter.onWorkspaceContextUpdated(new WorkspaceContextUpdateEvent(
contextUpdateData(true, ProjectType.Podir)));
verify(eventBus).fireEvent(eventCaptor.capture());
NotificationEvent event = eventCaptor.getValue();
assertThat(event.getMessage(), Matchers.equalTo("editable workspace"));
verify(display).setReadOnlyVisible(userWorkspace.hasReadOnlyAccess());
}
@Test
public void canSwitchToEditorView() {
// Given:
presenter.setStatesForTest(projectStats, selectedDocumentStats, null,
null);
// When:
presenter.showView(MainView.Editor);
// Then:
verify(translationPresenter).revealDisplay();
verify(searchResultPresenter).concealDisplay();
verify(sideMenuPresenter).setOptionMenu(MainView.Editor);
verify(display).showInMainView(MainView.Editor);
verify(display).setStats(statsCaptor.capture(), eq(true));
assertThat(statsCaptor.getValue(),
Matchers.sameInstance(selectedDocumentStats));
}
@Test
public void canSwitchToSearchView() {
// Given: current view is editor
when(messages.projectWideSearchAndReplace()).thenReturn(
"search and replace");
presenter.setStatesForTest(projectStats, selectedDocumentStats,
MainView.Editor, null);
// When:
presenter.showView(MainView.Search);
// Then:
verify(translationPresenter).saveEditorPendingChange();
verify(display).setDocumentLabel("", "search and replace");
verify(translationPresenter).concealDisplay();
verify(searchResultPresenter).revealDisplay();
verify(sideMenuPresenter).setOptionMenu(MainView.Search);
verify(display).showInMainView(MainView.Search);
verify(display).setStats(statsCaptor.capture(), eq(true));
assertThat(statsCaptor.getValue(), Matchers.sameInstance(projectStats));
}
@Test
public void canSwitchToDocumentView() {
// Given: current selected document is null
assertThat(presenter.getSelectedDocIdOrNull(),
Matchers.is(Matchers.nullValue()));
assertThat(presenter.getSelectedDocumentInfoOrNull(),
Matchers.is(Matchers.nullValue()));
when(messages.documentListTitle()).thenReturn("Documents");
presenter.setStatesForTest(projectStats, selectedDocumentStats, null,
null);
// When:
presenter.showView(MainView.Documents);
// Then:
verify(display).setDocumentLabel("", "Documents");
verify(translationPresenter).concealDisplay();
verify(searchResultPresenter).concealDisplay();
verify(sideMenuPresenter).setOptionMenu(MainView.Documents);
verify(display).showInMainView(MainView.Documents);
verify(display).setStats(statsCaptor.capture(), eq(true));
assertThat(statsCaptor.getValue(), Matchers.sameInstance(projectStats));
}
@Test
public void canSelectDocumentInEditorView() {
// Given:
presenter.setStatesForTest(projectStats, selectedDocumentStats, null,
null);
DocumentId docId = new DocumentId(1L, "");
// newly selected document has new stats
ContainerTranslationStatistics newSelectedStats =
new ContainerTranslationStatistics();
newSelectedStats.addStats(new TranslationStatistics(new TransUnitCount(
1, 2, 3), LocaleId.EN_US.toString()));
newSelectedStats.addStats(new TranslationStatistics(new TransUnitWords(
4, 5, 6), LocaleId.EN_US.toString()));
DocumentInfo documentInfo =
new DocumentInfo(docId, "a.po", "pot/", new LocaleId("en-US"),
newSelectedStats, new AuditInfo(new Date(),
"Translator"), new HashMap<String, String>(),
new AuditInfo(new Date(), "last translator"));
when(documentListPresenter.getDocumentInfo(docId)).thenReturn(
documentInfo);
// current view is editor
presenter.showView(MainView.Editor);
verify(display).setStats(statsCaptor.capture(), eq(true));
assertThat(statsCaptor.getValue(),
Matchers.sameInstance(selectedDocumentStats));
// When:
presenter.selectDocument(docId);
// Then:
display.setDocumentLabel("pot/", "a.po");
verify(display, atLeastOnce()).setStats(selectedDocumentStats, true);
assertThat(selectedDocumentStats.getStats(),
Matchers.equalTo(newSelectedStats.getStats()));
assertThat(presenter.getSelectedDocIdOrNull(), Matchers.is(docId));
}
@Test
public void canSelectDocumentNotInEditorView() {
// Given:
presenter.setStatesForTest(projectStats, selectedDocumentStats,
MainView.Documents, null);
DocumentId docId = new DocumentId(1L, "");
// newly selected document has new stats
ContainerTranslationStatistics newSelectedStats =
new ContainerTranslationStatistics();
newSelectedStats.addStats(new TranslationStatistics(new TransUnitCount(
1, 2, 3), LocaleId.EN_US.toString()));
newSelectedStats.addStats(new TranslationStatistics(new TransUnitWords(
4, 5, 6), LocaleId.EN_US.toString()));
DocumentInfo documentInfo =
new DocumentInfo(docId, "a.po", "pot/", new LocaleId("en-US"),
newSelectedStats, new AuditInfo(new Date(),
"Translator"), new HashMap<String, String>(),
new AuditInfo(new Date(), "last translator"));
when(documentListPresenter.getDocumentInfo(docId)).thenReturn(
documentInfo);
// When:
presenter.selectDocument(docId);
// Then:
verify(display).enableTab(MainView.Editor, true);
verifyNoMoreInteractions(display);
assertThat(presenter.getSelectedDocIdOrNull(), Matchers.is(docId));
assertThat(presenter.getSelectedDocumentInfoOrNull(),
Matchers.is(documentInfo));
}
@Test
public void onDocumentStatsUpdateWillDoNothingIfNoSelectedDocument() {
assertThat(presenter.getSelectedDocumentInfoOrNull(),
Matchers.is(Matchers.nullValue()));
presenter.onDocumentStatsUpdated(new DocumentStatsUpdatedEvent(
new DocumentId(1L, ""), new ContainerTranslationStatistics()));
verifyZeroInteractions(display);
}
@Test
public void onDocumentStatsUpdateWillDoNothingIsDifferentDocument() {
// Given: current view is null and selected doc id 2
presenter.setStatesForTest(projectStats, selectedDocumentStats, null,
null);
presenter.selectDocument(new DocumentId(2L, ""));
// When:
presenter.onDocumentStatsUpdated(new DocumentStatsUpdatedEvent(
new DocumentId(1L, ""), new ContainerTranslationStatistics()));
// Then:
verifyZeroInteractions(display);
}
@Test
public void onDocumentStatsUpdateWillSetStatsIfSameDocument() {
// Given: current view is Editor and selected doc id 1
presenter.setStatesForTest(projectStats, selectedDocumentStats, null,
null);
presenter.showView(MainView.Editor);
DocumentId docId = new DocumentId(1L, "");
DocumentInfo documentInfo =
new DocumentInfo(docId, "a.po", "pot/", new LocaleId("en-US"),
selectedDocumentStats, new AuditInfo(new Date(),
"Translator"), new HashMap<String, String>(),
new AuditInfo(new Date(), "last translator"));
when(documentListPresenter.getDocumentInfo(docId)).thenReturn(
documentInfo);
presenter.selectDocument(docId);
verify(display, atLeastOnce()).setStats(selectedDocumentStats, true);
// When:
ContainerTranslationStatistics newStats =
new ContainerTranslationStatistics();
newStats.addStats(new TranslationStatistics(
new TransUnitCount(9, 9, 9), LocaleId.EN_US.toString()));
newStats.addStats(new TranslationStatistics(
new TransUnitWords(8, 8, 8), LocaleId.EN_US.toString()));
presenter.onDocumentStatsUpdated(new DocumentStatsUpdatedEvent(docId,
newStats));
// Then:
assertThat(selectedDocumentStats.getStats(),
Matchers.equalTo(newStats.getStats()));
verify(display, atLeastOnce()).setStats(selectedDocumentStats, true);
}
@Test
public void onSearchAndReplaceClick() {
when(history.getToken()).thenReturn("view:doc;doc:blah");
presenter.onSearchAndReplaceClicked();
verify(history).newItem("view:search;doc:blah");
}
@Test
public void onDocumentsClickWillDoNothingIfNoSelectedDocument() {
when(history.getToken()).thenReturn("doc:blah");
presenter.onDocumentListClicked();
verify(history).getToken();
verifyNoMoreInteractions(history);
}
@Test
public void onDocumentsClickWillFireNewHistoryItemAndSwitchToDocumentView() {
// Given: current token is search view and has selected doc
DocumentId docId = new DocumentId(1L, "");
DocumentInfo documentInfo =
new DocumentInfo(docId, "a.po", "pot/", new LocaleId("en-US"),
selectedDocumentStats, new AuditInfo(new Date(),
"Translator"), new HashMap<String, String>(),
new AuditInfo(new Date(), "last translator"));
when(documentListPresenter.getDocumentInfo(docId)).thenReturn(
documentInfo);
when(history.getToken()).thenReturn("view:search;doc:pot/a.po");
presenter.selectDocument(docId);
// When:
presenter.onDocumentListClicked();
// Then:
verify(history).getToken();
verify(history).newItem("doc:pot/a.po");
verifyNoMoreInteractions(history);
}
@Test
public void onEditorClickAndSelectedDocumentIsNull() {
presenter.onEditorClicked();
verifyNoMoreInteractions(history);
}
@Test
public void onEditorClickAndHasSelectedDocument() {
DocumentInfo selectedDocument = mock(DocumentInfo.class);
presenter.setStatesForTest(null, null, null, selectedDocument);
when(history.getToken()).thenReturn("view:search");
presenter.onEditorClicked();
verify(history).newItem("view:doc");
}
@Test
public void onEditorClickAndHasSelectedDocumentButAlreadyInEditorView() {
DocumentInfo selectedDocument = mock(DocumentInfo.class);
presenter.setStatesForTest(null, null, null, selectedDocument);
when(history.getToken()).thenReturn("view:doc");
presenter.onEditorClicked();
verify(history).getToken();
verifyNoMoreInteractions(history);
}
@Test
public void onKeyShortcutClick() {
presenter.onKeyShortcutsClicked();
verify(keyShortcutPresenter).showShortcuts();
}
@Test
public void onProjectStatsUpdated() {
projectStats = new ContainerTranslationStatistics();
ContainerTranslationStatistics newStats =
new ContainerTranslationStatistics();
TranslationStatistics unitStats =
new TranslationStatistics(new TransUnitCount(7, 8, 9),
LocaleId.EN_US.getId());
TranslationStatistics wordStats =
new TranslationStatistics(new TransUnitWords(10, 11, 12),
LocaleId.EN_US.getId());
newStats.addStats(unitStats);
newStats.addStats(wordStats);
presenter.setStatesForTest(projectStats, selectedDocumentStats, null,
null);
presenter.showView(MainView.Documents);
ProjectStatsUpdatedEvent event = new ProjectStatsUpdatedEvent(newStats);
presenter.onProjectStatsUpdated(event);
assertThat("project stats should contains stats in the event",
projectStats.getStats().size(), is(2));
verify(display, times(2)).setStats(projectStats, true);
}
private static HasWorkspaceContextUpdateData contextUpdateData(
final boolean projectActive, final ProjectType projectType) {
return new HasWorkspaceContextUpdateData() {
@Override
public boolean isProjectActive() {
return projectActive;
}
@Override
public ProjectType getProjectType() {
return projectType;
}
@Override
public Map<ValidationId, State> getValidationStates() {
return null;
}
};
}
}