public void testSetQueryReturnsNumberOfMatches() {
Document document = createDocument();
AppContext mockContext = createMockContext();
ViewportModel mockView = createMockViewport(document, 4);
StubMatchManager mockMatchManager = new StubMatchManager(document);
// Setup Callback
SearchProgressListener callback = EasyMock.createMock(SearchProgressListener.class);
callback.onSearchBegin();
callback.onSearchDone();
callback.onSearchBegin();
callback.onSearchDone();
callback.onSearchBegin();
callback.onSearchDone();
callback.onSearchBegin();
callback.onSearchDone();
replay(callback);
// None of these get called during this test
Renderer mockRenderer = EasyMock.createNiceMock(Renderer.class);
replay(mockRenderer);
SearchModel model = SearchModel.createWithManagerAndScheduler(mockContext,
document,
mockRenderer,
mockView,
mockMatchManager,
new StubIncrementalScheduler(10, 1000),
createMockSelectionModel(document));
model.setQuery("when", callback);
assertEquals(1, mockMatchManager.getTotalMatches());
model.setQuery("When", callback);
assertEquals(1, mockMatchManager.getTotalMatches());
model.setQuery("Doug", callback);
assertEquals(8, mockMatchManager.getTotalMatches());
model.setQuery("tiger", callback);
assertEquals(3, mockMatchManager.getTotalMatches());
model.setQuery("", callback);
assertEquals(0, mockMatchManager.getTotalMatches());
// verify
verify(callback, mockRenderer, mockView, mockContext);
}