KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > StringArrayReaderTest


1 package com.puppycrawl.tools.checkstyle;
2
3 import junit.framework.TestCase;
4
5 import java.io.IOException JavaDoc;
6
7 public class StringArrayReaderTest
8     extends TestCase
9 {
10     public void testClose()
11     {
12         final StringArrayReader o = new StringArrayReader(new String JavaDoc[] {""});
13         assertNotNull(o);
14         o.close();
15         try {
16             o.read();
17             fail();
18         }
19         catch (IOException JavaDoc e) {
20         }
21     }
22
23     public void testLineBreakSingleChar()
24     {
25         final StringArrayReader o =
26             new StringArrayReader(new String JavaDoc[] {"a", "bc"});
27         try {
28             int a = o.read();
29             assertEquals('a', a);
30             int nl1 = o.read();
31             assertEquals('\n', nl1);
32             int b = o.read();
33             assertEquals('b', b);
34             int c = o.read();
35             assertEquals('c', c);
36             int nl2 = o.read();
37             assertEquals('\n', nl2);
38             int eof = o.read();
39             assertEquals(-1, eof);
40         }
41         catch (IOException JavaDoc ex) {
42         }
43     }
44
45     public void testLineBreakCharArray()
46     {
47         final StringArrayReader o =
48             new StringArrayReader(new String JavaDoc[] {"a", "bc"});
49         try {
50             char[] a = new char[1];
51             int count = o.read(a, 0, 1);
52             assertEquals(1, count);
53             assertEquals('a', a[0]);
54             int nl1 = o.read();
55             assertEquals('\n', nl1);
56             int b = o.read();
57             assertEquals('b', b);
58             int c = o.read();
59             assertEquals('c', c);
60             int nl2 = o.read();
61             assertEquals('\n', nl2);
62             int eof = o.read();
63             assertEquals(-1, eof);
64         }
65         catch (IOException JavaDoc ex) {
66         }
67     }
68
69     public void testNoLineBreakCharArray()
70     {
71         final StringArrayReader o =
72             new StringArrayReader(new String JavaDoc[] {"a", "bc"});
73         try {
74             char[] a = new char[1];
75             o.read(a, 0, 1);
76             int nl1 = o.read();
77             assertEquals('\n', nl1);
78             char[] b = new char[1];
79             int count = o.read(b, 0, 1);
80             assertEquals(1, count);
81             assertEquals('b', b[0]);
82             int c = o.read();
83             assertEquals('c', c);
84             int nl2 = o.read();
85             assertEquals('\n', nl2);
86             int eof = o.read();
87             assertEquals(-1, eof);
88         }
89         catch (IOException JavaDoc ex) {
90         }
91     }
92 }
93
Popular Tags