ArrayUtils { public static <T> T[] mergeArrays(T[] one, T[] two) { T[] mergedArray = Arrays.copyOf(one, one.length + two.length); System.arraycopy(two, 0, mergedArray, one.length, two.length); return mergedArray; }  static T[] mergeArrays(T[] one, T[] two); static boolean keysPresentInColumns(String[] keys, String[] columns); static String[] convertStringKeyToArray(String keys, String delimiter); static String[] convertStringKeyToArray(String keys); static int[] getCompareColumnsPosition(String[] columns, String[] keyColumns); static List<Integer> getColumnsPosition(String[] columns, String[] keyColumns); static boolean isIndexOfLastArrayElement(String[] array, int elementIndex);  }
@Test public void testMergeArrays() throws Exception { String[] one = new String[] { "one", "two" }; String[] two = new String[] { "three", "four" }; String[] result = new String[] { "one", "two", "three", "four" }; String[] mergedResult = ArrayUtils.mergeArrays(one, two); Assert.assertEquals(result[0], mergedResult[0]); Assert.assertEquals(result[1], mergedResult[1]); Assert.assertEquals(result[2], mergedResult[2]); Assert.assertEquals(result[3], mergedResult[3]); }
@Test(expected = NullPointerException.class) public void testMergeIfOneOFTheArraysIsNull() throws Exception { String[] one = new String[] { "one", "two" }; String[] two = new String[] { "three", "four" }; String[] result = new String[] { "one", "two", "three", "four" }; Assert.assertEquals(result, ArrayUtils.mergeArrays(one, null)); Assert.assertEquals(0, ArrayUtils.mergeArrays(null, null).length); Assert.assertEquals(two, ArrayUtils.mergeArrays(null, two)); }
@Test public void testMergeIfOneOFTheArraysIsEmpty() throws Exception { String[] one = new String[] { "one", "two" }; String[] two = new String[] { "three", "four" }; String[] empty = new String[] {}; String[] result = new String[] { "one", "two", "three", "four" }; Assert.assertEquals(one.length, ArrayUtils.mergeArrays(one, empty).length); Assert.assertEquals(0, ArrayUtils.mergeArrays(empty, empty).length); Assert.assertEquals(two.length, ArrayUtils.mergeArrays(empty, two).length); }