1 /*
2 * Copyright 2002-2004 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16 package org.springframework.richclient.settings.support;
17
18 import junit.framework.TestCase;
19
20 /**
21 * @author Peter De Bruycker
22 */
23 public class ArrayUtilTests extends TestCase {
24
25 public void testToIntArray() {
26 String[] stringArray = { "2", "3", "5", "0" };
27 int[] result = ArrayUtil.toIntArray(stringArray);
28
29 assertNotNull(result);
30 assertEquals(stringArray.length, result.length);
31 int expected[] = { 2, 3, 5, 0 };
32
33 for (int i = 0; i < expected.length; i++) {
34 assertEquals(expected[i], result[i]);
35 }
36 }
37
38 public void testToIntArrayInvalidArguments() {
39 String[] stringArray = { "2", "3", "notAnInt", "0" };
40 try {
41 ArrayUtil.toIntArray(stringArray);
42 fail("Should throw IllegalArgumentException");
43 } catch (IllegalArgumentException e) {
44 pass();
45 }
46 }
47
48 private static void pass() {
49 // test passes
50 }
51
52 }