Cutting the Cord

When you test-drive, you create the seams that support your testing intent. Recognizing that the retrieve() method (Listing 14-2)

• Was a bit long

• Had no ready-made seams with which to sever the network connection for testing

• And performed a wide variety of low-level mechanics in support of its purpose

I decided to simplify and encapsulate it before continuing. Commit [c602d34] was the first application of this principle for WebRetriever.

Listing 14-2: The working but unwieldy and poorly testable first version of WebRetriever.retrieve()

public String retrieve(String URI) throws IOException {  HttpClient httpClient = new DefaultHttpClient();  HttpGet httpGet = new HttpGet(URI);  HttpResponse ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.