package ru.agolovin.start;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.junit.Test;

import static org.junit.Assert.assertThat;
import static org.hamcrest.core.Is.is;

/**
 * Test methods for ConsoleInput class.
 *
 * @author agolovin (agolovin@list.ru)
 * @version $Id$
 * @since 0.1
 */
public class ValidateInputTest {
    /**
     * Test method for ask int in the range menu.
     */
    @Test
    public final void whenUserInputInTheRangeThenResultIs() {
        String result = "1";
        int[] range = new int[] {0, 1};
        InputStream in = new ByteArrayInputStream(result.getBytes());
        System.setIn(in);
        ValidateInput validateInput = new ValidateInput();

        int answer = validateInput.ask("test question", range);
        assertThat(Integer.parseInt(result), is(answer));

    }

    /**
     * Test method for ask int not in the range menu.
     */
    @Test
    public final void whenUserInputNotInTheRangeThenResultIs() {

        String input = "1";
        int[] range = new int[] {0, 2};
        InputStream in = new ByteArrayInputStream(input.getBytes());
        System.setIn(in);
        ValidateInput validateInput = new ValidateInput();
        boolean check = false;
        try {
            int answer = validateInput.ask("test question", range);
        } catch (Exception e) {
            check = true;
        }
        assertThat(check, is(true));

    }

}
@@ -17,24 +17,48 @@
 vin.start;%0A%0A
+import org.junit.Test;%0A%0A
 import java.
@@ -61,34 +61,35 @@
 ava.io.ByteArray
-In
+Out
 putStream;%0Aimpor
@@ -98,16 +98,25 @@
 java.io.
+ByteArray
 InputStr
@@ -124,32 +124,75 @@
 am;%0A
-%0A
 import 
-org.junit.Test;%0A
+java.io.PrintStream;%0A%0Aimport static org.hamcrest.core.Is.is;
 %0Aimp
@@ -234,47 +234,8 @@
 hat;
-%0Aimport static org.hamcrest.core.Is.is;
 %0A%0A/*
@@ -580,25 +580,24 @@
  = new int%5B%5D
- 
 %7B0, 1%7D;%0A    
@@ -592,32 +592,41 @@
 %7B0, 1%7D;%0A        
+ByteArray
 InputStream in =
@@ -1092,17 +1092,16 @@
 ew int%5B%5D
- 
 %7B0, 2%7D;%0A
@@ -1108,16 +1108,25 @@
         
+ByteArray
 InputStr
@@ -1263,16 +1263,126 @@
 nput();%0A
+        ByteArrayOutputStream out = new ByteArrayOutputStream();%0A        System.setOut(new PrintStream(out));%0A
         
@@ -1425,37 +1425,24 @@
 %0A           
- int answer =
  validateInp
@@ -1501,24 +1501,156 @@
 eption e) %7B%0A
+            System.out.println(%22Catch Exception%22);%0A        %7D%0A        if (out.toString().contains(%22Please select key from menu.%22)) %7B%0A
             
@@ -1665,32 +1665,33 @@
 true;%0A        %7D%0A
+%0A
         assertTh
@@ -1720,8 +1720,9 @@
     %7D%0A%0A%7D
+%0A

fix task 2.5