Refactors SuggestionSession to make it testable, adds some tests.
The adjustments make the dependencies of SuggestionSession lightweight enough
so the test can more easily inject them:
- SuggestionFactory is an interface, and the necessary methods take in the query
string when necessary, instead of taking it in as a c'tor paremeter. this means
we no longer need to create the factory for each query, just once per session.
- ShortcutRepository is an interface instead of an abstract base class (there is
no need for the base class anymore anyways since we only have one implementation).
- SuggestionSources implements an interface, SourceLookup, so the sesssion doesn't
depend directly on the heavy weight logic in SuggestionSources that interacts with
preferences etc
- Add interface 'DelayedExecutor' to remove direct dependency on the Handler
The test injects a special implementation of Executor and DelayedExecutor so it
can tell what sources have been queried when, allowing us to verify the behavior.
Introducing these new interfaces may seem a bit risky given our memory and speed
constraints, but in practice, this will only add a couple extra objects per session
creation, and I feel a lot better about the stability / maintainability of session
with some tests in place.
19 files changed