How it works...
First, with mocking, we've avoided implementing the Api dependency of the Authenticator class we were writing the test for. In fact, we are not interested in testing real results returned by the Api implementation. We want to test the mechanism of the tryToAuthorise() function and verify whether it's going to retry calling the Api.authorise() function at least 10 times in case of constant authorization failures. This is why we have set up the api mock to always return an empty string for the authorise() function result.
As you can imagine, such a test would take a lot of time to complete because, internally, the tryToAuthorise() function waits for 10 seconds before retrying the authorization. In order to avoid the too-long ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access