01: package pygmy.nntp.test;
02:
03: import junit.framework.TestCase;
04: import junit.framework.Test;
05: import junit.framework.TestSuite;
06: import pygmy.nntp.NntpInputStream;
07:
08: import java.io.ByteArrayInputStream;
09:
10: import pygmy.core.Http;
11:
12: public class NntpInputStreamTest extends TestCase {
13:
14: protected void setUp() throws Exception {
15: super .setUp();
16: }
17:
18: protected void tearDown() throws Exception {
19: super .tearDown();
20: }
21:
22: public void testReadText() throws Exception {
23: String testText = "Fry told him to go back to the jungle."
24: + Http.CRLF;
25:
26: StringBuffer buffer = new StringBuffer();
27: buffer.append(testText);
28: writeTextEnd(buffer);
29:
30: String testText2 = ".Gunter wanted to be an ape of moderate intelligence...."
31: + Http.CRLF;
32: buffer.append(".");
33: buffer.append(testText2);
34: writeTextEnd(buffer);
35:
36: String testText3 = "." + Http.CRLF;
37: buffer.append(".");
38: buffer.append(testText3);
39: writeTextEnd(buffer);
40:
41: NntpInputStream stream = new NntpInputStream(
42: new ByteArrayInputStream(buffer.toString().getBytes()));
43: assertEquals(testText, stream.readText());
44: assertEquals(testText2, stream.readText());
45: assertEquals(testText3, stream.readText());
46: }
47:
48: private void writeTextEnd(StringBuffer buffer) {
49: buffer.append(".");
50: buffer.append(Http.CRLF);
51: }
52:
53: public static Test suite() {
54: return new TestSuite(NntpInputStreamTest.class);
55: }
56:
57: public static void main(String[] args) {
58: junit.textui.TestRunner.run(suite());
59: }
60: }
|