1 package net.sf.uitags.util; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.io.Reader ; 6 7 import junit.framework.TestCase; 8 9 public class ResourceCloserTest extends TestCase { 10 public void testDoesNotFailOnNullResource() { 11 Reader reader = null; 12 ResourceCloser.close(reader); 13 14 InputStream inputStream = null; 15 ResourceCloser.close(inputStream); 16 } 17 18 public void testDoesNotFailOnExceptionCausedByClosingResource() { 19 ResourceCloser.close(new MockReader()); 20 ResourceCloser.close(new MockInputStream()); 21 } 22 23 24 25 29 private static final class MockReader extends Reader { 30 public void close() throws IOException { 31 throw new IOException ( 32 "Thrown by a test method that always throws an exception."); 33 } 34 35 public int read(char[] cbuf, int off, int len) throws IOException { 36 return 0; 37 } 38 } 39 40 private static final class MockInputStream extends InputStream { 41 public void close() throws IOException { 42 throw new IOException ( 43 "Thrown by a test method that always throws an exception."); 44 } 45 46 public int read() throws IOException { 47 return 0; 48 } 49 } 50 } 51 | Popular Tags |