1 package com.thoughtworks.acceptance;
2
3 public class ArraysTest extends AbstractAcceptanceTest {
4
5 public void testStringArray() {
6 String[] array = new String[]{"a", "b", "c"};
7
8 String expected = "" +
9 "<string-array>\n" +
10 " <string>a</string>\n" +
11 " <string>b</string>\n" +
12 " <string>c</string>\n" +
13 "</string-array>";
14
15 assertBothWays(array, expected);
16 }
17
18 public void testPrimitiveArray() {
19 int[] array = new int[]{1, 2};
20
21 String expected = "" +
22 "<int-array>\n" +
23 " <int>1</int>\n" +
24 " <int>2</int>\n" +
25 "</int-array>";
26
27 assertBothWays(array, expected);
28 }
29
30 class X {
31 String s = "hi";
32
33 public boolean equals(Object obj) {
34 return obj instanceof X;
35 }
36 }
37
38 public void testCustomObjectArray() {
39
40 X[] array = new X[]{new X(), new X()};
41
42 String expected = "" +
43 "<com.thoughtworks.acceptance.ArraysTest-X-array>\n" +
44 " <com.thoughtworks.acceptance.ArraysTest-X>\n" +
45 " <s>hi</s>\n" +
46 " </com.thoughtworks.acceptance.ArraysTest-X>\n" +
47 " <com.thoughtworks.acceptance.ArraysTest-X>\n" +
48 " <s>hi</s>\n" +
49 " </com.thoughtworks.acceptance.ArraysTest-X>\n" +
50 "</com.thoughtworks.acceptance.ArraysTest-X-array>";
51
52 assertBothWays(array, expected);
53 }
54
55 public void testArrayOfMixedTypes() {
56
57 Object[] array = new Number[]{new Long(2), new Integer(3)};
58
59 String expected = "" +
60 "<number-array>\n" +
61 " <long>2</long>\n" +
62 " <int>3</int>\n" +
63 "</number-array>";
64
65 assertBothWays(array, expected);
66
67 }
68
69 public void testEmptyArray() {
70 int[] array = new int[]{};
71
72 String expected = "<int-array/>";
73
74 assertBothWays(array, expected);
75
76 }
77
78 public void testUninitializedArray() {
79 String[] array = new String[4];
80 array[0] = "zero";
81 array[2] = "two";
82
83 String expected = "" +
84 "<string-array>\n" +
85 " <string>zero</string>\n" +
86 " <null/>\n" +
87 " <string>two</string>\n" +
88 " <null/>\n" +
89 "</string-array>";
90
91 assertBothWays(array, expected);
92
93 }
94 }
This page was automatically generated by Maven