1 17 package org.apache.commons.collections.primitives.adapters.io; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 23 import junit.framework.Test; 24 import junit.framework.TestSuite; 25 26 import org.apache.commons.collections.primitives.ByteIterator; 27 import org.apache.commons.collections.primitives.TestByteIterator; 28 29 33 public class TestInputStreamByteIterator extends TestByteIterator { 34 35 38 public TestInputStreamByteIterator(String testName) { 39 super(testName); 40 } 41 42 public static Test suite() { 43 return new TestSuite(TestInputStreamByteIterator.class); 44 } 45 46 48 public boolean supportsRemove() { 49 return false; 50 } 51 52 protected ByteIterator makeEmptyByteIterator() { 53 return new InputStreamByteIterator(new ByteArrayInputStream (new byte[0])); 54 } 55 56 protected ByteIterator makeFullByteIterator() { 57 return new InputStreamByteIterator(new ByteArrayInputStream (getFullElements())); 58 } 59 60 protected byte[] getFullElements() { 61 byte[] bytes = new byte[256]; 62 for(int i=0; i < 256; i++) { 63 bytes[i] = (byte)(i-128); 64 } 65 return bytes; 66 } 67 68 69 71 public void testErrorThrowingStream() { 72 InputStream errStream = new InputStream () { 73 public int read() throws IOException { 74 throw new IOException (); 75 } 76 }; 77 78 ByteIterator iter = new InputStreamByteIterator(errStream); 79 try { 80 iter.hasNext(); 81 fail("Expected RuntimeException"); 82 } catch(RuntimeException e) { 83 } 85 try { 86 iter.next(); 87 fail("Expected RuntimeException"); 88 } catch(RuntimeException e) { 89 } 91 } 92 93 public void testAdaptNull() { 94 assertNull(InputStreamByteIterator.adapt(null)); 95 } 96 97 public void testAdaptNonNull() { 98 assertNotNull(InputStreamByteIterator.adapt(new ByteArrayInputStream (new byte[0]))); 99 } 100 } 101 | Popular Tags |