but I don't see how that is possible since it is explicitly set within the function. Please let me know if I'm missing something.
The intent of overriding that method is to mock out both the ZK client and the connection to the ZK server. If we just mocked out the ZK client itself then the logic in ActiveStandbyElector that uses the ZK client to connect to the server would either fail outright (as you intentionally do for this one, specific test) or the mock needs to be much more sophisticated to fool the connection code. Overriding the method that does both the client create and server connect is simpler for the vast majority of the tests that want to focus on mocking out functionality relevant when connected to the ZK server rather.
+1 lgtm. I'll fix the indent nit flagged by checkstyle during the commit.