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.Reader;
020
021import junit.framework.Test;
022import junit.framework.TestCase;
023import junit.framework.TestSuite;
024
025import org.apache.commons.collections.primitives.ArrayCharList;
026import org.apache.commons.collections.primitives.CharList;
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 TestCharIteratorReader extends TestCase {
033
034    // conventional
035    // ------------------------------------------------------------------------
036
037    public TestCharIteratorReader(String testName) {
038        super(testName);
039    }
040
041    public static Test suite() {
042        return new TestSuite(TestCharIteratorReader.class);
043    }
044
045    // ------------------------------------------------------------------------
046    
047
048
049    // ------------------------------------------------------------------------
050    
051    public void testReadNonEmpty() throws Exception {
052        String str = "The quick brown fox jumped over the lazy dogs.";
053        CharList list = new ArrayCharList();
054        for(int i = 0; i < str.length(); i++) {
055            list.add(str.charAt(i));
056        }
057       
058        Reader in = new CharIteratorReader(list.iterator());
059        for(int i = 0; i < str.length(); i++) {
060            assertEquals(str.charAt(i),in.read());
061        }
062        assertEquals(-1,in.read());
063        assertEquals(-1,in.read());
064        in.close();
065    }
066
067    public void testReadEmpty() throws Exception {
068        CharList list = new ArrayCharList();
069        Reader in = new CharIteratorReader(list.iterator());
070        assertEquals(-1,in.read());
071        assertEquals(-1,in.read());
072        in.close();
073    }
074
075    public void testAdaptNull() {
076        assertNull(CharIteratorReader.adapt(null));
077    }
078
079    public void testAdaptNonNull() {
080        assertNotNull(CharIteratorReader.adapt(new ArrayCharList().iterator()));
081    }
082    
083}