package de.skuzzle.tinyplugz.guice;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;

import org.junit.Assert;
import org.junit.Test;

public class IteratorsTest {

    @SuppressWarnings("unchecked")
                @Test(expected = IllegalArgumentException.class)
                public void testCompositeNullIterator() {
                    Iterators.composite((Iterator[]) null);
                }

    @SuppressWarnings("unchecked")
                @Test(expected = IllegalArgumentException.class)
                public void testCompositeNullIterable() {
                    Iterators.composite((Iterable[]) null);
                }

    @Test
                public void testCompositeSingleIterator() throws Exception {
                    final Iterator<String> it = Collections.emptyIterator();
                    assertSame(it, Iterators.composite(it));
                }

    @Test
                public void testCompositeIterables() throws Exception {
                    final Collection<String> first = Arrays.asList("a", "b");
                    final Collection<String> second = Arrays.asList("c", "d");
                    final Iterable<String> wrapped = Iterators.composite(first, second);
                    final Iterator<String> it = wrapped.iterator();
                    assertEquals("a", it.next());
                    assertEquals("b", it.next());
                    assertEquals("c", it.next());
                    assertEquals("d", it.next());
                    assertFalse(it.hasNext());
                }

    @Test
                public void testCompositeSingleIterable() throws Exception {
                    final Iterable<String> it = Collections.emptyList();
                    assertSame(it, Iterators.composite(it));
                }

    @Test
    @SuppressWarnings("unchecked")
    public void testAllEmpty() {
        final Collection<String> v = new ArrayList<>();
        final Iterator<String>[] enums = (Iterator<String>[])
                new Iterator<?>[] { v.iterator(), v.iterator(), v.iterator() };
        final Iterator<String> ce = Iterators.composite(enums);
        Assert.assertFalse(ce.hasNext());
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testEmptyArray() {
        final Iterator<String>[] enums = (Iterator<String>[]) new Iterator<?>[0];
        final Iterator<String> ce = Iterators.composite(enums);
        Assert.assertFalse(ce.hasNext());
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testMiddleIsEmpty() {
        final Collection<String> empty = new ArrayList<>();
        final Collection<String> oneElement = Arrays.asList("foo");
        final Iterator<String>[] enums = (Iterator<String>[])
                new Iterator<?>[] { oneElement.iterator(), empty.iterator(),
                        oneElement.iterator() };
        final Iterator<String> ce = Iterators.composite(enums);
        Assert.assertEquals("foo", ce.next());
        Assert.assertTrue(ce.hasNext());
        Assert.assertEquals("foo", ce.next());
        Assert.assertFalse(ce.hasNext());
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testFirstIsEmpty() {
        final Collection<String> empty = new ArrayList<>();
        final Collection<String> oneElement = Arrays.asList("foo");
        final Iterator<String>[] enums = (Iterator<String>[])
                new Iterator<?>[] { empty.iterator(), oneElement.iterator(),
                        oneElement.iterator() };
        final Iterator<String> ce = Iterators.composite(enums);
        Assert.assertEquals("foo", ce.next());
        Assert.assertTrue(ce.hasNext());
        Assert.assertEquals("foo", ce.next());
        Assert.assertFalse(ce.hasNext());
    }

    @Test
    @SuppressWarnings("unchecked")
    public void testLastIsEmpty() {
        final Collection<String> empty = new ArrayList<>();
        final Collection<String> oneElement = Arrays.asList("foo");
        final Iterator<String>[] enums = (Iterator<String>[])
                new Iterator<?>[] { oneElement.iterator(), oneElement.iterator(),
                        empty.iterator() };
        final Iterator<String> ce = Iterators.composite(enums);
        Assert.assertEquals("foo", ce.next());
        Assert.assertTrue(ce.hasNext());
        Assert.assertEquals("foo", ce.next());
        Assert.assertFalse(ce.hasNext());
    }

    @SuppressWarnings("unchecked")
    @Test(expected = NoSuchElementException.class)
    public void testNoSuchElementException() {
        final Iterator<String>[] enums = (Iterator<String>[]) new Iterator<?>[0];
        final Iterator<String> ce = Iterators.composite(enums);
        ce.next();
    }
}


@@ -454,36 +454,24 @@
 unchecked%22)%0A
-            
     @Test(ex
@@ -507,36 +507,24 @@
 tion.class)%0A
-            
     public v
@@ -561,36 +561,24 @@
 ) %7B%0A        
-       
-     
 Iterators.co
@@ -601,36 +601,24 @@
 r%5B%5D) null);%0A
-            
     %7D%0A%0A    @
@@ -647,28 +647,16 @@
 ecked%22)%0A
-            
     @Tes
@@ -700,28 +700,16 @@
 .class)%0A
-            
     publ
@@ -746,28 +746,16 @@
 ble() %7B%0A
-            
         
@@ -794,28 +794,16 @@
  null);%0A
-            
     %7D%0A%0A 
@@ -807,36 +807,24 @@
 %0A%0A    @Test%0A
-            
     public v
@@ -872,36 +872,24 @@
 Exception %7B%0A
-            
         fina
@@ -937,36 +937,24 @@
 Iterator();%0A
-            
         asse
@@ -986,36 +986,24 @@
 osite(it));%0A
-            
     %7D%0A%0A    @
@@ -1003,36 +1003,24 @@
 %0A%0A    @Test%0A
-            
     public v
@@ -1071,36 +1071,24 @@
 n %7B%0A        
-      
-      
 final Collec
@@ -1137,36 +1137,24 @@
 %22);%0A        
-     
-       
 final Collec
@@ -1200,28 +1200,16 @@
 , %22d%22);%0A
-            
         
@@ -1277,28 +1277,16 @@
 econd);%0A
-            
         
@@ -1329,36 +1329,24 @@
 iterator();%0A
-            
         asse
@@ -1375,36 +1375,24 @@
 ));%0A        
-       
-     
 assertEquals
@@ -1413,36 +1413,24 @@
 ));%0A        
-     
-       
 assertEquals
@@ -1443,36 +1443,24 @@
 it.next());%0A
-            
         asse
@@ -1481,36 +1481,24 @@
 it.next());%0A
-            
         asse
@@ -1516,36 +1516,24 @@
 hasNext());%0A
-            
     %7D%0A%0A    @
@@ -1537,28 +1537,16 @@
   @Test%0A
-            
     publ
@@ -1610,28 +1610,16 @@
         
-      
-      
 final It
@@ -1663,28 +1663,16 @@
 List();%0A
-            
         
@@ -1712,28 +1712,16 @@
 e(it));%0A
-            
     %7D%0A%0A 
@@ -4627,9 +4627,8 @@
     %7D%0A%7D%0A
-%0A

fix formatting