/**
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
 */
package com.codeup.movies.console;

import com.codeup.console.Console;
import com.codeup.validation.NonEmptyString;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class CategoriesConsoleTest {

    @Test
    public void it_accepts_a_valid_category_name() {
        String categoryName = "action";
        when(console.promptForText(anyString(), any(NonEmptyString.class)))
            .thenReturn(categoryName)
        ;
        assertThat(categoriesConsole.askForCategoryName(), is(categoryName));
    }

    @Before
    public void configureConsole() {
        categoriesConsole = new CategoriesConsole(console);
    }

    @Mock
    private Console console;
    private CategoriesConsole categoriesConsole;
}

@@ -177,78 +177,8 @@
 le;%0A
-import com.codeup.validation.NonEmptyString;%0Aimport org.junit.Before;%0A
 impo
@@ -313,78 +313,92 @@
 ort 
-static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.*;
+java.io.ByteArrayInputStream;%0Aimport java.io.PrintStream;%0Aimport java.util.Scanner;%0A
 %0Aimp
@@ -408,32 +408,37 @@
  static org.
-mockito.
+hamcrest.Core
 Matchers.any
@@ -434,19 +434,23 @@
 atchers.
-any
+equalTo
 ;%0Aimport
@@ -465,74 +465,66 @@
 org.
-mockito.Matchers.anyString;%0Aimport static org.mockito.Mockito.when
+hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.*
 ;%0A%0A@
@@ -594,17 +594,16 @@
 eTest %7B%0A
-%0A
     @Tes
@@ -669,140 +669,271 @@
     
-String categoryName = %22action%22;%0A        when(console.promptForText(anyString(), any(NonEmptyString.class)))%0A            .thenReturn(
+console = aConsoleWithInput(categoryName);%0A%0A        assertThat(console.askForCategoryName(), is(equalTo(categoryName)));%0A    %7D%0A%0A    @Test%0A    public void it_keeps_prompting_until_a_valid_name_is_given() %7B%0A        console = aConsoleWithInput(emptyText, emptyText, 
 cate
@@ -945,18 +945,10 @@
 ame)
-%0A        
 ;
+%0A
 %0A   
@@ -964,26 +964,16 @@
 rtThat(c
-ategoriesC
 onsole.a
@@ -996,16 +996,24 @@
 e(), is(
+equalTo(
 category
@@ -1018,16 +1018,17 @@
 ryName))
+)
 ;%0A    %7D%0A
@@ -1036,80 +1036,215 @@
     
-@Before%0A    public void configureConsole() %7B%0A        categoriesConsole =
+private CategoriesConsole aConsoleWithInput(String... userInput) %7B%0A        ByteArrayInputStream input = new ByteArrayInputStream(%0A            String.join(%22%5Cn%22, userInput).getBytes()%0A        );%0A        return
  new
@@ -1266,34 +1266,109 @@
 ole(
-c
+new C
 onsole
-);%0A    %7D%0A%0A    @Mock
+(%0A            new Scanner(input).useDelimiter(%22%5Cn%22),%0A            output%0A        ));%0A    %7D%0A
 %0A   
@@ -1376,16 +1376,26 @@
 private 
+Categories
 Console 
@@ -1403,16 +1403,17 @@
 onsole;%0A
+%0A
     priv
@@ -1420,43 +1420,132 @@
 ate 
-CategoriesConsole categoriesConsole
+final String categoryName = %22action%22;%0A    private final String emptyText = %22    %22;%0A%0A    @Mock%0A    private PrintStream output
 ;%0A%7D%0A

Add test to verify that the console prompts more than once if needed.