Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstanceOfAssertFactories.array and InstanceOfAssertFactories.array2D expect array type parameter instead of the one for their elements #3386

Open
scordio opened this issue Mar 3, 2024 · 1 comment · May be fixed by #3387
Labels
type: improvement A general improvement
Milestone

Comments

@scordio
Copy link
Member

scordio commented Mar 3, 2024

Currently, InstanceOfAssertFactories.array and InstanceOfAssertFactories.array2D must be used in the following way:

Object array = new Integer[] { 0, 1 };
assertThat(array).asInstanceOf(array(Integer[].class)).containsExactly(0, 1);

Object array2D = new Integer[][] { { 0, 1 }, { 2, 3 } };
assertThat(array2D).asInstanceOf(array2D(Integer[][].class)).hasDimensions(2, 2);

where the array type is provided as a parameter.

However, factories like collection or list expect the element type instead:

Object list = List.of("Homer", "Marge", "Bart", "Lisa", "Maggie");

assertThat(list).asInstanceOf(collection(String.class)).contains("Bart", "Lisa");
assertThat(list).asInstanceOf(list(String.class)).contains("Bart", "Lisa");

We should change the type parameter for array and array2d to be the element type.

@scordio scordio added the type: improvement A general improvement label Mar 3, 2024
@scordio scordio changed the title InstanceOfAssertFactories.array and InstanceOfAssertFactories.array2D expect array type parameter instead of element type parameter InstanceOfAssertFactories.array and InstanceOfAssertFactories.array2D expect type parameter of array itself instead of its elements Mar 3, 2024
@scordio
Copy link
Member Author

scordio commented Mar 3, 2024

Targeting version 4 as such a change is likely to break existing code.

@scordio scordio added this to the 4.0.0 milestone Mar 3, 2024
@scordio scordio changed the title InstanceOfAssertFactories.array and InstanceOfAssertFactories.array2D expect type parameter of array itself instead of its elements InstanceOfAssertFactories.array and InstanceOfAssertFactories.array2D expect array type parameter instead of the one for their elements Mar 3, 2024
@scordio scordio linked a pull request Mar 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A general improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant