View Javadoc

1   package com.atlassian.core.util;
2   
3   import junit.framework.TestCase;
4   import org.junit.Test;
5   
6   import javax.imageio.ImageIO;
7   import java.io.IOException;
8   import java.io.InputStream;
9   
10  public class TestReusableBufferedInputStream extends TestCase
11  {
12      public void testReusableInputStreamIsReusable() throws Exception
13      {
14          InputStream inputStream = this.getClass().getResourceAsStream("/image.gif");
15          InputStream reusableInputStream = new ReusableBufferedInputStream(inputStream);
16  
17          ImageIO.read(reusableInputStream);
18          assertTrue("Expect end of the input stream after reading from it", reusableInputStream.available() == 0);
19  
20          reusableInputStream.close();
21          assertTrue("Expect to be at the start of the reusable input stream after calling close()", reusableInputStream.available() > 0);
22      }
23  
24      @Test(expected = IOException.class)
25      public void testReusableInputStreamIsClosable() throws Exception
26      {
27          InputStream inputStream = this.getClass().getResourceAsStream("/image.gif");
28          ReusableBufferedInputStream reusableInputStream = new ReusableBufferedInputStream(inputStream);
29  
30          reusableInputStream.destroy();
31          ImageIO.read(reusableInputStream);
32      }
33  }