01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16:
17: package org.columba.mail.parser;
18:
19: import java.io.ByteArrayInputStream;
20: import java.io.IOException;
21:
22: import junit.framework.TestCase;
23:
24: import org.columba.ristretto.message.Header;
25:
26: public class PassiveHeaderParserInputStreamTest extends TestCase {
27:
28: public void testFullRead() throws IOException {
29: String header = "Subject: nbla\r\n\r\n some message blabla\r\n";
30:
31: PassiveHeaderParserInputStream test = new PassiveHeaderParserInputStream(
32: new ByteArrayInputStream(header.getBytes()));
33:
34: byte[] dummy = new byte[10000];
35:
36: assertFalse(test.isHeaderAvailable());
37:
38: assertEquals(header.length(), test.read(dummy));
39: assertTrue(test.isHeaderAvailable());
40:
41: Header parsedHeader = test.getHeader();
42:
43: assertEquals("nbla", parsedHeader.get("Subject"));
44:
45: }
46:
47: public void testPartRead() throws IOException {
48: String header = "Subject: nbla\r\n\r\nsome message blabla\r\n";
49:
50: PassiveHeaderParserInputStream test = new PassiveHeaderParserInputStream(
51: new ByteArrayInputStream(header.getBytes()));
52:
53: assertFalse(test.isHeaderAvailable());
54:
55: for (int i = 0; i < 17; i++) {
56: assertFalse(test.isHeaderAvailable());
57: test.read();
58: }
59:
60: assertTrue(test.isHeaderAvailable());
61:
62: Header parsedHeader = test.getHeader();
63:
64: assertEquals("nbla", parsedHeader.get("Subject"));
65:
66: }
67:
68: }
|