001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.util;
005:
006: import com.tc.test.TCTestCase;
007:
008: /**
009: * Unit test for {@link StandardStringifier}.
010: */
011: public class StandardStringifierTest extends TCTestCase {
012:
013: private StandardStringifier stringifier;
014:
015: public void setUp() {
016: this .stringifier = StandardStringifier.INSTANCE;
017: }
018:
019: public void testNull() throws Exception {
020: assertEquals("<null>", stringifier.toString(null));
021: }
022:
023: private static class MyObj {
024: private final String value;
025:
026: public MyObj(String value) {
027: this .value = value;
028: }
029:
030: public String toString() {
031: return this .value;
032: }
033: }
034:
035: public void testObject() throws Exception {
036: assertEquals("FOOBAR", stringifier
037: .toString(new MyObj("FOOBAR")));
038: }
039:
040: public void testObjectArray() throws Exception {
041: assertEquals("Object[3]: FOOBAR, barbaz, FOOFLE", stringifier
042: .toString(new Object[] { new MyObj("FOOBAR"),
043: new MyObj("barbaz"), new MyObj("FOOFLE") }));
044: assertEquals(
045: "Object[22]: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...",
046: stringifier.toString(new Object[] { new MyObj("1"),
047: new MyObj("2"), new MyObj("3"), new MyObj("4"),
048: new MyObj("5"), new MyObj("6"), new MyObj("7"),
049: new MyObj("8"), new MyObj("9"),
050: new MyObj("10"), new MyObj("11"),
051: new MyObj("12"), new MyObj("13"),
052: new MyObj("14"), new MyObj("15"),
053: new MyObj("16"), new MyObj("17"),
054: new MyObj("18"), new MyObj("19"),
055: new MyObj("20"), new MyObj("21"),
056: new MyObj("22") }));
057: }
058:
059: public void testOurObjectArray() throws Exception {
060: assertEquals(
061: "StandardStringifierTest.MyObj[3]: FOOBAR, barbaz, FOOFLE",
062: stringifier.toString(new MyObj[] { new MyObj("FOOBAR"),
063: new MyObj("barbaz"), new MyObj("FOOFLE") }));
064: assertEquals(
065: "StandardStringifierTest.MyObj[22]: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...",
066: stringifier.toString(new MyObj[] { new MyObj("1"),
067: new MyObj("2"), new MyObj("3"), new MyObj("4"),
068: new MyObj("5"), new MyObj("6"), new MyObj("7"),
069: new MyObj("8"), new MyObj("9"),
070: new MyObj("10"), new MyObj("11"),
071: new MyObj("12"), new MyObj("13"),
072: new MyObj("14"), new MyObj("15"),
073: new MyObj("16"), new MyObj("17"),
074: new MyObj("18"), new MyObj("19"),
075: new MyObj("20"), new MyObj("21"),
076: new MyObj("22") }));
077: }
078:
079: public void testByteArray() throws Exception {
080: assertEquals("3 bytes: 0102 03 ...", stringifier
081: .toString(new byte[] { 1, 2, 3 }));
082: }
083:
084: public void testShortArray() throws Exception {
085: assertEquals("short[3]: 1, 2, 3", stringifier
086: .toString(new short[] { 1, 2, 3 }));
087: assertEquals(
088: "short[22]: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...",
089: stringifier.toString(new short[] { 1, 2, 3, 4, 5, 6, 7,
090: 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
091: 20, 21, 22 }));
092: }
093:
094: public void testIntArray() throws Exception {
095: assertEquals("int[3]: 1, 2, 3", stringifier.toString(new int[] {
096: 1, 2, 3 }));
097: assertEquals(
098: "int[22]: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...",
099: stringifier.toString(new int[] { 1, 2, 3, 4, 5, 6, 7,
100: 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
101: 20, 21, 22 }));
102: }
103:
104: public void testLongArray() throws Exception {
105: assertEquals("long[3]: 1, 2, 3", stringifier
106: .toString(new long[] { 1, 2, 3 }));
107: assertEquals(
108: "long[22]: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...",
109: stringifier.toString(new long[] { 1, 2, 3, 4, 5, 6, 7,
110: 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
111: 20, 21, 22 }));
112: }
113:
114: public void testCharArray() throws Exception {
115: assertEquals("char[3]: 1, 2, 3", stringifier
116: .toString(new char[] { '1', '2', '3' }));
117: assertEquals(
118: "char[22]: 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, ...",
119: stringifier.toString(new char[] { '1', '2', '3', '4',
120: '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
121: 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm' }));
122: }
123:
124: public void testBooleanArray() throws Exception {
125: assertEquals("boolean[3]: true, false, true", stringifier
126: .toString(new boolean[] { true, false, true }));
127: assertEquals(
128: "boolean[22]: true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, ...",
129: stringifier.toString(new boolean[] { true, false, true,
130: false, true, false, true, false, true, false,
131: true, false, true, false, true, false, true,
132: false, true, false, true, false }));
133: }
134:
135: public void testFloatArray() throws Exception {
136: assertEquals("float[3]: 1.0, 2.0, 3.0", stringifier
137: .toString(new float[] { 1.0f, 2.0f, 3.0f }));
138: assertEquals(
139: "float[22]: 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, ...",
140: stringifier.toString(new float[] { 1.0f, 2.0f, 3.0f,
141: 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f,
142: 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
143: 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f }));
144: }
145:
146: public void testDoubleArray() throws Exception {
147: assertEquals("double[3]: 1.0, 2.0, 3.0", stringifier
148: .toString(new double[] { 1.0, 2.0, 3.0 }));
149: assertEquals(
150: "double[22]: 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, ...",
151: stringifier.toString(new double[] { 1.0, 2.0, 3.0, 4.0,
152: 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0,
153: 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0,
154: 21.0, 22.0 }));
155: }
156:
157: }
|