01: /*
02: * MessageBufferTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import workbench.WbTestCase;
15:
16: /**
17: *
18: * @author support@sql-workbench.net
19: */
20: public class MessageBufferTest extends WbTestCase {
21:
22: public MessageBufferTest(String testName) {
23: super (testName);
24: }
25:
26: public void testMaxSize() {
27: try {
28: int max = 5;
29: MessageBuffer b = new MessageBuffer(5);
30: for (int i = 0; i < max * 2; i++) {
31: b.append("Line" + i + "\n");
32: }
33: String content = b.getBuffer().toString();
34: String expected = "(...)\nLine5\nLine6\nLine7\nLine8\nLine9\n";
35: assertEquals(expected, content);
36: } catch (Exception e) {
37: e.printStackTrace();
38: }
39: }
40:
41: public void testAppendBuffer() {
42: MessageBuffer b1 = new MessageBuffer();
43: b1.append("Line one");
44: int l = b1.getLength();
45: MessageBuffer b2 = new MessageBuffer();
46: b2.append(b1);
47: assertEquals("Wrong length", b2.getLength(), l);
48:
49: b2 = new MessageBuffer();
50: b2.append("Some stuff");
51: int l2 = b2.getLength();
52: b2.append(b1);
53: assertEquals("Wrong length", b2.getLength(), l + l2);
54: }
55:
56: public void testBuffer() {
57: try {
58: MessageBuffer b = new MessageBuffer();
59: b.append("Hello, world");
60: b.appendNewLine();
61: b.append("how are you?");
62:
63: CharSequence s = b.getBuffer();
64: assertEquals("Hello, world\nhow are you?", s.toString());
65:
66: } catch (Exception e) {
67: e.printStackTrace();
68: fail(e.getMessage());
69: }
70: }
71:
72: }
|