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

isUnmodifiable assertion for Iterator instances #3458

Closed
scordio opened this issue May 5, 2024 · 3 comments · Fixed by #3477
Closed

isUnmodifiable assertion for Iterator instances #3458

scordio opened this issue May 5, 2024 · 3 comments · Fixed by #3477
Assignees
Labels
type: new feature A new feature

Comments

@scordio
Copy link
Member

scordio commented May 5, 2024

Feature summary

Similarly to #2102, we could have an isUnmodifiable() assertion for Iterator types.

Example

Iterator<Integer> iterator = Collections.unmodifiableList(Arrays.asList(1, 2, 3)).iterator();

assertThat(iterator).isUnmodifiable();
@scordio scordio added the type: new feature A new feature label May 5, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 14, 2024
@dehasi
Copy link
Contributor

dehasi commented May 14, 2024

@scordio if nobody works on this task, I'd like to pick it up. And it seems a bit more challenging than for collections :)

@scordio
Copy link
Member Author

scordio commented May 14, 2024

Sure and thanks, @dehasi!

What challenges have you encountered?

@dehasi
Copy link
Contributor

dehasi commented May 14, 2024

To be short, I can't rely on that iterator.remove() will throw UnsupportedOperationException.

I.e. Collections.EmptyIterator.remove() throws IllegalStateException. Do we treat EmptyIterator as unmodifiable?

But can't rely on IllegalStateException as unmodifiability marker. ArrayList<>().itertator() can also throw IllegalStateException if we haven't called next.

Initially, I wanted to check unmodifiability by just calling iterator.remove(). It's not enough (see to ArrayList example).
Now, I'm thinking of making an additional check like iterator.next(); iterator.remove(). However, it will look a bit weird.

dehasi pushed a commit to dehasi/assertj that referenced this issue May 15, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 15, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 15, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 15, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 15, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 15, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 15, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 16, 2024
dehasi pushed a commit to dehasi/assertj that referenced this issue May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: new feature A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants