/** * Tests {@link Maps#toArray(Map, Object[])} when the input array is large enough to hold all * entries in the supplied map. */ @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); }
/** * Tests {@link Maps#toArray(Map, Object[])} when the input array is not large enough to hold all * entries in the supplied map. */ @Test public void testToArray_insufficientSize() { // Intentionally make the input array too small to fit all entries in the map. 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); }