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.3
 * Create iterator for simple numbers
 *
 * @author Anton Vasilyuk
 * @version 1.0
 * @since 0.1
 */

public class IteratorSimpleNumbersTest {

    /**.
     * Method for check method Next
     */
    @Test
    public void whenNeedTakeAwayOnlySimpleNumbersThenDoIt() {
        int checkNum = 0;
        int[] array = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
        IteratorSimpleNumbers iter = new IteratorSimpleNumbers(array);
        int[] testArray = {2, 3, 5, 7, 11};
        int[] resultArray = new int[5];

        for (int i = 0; i < resultArray.length; i++) {
            resultArray[i] = (Integer) iter.next();
            if(resultArray[i] != testArray[i]) {checkNum++;}
        }
        boolean fact = true;
        boolean expect = true;
        if(checkNum != 0) {fact = false;}
        assertThat(fact, is(expect));
    }

    /**.
     * Test working hasNext
     */
    @Test
    public void whenIterateTwoTimeArrayThenHasNextReturnTrue() {
        int[] array = {2, 3, 4, 5};
        IteratorSimpleNumbers iter = new IteratorSimpleNumbers(array);
        iter.next();
        iter.next();
        boolean result = iter.hasNext();
        assertThat(result, is(true));
    }

    /**.
     * Test working hasNext if not simple numbers
     */
    @Test
    public void whenInArrayNotSimpleNumberThenHasNextReturnFalse() {
        int[] array = {4, 6, 8, 9};
        IteratorSimpleNumbers iter = new IteratorSimpleNumbers(array);
        boolean result = iter.hasNext();
        assertThat(result, is(false));
    }

    /**.
     * Test working hasNext if in array not numbers
     */
    @Test
    public void whenInArrayNoElementThenHasNextReturnNEE() {
        int[] value = null;
        IteratorSimpleNumbers iter = new IteratorSimpleNumbers(value);
        try {
            iter.hasNext();
        } catch (NoSuchElementException nee) {
            assertThat(nee.getMessage(), is("In this array not element"));
        }
    }
}
@@ -471,32 +471,34 @@
 0;%0A        int%5B%5D
+%5B%5D
  array = %7B2, 3, 
@@ -494,39 +494,23 @@
 y = 
+%7B
 %7B2, 3
-, 4, 5, 6
+%7D
 , 
+%7B
 7, 8
-, 9, 10, 11
+%7D
 %7D;%0A 
@@ -616,16 +616,9 @@
  3, 
-5, 7, 11
+7
 %7D;%0A 
@@ -652,17 +652,17 @@
 new int%5B
-5
+3
 %5D;%0A%0A    
@@ -1097,11 +1097,12 @@
 turn
-Tru
+fals
 e() 
@@ -1108,32 +1108,34 @@
  %7B%0A        int%5B%5D
+%5B%5D
  array = %7B2, 3, 
@@ -1131,20 +1131,28 @@
 y = 
+%7B
 %7B2, 3, 
+11%7D, %7B
 4, 5%7D
+%7D
 ;%0A  
@@ -1507,16 +1507,18 @@
    int%5B%5D
+%5B%5D
  array =
@@ -1522,20 +1522,24 @@
 y = 
+%7B
 %7B4, 6
+%7D
 , 
+%7B
 8, 9%7D
+%7D
 ;%0A  
@@ -1847,16 +1847,18 @@
    int%5B%5D
+%5B%5D
  value =
@@ -2095,24 +2095,24 @@
 element%22));%0A
-
         %7D%0A  
@@ -2114,10 +2114,262 @@
  %7D%0A    %7D
+%0A%0A    /**.%0A     * Test when is one array%0A     */%0A    @Test%0A    public void whenIsOneArray() %7B%0A        IteratorSimpleNumbers it = new IteratorSimpleNumbers(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.3