01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.components;
04:
05: import junit.framework.TestCase;
06: import java.io.*;
07: import fitnesse.util.*;
08:
09: public class ContentBufferTest extends TestCase {
10: protected void tearDown() throws Exception {
11: System.gc();
12: }
13:
14: public void testName() throws Exception {
15: String name = new ContentBuffer().getFile().getName();
16: assertTrue(name.startsWith("FitNesse-"));
17: assertTrue(name.endsWith(".tmp"));
18:
19: name = new ContentBuffer(".html").getFile().getName();
20: assertTrue(name.startsWith("FitNesse-"));
21: assertTrue(name.endsWith(".html"));
22: }
23:
24: public void testSimpleUsage() throws Exception {
25: ContentBuffer buffer = new ContentBuffer();
26: buffer.append("some content");
27: assertEquals("some content", buffer.getContent());
28: }
29:
30: public void testGettingInputStream() throws Exception {
31: ContentBuffer buffer = new ContentBuffer();
32: buffer.append("some content");
33:
34: int bytes = buffer.getSize();
35: assertEquals(12, bytes);
36:
37: InputStream input = buffer.getInputStream();
38: String content = new StreamReader(input).read(12);
39: assertEquals("some content", content);
40: }
41:
42: public void testDelete() throws Exception {
43: ContentBuffer buffer = new ContentBuffer();
44: File file = buffer.getFile();
45:
46: assertTrue(file.exists());
47: buffer.delete();
48: assertFalse(file.exists());
49: }
50:
51: public void testUnicode() throws Exception {
52: ContentBuffer buffer = new ContentBuffer();
53: buffer.append("??¾š");
54: assertEquals("??¾š", new StreamReader(buffer.getInputStream())
55: .read(buffer.getSize()));
56: }
57: }
|