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

Move isUnmodifiable assertion to Iterables #3160

Open
wants to merge 5 commits into
base: 3.x
Choose a base branch
from

Conversation

etellman
Copy link
Contributor

Extract finding mutating methods into a separate class,
MutatingMethodFinder which just looks for mutating methods in collections.

Add unit tests for MutatingMethodFinder which test all of the mutating
methods in the supported collection types.

Move the assertion up from AbstractCollectionAssert to
AbstractIterableAssert.

see: #2974

Extract finding mutating methods into a separate class,
MutatingMethodFinder which just looks for mutating methods in collections.

Add unit tests for MutatingMethodFinder which test all of the mutating
methods in the supported collection types.

Move the assertion up from AbstractCollectionAssert to
AbstractIterableAssert.

see: assertj#2974
Add isUnmodifiable() back to AbstractCollectionAssert for binary
compatibility.
If a collection is empty, it doesn't matter what methods like clear()
and remove() do, when checking whether the collection is modifiable. As
long as it isn't possible to add anything, the collection will never
contain any elements.

This matters because throwing UnsupportedOperationException is optional.
If a collection is empty, remove() can either do nothing or throw
UnsupportedOperationException. So if the collection being tested for
unmodifiability is empty, calling remove() doesn't tell you anything
about whether the collection is modifiable.

The current approach is to have lists of pre-approved unmodifiable
collections, but this won't work for collections that aren't one of the
known collections but use no-op for things like remove().
@scordio scordio self-assigned this Jan 1, 2024
@scordio scordio changed the title Move isImmutable() assertion to Iterables Move isUnmodifiable assertion to Iterables Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants