1
2
3
4
5
6
7 package org.mule.util;
8
9 import org.mule.tck.junit4.AbstractMuleTestCase;
10
11 import java.util.List;
12
13 import org.junit.Test;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.assertSame;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20
21 public class ArrayUtilsTestCase extends AbstractMuleTestCase
22 {
23
24 @Test
25 public void testToArrayOfComponentType()
26 {
27
28 assertNull(ArrayUtils.toArrayOfComponentType(null, String.class));
29
30
31 String[] a = new String[]{};
32 String[] a2 = (String[])ArrayUtils.toArrayOfComponentType(a, String.class);
33 assertSame(a2, a);
34
35
36 try
37 {
38 ArrayUtils.toArrayOfComponentType(a, null);
39 fail();
40 }
41 catch (IllegalArgumentException iex)
42 {
43
44 }
45
46
47 a = new String[]{":-)"};
48 CharSequence[] cs = (CharSequence[])ArrayUtils.toArrayOfComponentType(a, CharSequence.class);
49 assertEquals(a.length, cs.length);
50 assertSame(a[0], cs[0]);
51
52
53 try
54 {
55 ArrayUtils.toArrayOfComponentType(a, List.class);
56 fail();
57 }
58 catch (ArrayStoreException asx)
59 {
60
61 }
62
63 }
64
65 @Test
66 public void testToStringMaxLength()
67 {
68 Object test = new byte[100];
69 for (int i = 0; i < ((byte[])test).length; i++)
70 {
71 ((byte[])test)[i] = (byte)i;
72 }
73
74
75 String result = ArrayUtils.toString(test, 10);
76 assertTrue(result.endsWith("[..]}"));
77 assertEquals(9, StringUtils.countMatches(result, ","));
78 }
79
80 }