001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections.primitives.adapters.io;
018
019import java.io.InputStream;
020
021import junit.framework.Test;
022import junit.framework.TestCase;
023import junit.framework.TestSuite;
024
025import org.apache.commons.collections.primitives.ArrayByteList;
026import org.apache.commons.collections.primitives.ByteList;
027
028/**
029 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
030 * @author Rodney Waldhoff
031 */
032public class TestByteIteratorInputStream extends TestCase {
033
034    // conventional
035    // ------------------------------------------------------------------------
036
037    public TestByteIteratorInputStream(String testName) {
038        super(testName);
039    }
040
041    public static Test suite() {
042        return new TestSuite(TestByteIteratorInputStream.class);
043    }
044
045    // ------------------------------------------------------------------------
046    
047
048
049    // ------------------------------------------------------------------------
050    
051    public void testReadNonEmpty() throws Exception {
052        ByteList list = new ArrayByteList();
053        for(int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
054            list.add((byte)i);
055        }
056       
057        InputStream in = new ByteIteratorInputStream(list.iterator());
058        for(int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
059            assertEquals(0xFF&i,in.read());
060        }
061        assertEquals(-1,in.read());
062        assertEquals(-1,in.read());
063    }
064
065    public void testReadEmpty() throws Exception {
066        ByteList list = new ArrayByteList();
067        InputStream in = new ByteIteratorInputStream(list.iterator());
068        assertEquals(-1,in.read());
069        assertEquals(-1,in.read());
070    }
071
072    public void testAdaptNull() {
073        assertNull(ByteIteratorInputStream.adapt(null));
074    }
075
076    public void testAdaptNonNull() {
077        assertNotNull(ByteIteratorInputStream.adapt(new ArrayByteList().iterator()));
078    }
079    
080}