Test Smell: Bloated Construction

We must pass an InputStream to a Search object through its constructor. Our test builds an InputStream in two places. The first construction requires three statements:

String​ pageContent = ​"There are certain queer times and occasions "
+ ​"in this strange mixed affair we call life when a man "
+ ​"takes this whole universe for a vast practical joke, "
+ ​"though the wit thereof he but dimly discerns, and more "
+ ​"than suspects that the joke is at nobody's expense but "
+ ​"his own."​;
byte​​[]​ bytes = pageContent.getBytes();
ByteArrayInputStream​ stream = ​new​ ​ByteArrayInputStream​(bytes);

As in our earlier example, where you introduced ...

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.