01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.text;
06:
07: import com.tc.util.NonPortableDetail;
08:
09: import java.io.PrintWriter;
10: import java.io.StringWriter;
11: import java.util.LinkedList;
12: import java.util.List;
13:
14: import junit.framework.TestCase;
15:
16: public class NonPortableReasonFormatterTest extends TestCase {
17:
18: private NonPortableReasonFormatter formatter;
19: private PrintWriter out;
20: private TestParagraphFormatter paragraphFormatter;
21: private StringFormatter stringFormatter;
22: private StringWriter stringWriter;
23: private String separator;
24:
25: public void setUp() {
26: stringFormatter = new StringFormatter();
27: stringWriter = new StringWriter();
28: out = new PrintWriter(stringWriter);
29: separator = ": ";
30: paragraphFormatter = new TestParagraphFormatter();
31: formatter = new ConsoleNonPortableReasonFormatter(out,
32: separator, stringFormatter, paragraphFormatter);
33: }
34:
35: public void testBasics() {
36:
37: String reasonText = "my reason text";
38: formatter.formatReasonText(reasonText);
39: assertEquals(1, paragraphFormatter.formatCalls.size());
40: assertEquals(reasonText, paragraphFormatter.formatCalls.get(0));
41:
42: // check the formatting of details
43: NonPortableDetail detail1 = new NonPortableDetail("0123456789",
44: "0123456789");
45: NonPortableDetail detail2 = new NonPortableDetail("0123",
46: "0123");
47: formatter.formatDetail(detail1);
48: formatter.formatDetail(detail2);
49:
50: StringBuffer expected = new StringBuffer();
51: expected.append(reasonText + stringFormatter.newline());
52: expected.append(stringFormatter.newline());
53:
54: expected
55: .append("For more information on this issue, please visit our Troubleshooting Guide at:"
56: + stringFormatter.newline());
57: expected.append("http://terracotta.org/kit/troubleshooting"
58: + stringFormatter.newline());
59: expected.append(stringFormatter.newline());
60:
61: expected.append("0123456789" + separator + "0123456789"
62: + stringFormatter.newline());
63: expected.append("0123 " + separator + "0123");
64:
65: // check formatting
66: formatter.flush();
67: System.err.println("Expecting: <" + expected + ">, found: <"
68: + stringWriter.getBuffer().toString() + ">");
69: assertEquals(expected.toString(), stringWriter.getBuffer()
70: .toString());
71: formatter.flush();
72: assertEquals(expected.toString(), stringWriter.getBuffer()
73: .toString());
74: }
75:
76: private static final class TestParagraphFormatter implements
77: ParagraphFormatter {
78:
79: public final List formatCalls = new LinkedList();
80:
81: public String format(String in) {
82: formatCalls.add(in);
83: return in;
84: }
85: }
86: }
|