O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dead End

I started by refactoring to create a dependency injection seam [63797de]. The idea was to inject an HttpClient mock that would allow me to inspect the resulting argument to its execute() method in retrieve-Response(). To that end, I elevated the HttpClient instance to a class field initialized in the default constructor, which I now needed to make explicit. I then factored out a constructor that took an HttpClient instance as an argument and reworked the default constructor to chain to the new one, passing a fresh instance.

In writing the test to exploit the seam, I discovered that many of the methods of DefaultHttpClient and AbstractHttpClient, including the single-argument version of execute() that the code uses, are final, preventing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required