### Question:
PatternDetectingReader extends FilterReader { @Override public int read() throws IOException { char[] buffer = new char[1]; int read = read(buffer); if (read < 0) { return read; } else { return buffer[0]; } } PatternDetectingReader(Reader delegate, String pattern); @Override void close(); @Override int read(); @Override int read(char[] b); @Override int read(char[] b, int off, int len);  }### Answer:
@Test public void testNotFoundSingleBytes() throws IOException { Reader data = new StringReader("aabbcc"); PatternDetectingReader in = new PatternDetectingReader(data, "abc"); assertNotEquals(-1, in.read()); assertNotEquals(-1, in.read()); assertNotEquals(-1, in.read()); assertNotEquals(-1, in.read()); assertNotEquals(-1, in.read()); assertNotEquals(-1, in.read()); assertEquals(-1, in.read()); assertThrows(IOException.class, in::close); }
@Test public void testNotFoundMultiBytes() throws IOException { char[] buffer = new char[5]; Reader data = new StringReader("aabbccdd"); PatternDetectingReader in = new PatternDetectingReader(data, "abc"); assertEquals(3, in.read(buffer, 1, 3)); assertEquals(3, in.read(buffer, 1, 3)); assertEquals(2, in.read(buffer, 1, 3)); assertEquals(-1, in.read(buffer, 1, 3)); assertThrows(IOException.class, in::close); }