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

IterableAssert.startsWith tries to evaluate size of collection (2.0M10) #154

Open
mpi opened this issue Jun 9, 2013 · 0 comments
Open

Comments

@mpi
Copy link

mpi commented Jun 9, 2013

IterableAssert.startsWith checks size of actual iterable:
if (sizeOf(actual) < sequenceSize) {

this causes infinite loop for inifinite iterables. Test case:

public void shouldNotEvaluateAllCollection() throws Exception {

    Iterable<Integer> list = infiniteListOfNumbers();
    assertThat(list).startsWith(1, 2, 3, 4, 5);

}

private Iterable<Integer> infiniteListOfNumbers() {

    return new Iterable<Integer>() {

        int number = 1;

        @Override
        public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {

                @Override
                public boolean hasNext() {
                    return true;
                }

                @Override
                public Integer next() {
                    return number++;
                }

                @Override
                public void remove() {
                }
            };
        }
    };
}
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

No branches or pull requests

1 participant