### Question:
ReflectionUtils { public static Object instantiatePrimitiveArray(Class<?> type, String[] values) { logger.entering(new Object[] { type, values }); validateParams(type, values); checkArgument(isPrimitiveArray(type), type + " is NOT a primitive array type."); Class<?> componentType = type.getComponentType(); Object arrayToReturn = Array.newInstance(componentType, values.length); Method parserMethod = getParserMethod(componentType); for (int i = 0; i < values.length; i++) { try { Array.set(arrayToReturn, i, parserMethod.invoke(arrayToReturn, values[i])); } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { throw new ReflectionException(e); } } logger.exiting(arrayToReturn); return arrayToReturn; } private  ReflectionUtils(); static boolean hasOneArgStringConstructor(Class<?> type); static boolean hasDefaultConstructor(Class<?> type); static Object instantiateDefaultCustomTypeArray(DefaultCustomType type, String[] values); static Object instantiatePrimitiveArray(Class<?> type, String[] values); static Object instantiatePrimitiveObject(Class<?> type, Object objectToInvokeUpon, String valueToAssign); static Object instantiateWrapperArray(Class<?> type, String[] values); static Object instantiateWrapperObject(Class<?> type, Object objectToInvokeUpon, String valueToAssign); static boolean isPrimitiveArray(Class<?> type); static boolean isWrapperArray(Class<?> type);  }### Answer:
@Test(groups = "unit") public void testInstantiatePrimitiveArray() { Object obj = ReflectionUtils.instantiatePrimitiveArray(int[].class, new String[] { "1" }); assertTrue(obj != null); assertTrue(obj instanceof int[]); assertTrue(((int[]) obj).length == 1); assertEquals(((int[]) obj)[0], 1); }
@Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) public void testInstantiatePrimitiveArrayErrorCondition1() { ReflectionUtils.instantiatePrimitiveArray(String[].class, new String[] { "1" }); }
@Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) public void testInstantiatePrimitiveArrayErrorCondition2() { ReflectionUtils.instantiatePrimitiveArray(null, new String[] { "1" }); }
@Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) public void testInstantiatePrimitiveArrayErrorCondition3() { ReflectionUtils.instantiatePrimitiveArray(int[].class, null); }
@Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) public void testInstantiatePrimitiveArrayErrorCondition4() { ReflectionUtils.instantiatePrimitiveArray(int[].class, new String[] {}); }
@Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) public void testInstantiatePrimitiveArrayErrorCondition5() { ReflectionUtils.instantiatePrimitiveArray(int[][].class, new String[] { "1" }); }
@Test(groups = "unit", expectedExceptions = { ReflectionException.class }) public void testInstantiatePrimitiveArrayErrorCondition6() { ReflectionUtils.instantiatePrimitiveArray(int[].class, new String[] { "one" }); }