Interface ToArrayContract<E,C extends Collection<E>>
- Type Parameters:
E
- The element type being tested.C
- The collection type being tested.
- All Superinterfaces:
CollectionContractConfig
,CollectionContractSupport<E,
,C> CollectionProviderSupport<E,
,C> ContractSupport<C>
,ElementProviderSupport<E>
,ProviderSupport<C>
,SupportedMethods
- All Known Subinterfaces:
CollectionContract<E,
,C> ListContract<E,
,L> ListToArrayContract<E,
,L> SequencedCollectionContract<E,
C>
This interface tests if a collection class has implemented the
toArray
method
correctly.- Since:
- 1.0.0
- Author:
- evanbergstrom
- See Also:
-
Field Summary
Fields inherited from interface org.soliscode.test.contract.support.CollectionContractSupport
DEFAULT_SIZE
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
Tests that thetoArray()
method works for a collection with elements.default void
Tests that thetoArray()
method returns a safe array that can be modified without changing the elements of the container.default void
Tests that thetoArray()
method works for an empty collection.default void
Tests that thetoArray(T[])
method works for a collection with elements.default void
Tests that thetoArray(T[])
method works for an empty collection.default void
Tests that thetoArray(T[])
method throws on a null array.Methods inherited from interface org.soliscode.test.contract.CollectionContractConfig
permitDuplicates, permitIncompatibleTypes, permitNulls
Methods inherited from interface org.soliscode.test.contract.support.CollectionProviderSupport
provider
Methods inherited from interface org.soliscode.test.contract.support.ElementProviderSupport
elementProvider
Methods inherited from interface org.soliscode.test.SupportedMethods
supportsMethod
-
Method Details
-
testToArrayOnEmptyCollection
@Test @DisplayName("The toArray method works on an empty container.") default void testToArrayOnEmptyCollection()Tests that thetoArray()
method works for an empty collection. -
testToArray
@Test @DisplayName("The toArray method works on a container with elements") default void testToArray()Tests that thetoArray()
method works for a collection with elements. -
testToArrayIsSafe
@Test @DisplayName("The toArray method returns a safe array") default void testToArrayIsSafe()Tests that thetoArray()
method returns a safe array that can be modified without changing the elements of the container. -
testToArrayStoreOnEmptyCollection
@Test @DisplayName("The toArray method works on an empty container.") default void testToArrayStoreOnEmptyCollection()Tests that thetoArray(T[])
method works for an empty collection. -
testToArrayStore
@Test @DisplayName("The toArray method works on a container with elements") default void testToArrayStore()Tests that thetoArray(T[])
method works for a collection with elements. -
testToArrayStoreThrowsOnNullArray
@Test @DisplayName("The toArray(T[]) method throws on a null array.") default void testToArrayStoreThrowsOnNullArray()Tests that the
toArray(T[])
method throws on a null array.Implementation Notes
This test checks that the
toArray(T[])
function throws the correct exception if it is called on a null value. IntelliJ will detect a problem when it is called with a null argument since the method declaration has a NotNull annotation. Since this is what we are trying to test, the inspection is suppressed here.Any implementations that use the
NotNull
annotation for the collection parameter may throw anIllegalArgumentException
here, so either exception type is accepted.
-