/*
 * Copyright (c) 2012 Ray A. Conner
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.github.rconner.util;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

/**
 * Helper methods for other tests, and tests for those methods (which is why this class is named ...Test, so maven will
 * pick it up).
 */
public class IterableTest {

    // TODO: These should really be hamcrest Matcher implementations. I'm sure these already exist somewhere,
    // but it's not in the junit jar.

    public static <E> void assertIteratorEmpty( Iterator<E> i ) {
        assertThat( i.hasNext(), is( false ) );
        try {
            i.next();
            fail( "Should throw NoSuchElementException." );
        } catch( NoSuchElementException ignored ) {
            // expected
        }
    }

    @Test
    public void testAssertIteratorEmpty() {
        assertIteratorEmpty( Iterators.emptyIterator() );
    }

    public static <E> void assertIteratorContains( Iterator<E> i, Object... elements ) {
        assertThat( Lists.<Object>newArrayList( i ), is( Arrays.asList( elements ) ) );
        assertIteratorEmpty( i );
    }

    @Test
    public void testAssertIteratorContains() {
        assertIteratorContains( Iterators.emptyIterator() );
        assertIteratorContains( Arrays.asList( 2 ).iterator(), 2 );
        assertIteratorContains( Arrays.asList( 3, 5 ).iterator(), 3, 5 );
        assertIteratorContains( Arrays.asList( 7, 11, 13, 17, 19 ).iterator(), 7, 11, 13, 17, 19 );
    }

    public static void assertIteratorsEqual( Iterator<?> a, Iterator<?> b ) {
        assertThat( Lists.newArrayList( a ), is( Lists.newArrayList( b ) ) );
        assertIteratorEmpty( a );
        assertIteratorEmpty( b );
    }
}

@@ -1149,16 +1149,60 @@
 .util;%0A%0A
+import com.google.common.collect.Iterables;%0A
 import c
@@ -2273,36 +2273,32 @@
    public static
- %3CE%3E
  void assertIter
@@ -2297,32 +2297,30 @@
 sertIterator
-Contains
+sEqual
 ( Iterator%3CE
@@ -2322,108 +2322,245 @@
 tor%3C
-E%3E i, Object... elements ) %7B%0A        assertThat( Lists.%3CObject%3EnewArrayList( i ), is( Arrays.asList(
+?%3E a, Iterator%3C?%3E b ) %7B%0A        assertThat( Iterators.elementsEqual( a, b ), is( true ) );%0A        assertIteratorEmpty( a );%0A        assertIteratorEmpty( b );%0A    %7D%0A%0A    public static void assertIteratorContains( Iterator%3C?%3E i, Object...
  ele
@@ -2567,20 +2567,17 @@
 ments ) 
-) );
+%7B
 %0A       
@@ -2595,16 +2595,55 @@
 ator
-Empty( i
+sEqual( i, Arrays.asList( elements ).iterator()
  );%0A
@@ -3042,35 +3042,35 @@
 void assertItera
-tor
+ble
 sEqual( Iterator
@@ -3058,35 +3058,35 @@
 blesEqual( Itera
-tor
+ble
 %3C?%3E a, Iterator%3C
@@ -3073,35 +3073,35 @@
 able%3C?%3E a, Itera
-tor
+ble
 %3C?%3E b ) %7B%0A      
@@ -3118,130 +3118,51 @@
 at( 
-Lists.newArrayList( a ), is( Lists.newArrayList( b ) ) );%0A        assertIteratorEmpty( a );%0A        assertIteratorEmpty( b
+Iterables.elementsEqual( a, b ), is( true )
  );%0A

Make this more efficient. No reason to create new lists.