1 17 package org.apache.commons.collections.primitives.adapters.io; 18 19 import java.io.InputStream ; 20 21 import junit.framework.Test; 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 25 import org.apache.commons.collections.primitives.ArrayByteList; 26 import org.apache.commons.collections.primitives.ByteList; 27 28 32 public class TestByteIteratorInputStream extends TestCase { 33 34 37 public TestByteIteratorInputStream(String testName) { 38 super(testName); 39 } 40 41 public static Test suite() { 42 return new TestSuite(TestByteIteratorInputStream.class); 43 } 44 45 47 48 49 51 public void testReadNonEmpty() throws Exception { 52 ByteList list = new ArrayByteList(); 53 for(int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { 54 list.add((byte)i); 55 } 56 57 InputStream in = new ByteIteratorInputStream(list.iterator()); 58 for(int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { 59 assertEquals(0xFF&i,in.read()); 60 } 61 assertEquals(-1,in.read()); 62 assertEquals(-1,in.read()); 63 } 64 65 public void testReadEmpty() throws Exception { 66 ByteList list = new ArrayByteList(); 67 InputStream in = new ByteIteratorInputStream(list.iterator()); 68 assertEquals(-1,in.read()); 69 assertEquals(-1,in.read()); 70 } 71 72 public void testAdaptNull() { 73 assertNull(ByteIteratorInputStream.adapt(null)); 74 } 75 76 public void testAdaptNonNull() { 77 assertNotNull(ByteIteratorInputStream.adapt(new ArrayByteList().iterator())); 78 } 79 80 } 81 | Popular Tags |