public void testToArray_emptyArrayOfObject() { Object[] in = new Object[0]; Object[] array = collection.toArray(in); assertEquals( "toArray(emptyObject[]) should return an array of type Object", Object[].class, array.getClass()); assertEquals("toArray(emptyObject[]).length", getNumElements(), array.length); expectArrayContentsAnyOrder(createSamplesArray(), array); }
@CollectionFeature.Require(KNOWN_ORDER) public void testToArray_oversizedArray_ordered() { E[] array = getSubjectGenerator().createArray(getNumElements() + 2); array[getNumElements()] = e3(); array[getNumElements() + 1] = e3(); assertSame( "toArray(overSizedE[]) should return the given array", array, collection.toArray(array)); List<E> expected = getOrderedElements(); for (int i = 0; i < getNumElements(); i++) { assertEquals(expected.get(i), array[i]); } assertNull( "The array element immediately following the end of the collection should be nulled", array[getNumElements()]); // array[getNumElements() + 1] might or might not have been nulled }
public void testToArray_oversizedArray() { E[] array = getSubjectGenerator().createArray(getNumElements() + 2); array[getNumElements()] = e3(); array[getNumElements() + 1] = e3(); assertSame( "toArray(overSizedE[]) should return the given array", array, collection.toArray(array)); List<E> subArray = Arrays.asList(array).subList(0, getNumElements()); E[] expectedSubArray = createSamplesArray(); for (int i = 0; i < getNumElements(); i++) { assertTrue( "toArray(overSizedE[]) should contain element " + expectedSubArray[i], subArray.contains(expectedSubArray[i])); } assertNull( "The array element immediately following the end of the collection should be nulled", array[getNumElements()]); // array[getNumElements() + 1] might or might not have been nulled }
public void testToArray_rightSizedArrayOfObject() { Object[] array = new Object[getNumElements()]; assertSame( "toArray(sameSizeObject[]) should return the given array", array, collection.toArray(array)); expectArrayContentsAnyOrder(createSamplesArray(), array); }
public void testToArray_noArgs() { Object[] array = collection.toArray(); expectArrayContentsAnyOrder(createSamplesArray(), array); }
@CollectionFeature.Require(KNOWN_ORDER) public void testToArray_rightSizedArrayOfObject_ordered() { Object[] array = new Object[getNumElements()]; assertSame( "toArray(sameSizeObject[]) should return the given array", array, collection.toArray(array)); expectArrayContentsInOrder(getOrderedElements(), array); }
@CollectionFeature.Require(KNOWN_ORDER) public void testToArray_emptyArray_ordered() { E[] empty = getSubjectGenerator().createArray(0); E[] array = collection.toArray(empty); assertEquals( "toArray(emptyT[]) should return an array of type T", empty.getClass(), array.getClass()); assertEquals("toArray(emptyT[]).length:", getNumElements(), array.length); expectArrayContentsInOrder(getOrderedElements(), array); }
private void expectArrayContentsInOrder(List<E> expected, Object[] actual) { assertEquals("toArray() ordered contents: ", expected, Arrays.asList(actual)); }
@CollectionSize.Require(absent = ZERO) public void testToArray_emptyArrayOfWrongTypeForNonEmptyCollection() { try { WrongType[] array = new WrongType[0]; collection.toArray(array); fail("toArray(notAssignableTo[]) should throw"); } catch (ArrayStoreException expected) { } }
@CollectionSize.Require(ZERO) public void testToArray_emptyArrayOfWrongTypeForEmptyCollection() { WrongType[] array = new WrongType[0]; assertSame( "toArray(sameSizeNotAssignableTo[]) should return the given array", array, collection.toArray(array)); }
@CollectionFeature.Require(KNOWN_ORDER) public void testToArray_rightSizedArray_ordered() { E[] array = getSubjectGenerator().createArray(getNumElements()); assertSame( "toArray(sameSizeE[]) should return the given array", array, collection.toArray(array)); expectArrayContentsInOrder(getOrderedElements(), array); }
public void testToArray_rightSizedArray() { E[] array = getSubjectGenerator().createArray(getNumElements()); assertSame( "toArray(sameSizeE[]) should return the given array", array, collection.toArray(array)); expectArrayContentsAnyOrder(createSamplesArray(), array); }
@CollectionFeature.Require(KNOWN_ORDER) public void testToArray_emptyArray_ordered() { E[] empty = getSubjectGenerator().createArray(0); E[] array = collection.toArray(empty); assertEquals("toArray(emptyT[]) should return an array of type T", empty.getClass(), array.getClass()); assertEquals("toArray(emptyT[]).length:", getNumElements(), array.length); expectArrayContentsInOrder(getOrderedElements(), array); }
public void testToArray_noArgs() { Object[] array = collection.toArray(); expectArrayContentsAnyOrder(createSamplesArray(), array); }
/** * {@link Collection#toArray(Object[])} says: "Note that <tt>toArray(new Object[0])</tt> is * identical in function to <tt>toArray()</tt>." * * <p>For maximum effect, the collection under test should be created from an element array of a * type other than {@code Object[]}. */ public void testToArray_isPlainObjectArray() { Object[] array = collection.toArray(); assertEquals(Object[].class, array.getClass()); }
@CollectionSize.Require(absent = ZERO) public void testToArray_emptyArrayOfWrongTypeForNonEmptyCollection() { try { WrongType[] array = new WrongType[0]; collection.toArray(array); fail("toArray(notAssignableTo[]) should throw"); } catch (ArrayStoreException expected) { } }
@CollectionSize.Require(ZERO) public void testToArray_emptyArrayOfWrongTypeForEmptyCollection() { WrongType[] array = new WrongType[0]; assertSame( "toArray(sameSizeNotAssignableTo[]) should return the given array", array, collection.toArray(array)); }
public void testToArray_emptyArray() { E[] empty = getSubjectGenerator().createArray(0); E[] array = collection.toArray(empty); assertEquals( "toArray(emptyT[]) should return an array of type T", empty.getClass(), array.getClass()); assertEquals("toArray(emptyT[]).length:", getNumElements(), array.length); expectArrayContentsAnyOrder(createSamplesArray(), array); }
@CollectionFeature.Require(KNOWN_ORDER) public void testToArray_rightSizedArrayOfObject_ordered() { Object[] array = new Object[getNumElements()]; assertSame("toArray(sameSizeObject[]) should return the given array", array, collection.toArray(array)); expectArrayContentsInOrder(getOrderedElements(), array); }
public void testToArray_rightSizedArrayOfObject() { Object[] array = new Object[getNumElements()]; assertSame( "toArray(sameSizeObject[]) should return the given array", array, collection.toArray(array)); expectArrayContentsAnyOrder(createSamplesArray(), array); }