KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > adapters > io > TestReaderCharIterator


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.commons.collections.primitives.adapters.io;
18
19 import java.io.IOException JavaDoc;
20 import java.io.Reader JavaDoc;
21 import java.io.StringReader JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 import org.apache.commons.collections.primitives.CharIterator;
27 import org.apache.commons.collections.primitives.TestCharIterator;
28
29 /**
30  * @version $Revision: 480451 $ $Date: 2006-11-28 23:45:08 -0800 (Tue, 28 Nov 2006) $
31  * @author Rodney Waldhoff
32  */

33 public class TestReaderCharIterator extends TestCharIterator {
34
35     // conventional
36
// ------------------------------------------------------------------------
37

38     public TestReaderCharIterator(String JavaDoc testName) {
39         super(testName);
40     }
41
42     public static Test suite() {
43         return new TestSuite(TestReaderCharIterator.class);
44     }
45
46     // ------------------------------------------------------------------------
47

48     public boolean supportsRemove() {
49         return false;
50     }
51
52     protected CharIterator makeEmptyCharIterator() {
53         return new ReaderCharIterator(new StringReader JavaDoc(""));
54     }
55
56     protected CharIterator makeFullCharIterator() {
57         return new ReaderCharIterator(new StringReader JavaDoc(new String JavaDoc(getFullElements())));
58     }
59
60     protected char[] getFullElements() {
61         return "The quick brown fox jumped over the lazy dogs.".toCharArray();
62     }
63
64
65     // ------------------------------------------------------------------------
66

67     public void testErrorThrowingReader() {
68         Reader JavaDoc errReader = new Reader JavaDoc() {
69             public int read(char[] buf, int off, int len) throws IOException JavaDoc {
70                 throw new IOException JavaDoc();
71             }
72             
73             public void close() throws IOException JavaDoc {
74             }
75         };
76         
77         CharIterator iter = new ReaderCharIterator(errReader);
78         try {
79             iter.hasNext();
80             fail("Expected RuntimeException");
81         } catch(RuntimeException JavaDoc e) {
82             // expected
83
}
84         try {
85             iter.next();
86             fail("Expected RuntimeException");
87         } catch(RuntimeException JavaDoc e) {
88             // expected
89
}
90     }
91     
92     public void testAdaptNull() {
93         assertNull(ReaderCharIterator.adapt(null));
94     }
95
96     public void testAdaptNonNull() {
97         assertNotNull(ReaderCharIterator.adapt(new StringReader JavaDoc("")));
98     }
99 }
100
Popular Tags