package ru.job4j;

import org.junit.Test;

import java.util.NoSuchElementException;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;

/**
 * Task 4.1.2
 * Test create Iterator even numbers
 *
 * @author Anton Vasilyuk on 03.06.2017.
 * @version 1.0
 * @since 0.1
 */

public class IteratorEvenNumbersTest {

    /**.
     * Testing Iterator for even numbers
     */
    @Test
    public void whenNeedAddOnlyEvenNumbers() {
        IteratorEvenNumbers iter = new IteratorEvenNumbers(new int[] {1, 2, 3, 4});
        int[] arrayResult = new int[2];
        int[] check = {2, 4};

        for (int i = 0; i < arrayResult.length; i++) {
            arrayResult[i] = (Integer) iter.next();
        }

        boolean expect = true;
        boolean fact = true;
        for (int i = 0; i < arrayResult.length; i++) {
            if (arrayResult[i] != check[i]) {fact = false;}
        }
        assertThat(fact, is(expect));
    }

    @Test
    public void whenIterateOneTimeThenHasNextReturnTrue() {
        IteratorEvenNumbers iter = new IteratorEvenNumbers(new int[] {1, 2, 3, 4});
        iter.next();
        boolean result = iter.hasNext();
        assertThat(result, is(true));
    }

    @Test
    public void whenIterateTwoTimeThenHasNextReturnFalse() {
        IteratorEvenNumbers iter = new IteratorEvenNumbers(new int[] {1, 2, 3, 4});
        iter.next();
        iter.next();
        boolean result = iter.hasNext();
        assertThat(result, is(false));
    }

    @Test
    public void whenArrayIsNullThenHasNextReturnNEE() {
        int[] value = null;
        IteratorEvenNumbers iter = new IteratorEvenNumbers(value);
        try {
            iter.hasNext();
        } catch (NoSuchElementException nee) {
            assertThat(nee.getMessage(), is("No element in this array."));
        }
    }
}
@@ -506,37 +506,43 @@
 rs(new int%5B%5D
- 
+%5B%5D %7B
 %7B1, 2
+%7D
 , 
+%7B
 3, 4%7D
+%7D
 );%0A        i
@@ -725,39 +725,8 @@
  %7D%0A%0A
-        boolean expect = true;%0A
     
@@ -907,14 +907,12 @@
  is(
-expect
+true
 ));%0A
@@ -1052,37 +1052,43 @@
 rs(new int%5B%5D
- 
+%5B%5D %7B
 %7B1, 2
+%7D
 , 
+%7B
 3, 4%7D
+%7D
 );%0A        i
@@ -1328,21 +1328,27 @@
 nt%5B%5D
- 
+%5B%5D %7B
 %7B1, 2
+%7D
 , 
+%7B
 3, 4%7D
+%7D
 );%0A 
@@ -1554,16 +1554,18 @@
    int%5B%5D
+%5B%5D
  value =
@@ -1798,24 +1798,24 @@
  array.%22));%0A
-
         %7D%0A  
@@ -1817,10 +1817,258 @@
  %7D%0A    %7D
+%0A%0A    /**.%0A     * Test when is one array%0A     */%0A    @Test%0A    public void whenIsOneArray() %7B%0A        IteratorEvenNumbers it = new IteratorEvenNumbers(new int%5B%5D%5B%5D %7B%7B1, 2, 3, 4%7D%7D);%0A        it.next();%0A        assertThat(it.hasNext(), is(true));%0A    %7D
 %0A%7D

add file for chapter_003_4.1.2