How do i test for the equality of two iterators using JUnit?
Is there any built in method or is it just by comparing each and every element in that?
Thanks,
Sriram
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no sane way to test equality of
Iterators.If going insane in this is an option, you may want to delve into the implementation of the specific iterator type you are testing, and use reflection to access private stuff and compare that (I’m sure, with enough analysis of source code, that you would find what needs to hold for two ListIterators to be equal, for example).
Or if it’s your own iterator type, then export some variables that help you out and use them instead of reflection.
Iterating through and comparing elements is only a weak guarantee, as you could be iterating over a clone of your collection, meaning the iterators look the same, but aren’t.
Just don’t do this.