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.IOException; 020import java.io.Reader; 021import java.io.StringReader; 022 023import junit.framework.Test; 024import junit.framework.TestSuite; 025 026import org.apache.commons.collections.primitives.CharIterator; 027import org.apache.commons.collections.primitives.TestCharIterator; 028 029/** 030 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $ 031 * @author Rodney Waldhoff 032 */ 033public class TestReaderCharIterator extends TestCharIterator { 034 035 // conventional 036 // ------------------------------------------------------------------------ 037 038 public TestReaderCharIterator(String testName) { 039 super(testName); 040 } 041 042 public static Test suite() { 043 return new TestSuite(TestReaderCharIterator.class); 044 } 045 046 // ------------------------------------------------------------------------ 047 048 public boolean supportsRemove() { 049 return false; 050 } 051 052 protected CharIterator makeEmptyCharIterator() { 053 return new ReaderCharIterator(new StringReader("")); 054 } 055 056 protected CharIterator makeFullCharIterator() { 057 return new ReaderCharIterator(new StringReader(new String(getFullElements()))); 058 } 059 060 protected char[] getFullElements() { 061 return "The quick brown fox jumped over the lazy dogs.".toCharArray(); 062 } 063 064 065 // ------------------------------------------------------------------------ 066 067 public void testErrorThrowingReader() { 068 Reader errReader = new Reader() { 069 public int read(char[] buf, int off, int len) throws IOException { 070 throw new IOException(); 071 } 072 073 public void close() throws IOException { 074 } 075 }; 076 077 CharIterator iter = new ReaderCharIterator(errReader); 078 try { 079 iter.hasNext(); 080 fail("Expected RuntimeException"); 081 } catch(RuntimeException e) { 082 // expected 083 } 084 try { 085 iter.next(); 086 fail("Expected RuntimeException"); 087 } catch(RuntimeException e) { 088 // expected 089 } 090 } 091 092 public void testAdaptNull() { 093 assertNull(ReaderCharIterator.adapt(null)); 094 } 095 096 public void testAdaptNonNull() { 097 assertNotNull(ReaderCharIterator.adapt(new StringReader(""))); 098 } 099}