01: package org.uispec4j.utils;
02:
03: import junit.framework.AssertionFailedError;
04:
05: import java.util.ArrayList;
06: import java.util.Collections;
07: import java.util.List;
08:
09: public class ArrayUtilsTest extends UnitTestCase {
10: public void testToStringWithObjects() throws Exception {
11: assertEquals("[3,true,Hello]", ArrayUtils
12: .toString(new Object[] { new Integer(3), Boolean.TRUE,
13: "Hello" }));
14: }
15:
16: public void testToStringForArrays() {
17: assertEquals("[]", ArrayUtils.toString(new String[0]));
18: assertEquals("[a]", ArrayUtils.toString(new String[] { "a" }));
19: assertEquals("[a,b]", ArrayUtils.toString(new String[] { "a",
20: "b" }));
21: assertEquals("[a,b,c]", ArrayUtils.toString(new String[] { "a",
22: "b", "c" }));
23:
24: assertEquals("[a,b,[null,d],[e,[f,g]],h]",
25: ArrayUtils
26: .toString(new Object[] {
27: "a",
28: "b",
29: new String[] { null, "d" },
30: new Object[] { "e",
31: new String[] { "f", "g" } },
32: "h" }));
33: }
34:
35: public void testToStringForLists() throws Exception {
36: List list = new ArrayList();
37: assertEquals("[]", ArrayUtils.toString(list));
38: list.add("a");
39: assertEquals("[a]", ArrayUtils.toString(new String[] { "a" }));
40: list.add("b");
41: assertEquals("[a,b]", ArrayUtils.toString(new String[] { "a",
42: "b" }));
43: list.add("c");
44: assertEquals("[a,b,c]", ArrayUtils.toString(new String[] { "a",
45: "b", "c" }));
46: }
47:
48: public void testToStringWithIntegers() throws Exception {
49: assertEquals("[4,6,9]", ArrayUtils
50: .toString(new int[] { 4, 6, 9 }));
51: }
52:
53: public void testToStringForTwoDimensionalArrays() throws Exception {
54: assertEquals("[]", ArrayUtils.toString(new String[][] {}));
55: assertEquals("[[a]]", ArrayUtils
56: .toString(new String[][] { { "a" } }));
57: assertEquals("[[a,\tb]\n [c,\td]]",
58: ArrayUtils.toString(new String[][] { { "a", "b" },
59: { "c", "d" } }));
60: }
61:
62: public void testAssertEmptyForAnArray() throws Exception {
63: ArrayUtils.assertEmpty((String[]) null);
64: ArrayUtils.assertEmpty(new Object[0]);
65: try {
66: ArrayUtils.assertEmpty(new String[] { "a" });
67: throw new AssertionFailureNotDetectedError();
68: } catch (AssertionFailedError e) {
69: assertEquals("Array should be empty but is [a]", e
70: .getMessage());
71: }
72: }
73:
74: public void testAssertEmpty() throws Exception {
75: ArrayUtils.assertEmpty((List[]) null);
76: ArrayUtils.assertEmpty(Collections.EMPTY_LIST);
77: try {
78: List list = new ArrayList();
79: list.add("a");
80: ArrayUtils.assertEmpty(list);
81: throw new AssertionFailureNotDetectedError();
82: } catch (AssertionFailedError e) {
83: assertEquals("List should be empty but is [a]", e
84: .getMessage());
85: }
86: }
87: }
|