01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.util;
05:
06: import com.tc.text.NonPortableReasonFormatter;
07:
08: import java.util.LinkedList;
09: import java.util.List;
10:
11: import junit.framework.TestCase;
12:
13: public class NonPortableReasonTest extends TestCase {
14: private NonPortableReason reason;
15:
16: public void setUp() {
17: this .reason = new NonPortableReason(getClass(),
18: NonPortableReason.TEST_REASON);
19: }
20:
21: public void testAcceptFormatter() {
22: TestNonPortableReasonFormatter formatter = new TestNonPortableReasonFormatter();
23: this .reason.addDetail("label1", "value1");
24: this .reason.addDetail("label2", "value2");
25: this .reason.accept(formatter);
26:
27: // make sure the detail text was formatted
28: assertEquals(1, formatter.formatReasonTextCalls.size());
29:
30: // make sure the details were formatted
31: assertEquals(2, formatter.formatDetailsCalls.size());
32: assertReasonEquals("label1", "value1",
33: formatter.formatDetailsCalls.get(0));
34: assertReasonEquals("label2", "value2",
35: formatter.formatDetailsCalls.get(1));
36:
37: // make sure the instruction text was formatted
38: assertEquals(1, formatter.formatInstructionsTextCalls.size());
39: }
40:
41: private void assertReasonEquals(String label, String value, Object o) {
42: NonPortableDetail detail = (NonPortableDetail) o;
43: assertEquals(label, detail.getLabel());
44: assertEquals(value, detail.getValue());
45: }
46:
47: private static final class TestNonPortableReasonFormatter implements
48: NonPortableReasonFormatter {
49:
50: public final List formatReasonTextCalls = new LinkedList();
51: public final List formatDetailsCalls = new LinkedList();
52: public final List formatInstructionsTextCalls = new LinkedList();
53: public final List flushCalls = new LinkedList();
54:
55: public void formatReasonText(String reasonText) {
56: formatReasonTextCalls.add(reasonText);
57: }
58:
59: public void formatDetail(NonPortableDetail detail) {
60: formatDetailsCalls.add(detail);
61: }
62:
63: public void formatInstructionsText(String instructionsText) {
64: formatInstructionsTextCalls.add(instructionsText);
65: }
66:
67: public void flush() {
68: flushCalls.add(new Object());
69: }
70:
71: public void formatReasonTypeName(byte reasonType) {
72: return;
73: }
74: }
75: }
|