@Test(expected = ArrayStoreException.class) public void testMergeArraysNativeIllegalType() { char[] chars = {'a', 'b', 'c'}; int[] integers = {1, 2, 3}; // Integer not assignable to String CollectionUtil.mergeArrays(chars, integers); }
@Test(expected = ArrayStoreException.class) public void testMergeArraysObjectIllegalType() { String[] strings = {"foo", "bar", "baz"}; Integer[] integers = {1, 2, 3}; // Integer not assignable to String CollectionUtil.mergeArrays(strings, integers); }
@Test public void testMergeArraysObjectAssignable() { Integer[] integers = {1, 2, 3}; // Integer assignable to Object Object[] merged = (Object[]) CollectionUtil.mergeArrays(stringObjects, integers); assertArrayEquals(new Object[] {"foo", "bar", "baz", 1, 2, 3}, merged); }
@Test public void testMergeArraysNative() { char[] chars = {'a', 'b', 'c'}; char[] more = {'x', 'y', 'z'}; char[] merged = (char[]) CollectionUtil.mergeArrays(chars, more); assertArrayEquals(new char[] {'a', 'b', 'c', 'x', 'y', 'z'}, merged); }
@Test(expected = IndexOutOfBoundsException.class) public void testMergeArraysObjectNegativeSecondLength() { CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, -1); }
@Test(expected = IndexOutOfBoundsException.class) public void testMergeArraysObjectBadSecondOffset() { CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 4, 1); }
@Test public void testMergeArraysObjectOffset() { Object[] merged = (Object[]) CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, 1); assertArrayEquals(new Object[] {"bar", "baz", 3}, merged); }