March 2015
Intermediate to advanced
236 pages
5h 26m
English
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:
| iloveyouboss/test-10/test/util/SearchTest.java | |
| | @Test |
| | public void returnsErroredWhenUnableToReadStream() { |
| | stream = createStreamThrowingErrorWhenRead(); |
| | Search search = new Search(stream, "", ""); |
| | |
| | search.execute(); |
| | |
| | assertTrue(search.errored()); |
| | } |
| | |
| | private InputStream createStreamThrowingErrorWhenRead() { |
| | return new InputStream() { |
| | @Override |
| | public int read() throws IOException { |
| | throw new IOException(); |
| | } |
| | }; |
| | } |
And add a test for the opposite:
| iloveyouboss/test-10/test/util/SearchTest.java ... |
Read now
Unlock full access