### Question:
Closer { public static void close(Reader reader) { if (reader != null) { try { reader.close(); } catch (IOException e) { UncheckedInterruptedException.ioException(e); } } } Closer(); static void close(Reader reader); static void close(Writer writer); static void close(InputStream inputStream); static void close(OutputStream outputStream); static void close(Socket socket);  }### Answer:
@Test public void testCloseReader() throws Exception { Closer.close((Reader)null); final Reader reader = new Reader() { public void close() throws IOException { TestCloser.this.close(); } public int read(char[] cbuf, int off, int len) { return 0; } }; Closer.close(reader); m_ioexception[0] = new IOException(); Closer.close(reader); m_ioexception[0] = new InterruptedIOException(); try { Closer.close(reader); fail("Expected UncheckedInterruptedException"); } catch (UncheckedInterruptedException e) { assertSame(m_ioexception[0], e.getCause()); } }
@Test public void testCloseWriter() throws Exception { Closer.close((Writer)null); final Writer writer = new Writer() { public void close() throws IOException { TestCloser.this.close(); } public void flush() throws IOException { } public void write(char[] cbuf, int off, int len) throws IOException { } }; Closer.close(writer); m_ioexception[0] = new IOException(); Closer.close(writer); m_ioexception[0] = new InterruptedIOException(); try { Closer.close(writer); fail("Expected UncheckedInterruptedException"); } catch (UncheckedInterruptedException e) { assertSame(m_ioexception[0], e.getCause()); } }
@Test public void testCloseInputStream() throws Exception { Closer.close((InputStream)null); final InputStream in = new InputStream() { public void close() throws IOException { TestCloser.this.close(); } public int read() throws IOException { return 0; } }; Closer.close(in); m_ioexception[0] = new IOException(); Closer.close(in); m_ioexception[0] = new InterruptedIOException(); try { Closer.close(in); fail("Expected UncheckedInterruptedException"); } catch (UncheckedInterruptedException e) { assertSame(m_ioexception[0], e.getCause()); } }
@Test public void testCloseOutputStream() throws Exception { Closer.close((OutputStream)null); final OutputStream outputStream = new OutputStream() { public void close() throws IOException { TestCloser.this.close(); } public void flush() throws IOException { } public void write(int b) throws IOException { } }; Closer.close(outputStream); m_ioexception[0] = new IOException(); Closer.close(outputStream); m_ioexception[0] = new InterruptedIOException(); try { Closer.close(outputStream); fail("Expected UncheckedInterruptedException"); } catch (UncheckedInterruptedException e) { assertSame(m_ioexception[0], e.getCause()); } }