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