### Question:
TypeUtil { public static <T> Map<T, T> arrayToMap(T[] list) { final HashMap<T, T> map = new HashMap<T, T>(); if (list == null) { return map; } if (list.length > 0 && (list.length % 2) == 1) { throw new IllegalArgumentException( "Array must be even in length, representing a series of Key, Value pairs."); } for (int i = 0; i < list.length; i = i + 2) { map.put(list[i], list[i + 1]); } return map; } private  TypeUtil(); static Map<T, T> arrayToMap(T[] list); static Map<String, Object> toMap(JsonObject json); @SuppressWarnings({ "unchecked", "PMD.CollapsibleIfStatements" }) static Class<T> getType(final Object object); static T toObjectType(String data, Class<T> klass); static String toString(final Object obj, final Class<?> klass); static String toString(final Object obj, final Class<?> klass, String methodName); static String toString(final Object obj); static ValueMap toValueMap(final Map<String, ?> map);  }### Answer:
@Test public void testArrayToMap() { String[] list = new String[]{"key1", "value1", "key2", "value2", "key3", "value3"}; Map<String, String> expResult = new HashMap<String, String>(); expResult.put("key1", "value1"); expResult.put("key2", "value2"); expResult.put("key3", "value3"); Map<String, String> result = TypeUtil.arrayToMap(list); assertEquals(expResult, result); }
@Test public void testArrayToMap_oddNummberArray() { String[] list = new String[]{"key1", "value1", "key2", "value2", "value3"}; try { TypeUtil.arrayToMap(list); assertTrue(false); } catch (IllegalArgumentException ex) { assertTrue(true); } }