1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.primitives.adapters.io;
18
19 import java.io.IOException;
20 import java.io.Reader;
21 import java.io.StringReader;
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
31
32
33 public class TestReaderCharIterator extends TestCharIterator {
34
35
36
37
38 public TestReaderCharIterator(String 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(""));
54 }
55
56 protected CharIterator makeFullCharIterator() {
57 return new ReaderCharIterator(new StringReader(new String(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 errReader = new Reader() {
69 public int read(char[] buf, int off, int len) throws IOException {
70 throw new IOException();
71 }
72
73 public void close() throws IOException {
74 }
75 };
76
77 CharIterator iter = new ReaderCharIterator(errReader);
78 try {
79 iter.hasNext();
80 fail("Expected RuntimeException");
81 } catch(RuntimeException e) {
82
83 }
84 try {
85 iter.next();
86 fail("Expected RuntimeException");
87 } catch(RuntimeException e) {
88
89 }
90 }
91
92 public void testAdaptNull() {
93 assertNull(ReaderCharIterator.adapt(null));
94 }
95
96 public void testAdaptNonNull() {
97 assertNotNull(ReaderCharIterator.adapt(new StringReader("")));
98 }
99 }