### Question:
Maps { public static <K, V, T> T[] toArray(Map<K, V> map, T[] entryArray) { return toList(map, entryArray.getClass().getComponentType()).toArray(entryArray); } private  Maps(); @SuppressWarnings("unchecked") static Map<K, V> toMap(List<T> entryList); static Map<K, V> toMap(T[] entryArray); static T[] toArray(Map<K, V> map, T[] entryArray); static List<T> toList(Map<K, V> map, Class<T> entryClass);  }### Answer:
@Test public void testToArray_sufficientSize() { Entry[] arrayToFill = new Entry[entriesList.size()]; Entry[] expectedArray = entriesList.toArray(arrayToFill); Entry[] actualArray = Maps.<String, String, Entry>toArray(entriesMap, arrayToFill); assertArrayEquals(expectedArray, actualArray); assertSame( "toArray should not have created a new array since the input array was large enough", arrayToFill, actualArray); }
@Test public void testToArray_insufficientSize() { Entry[] arrayToFill = new Entry[0]; Entry[] expectedArray = entriesList.toArray(arrayToFill); Entry[] actualArray = Maps.<String, String, Entry>toArray(entriesMap, arrayToFill); assertArrayEquals(expectedArray, actualArray); assertNotSame( "toArray should have created a new array since the input array was not large enough", arrayToFill, actualArray); }