Adding a New Test

With our initial ugly test whittled into two sleek, clear tests, it’s now relatively easy to add a couple of new tests. First let’s write a test that demonstrates how a search returns true for the errored() query:

public​ ​void​ returnsErroredWhenUnableToReadStream() {
stream = createStreamThrowingErrorWhenRead();
Search search = ​new​ Search(stream, ​""​, ​""​);
private​ ​InputStream​ createStreamThrowingErrorWhenRead() {
return​ ​new​ ​InputStream​() {
public​ ​int​ read() ​throws​ IOException {
throw​ ​new​ IOException();

And add a test for the opposite:

iloveyouboss/test-10/test/util/ ...

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.