I have to test someone elses method that runs endlessly but asks for an input:
public void automatize()
{
String cadena = new String();
while(true)
{
System.out.println("Executing...(Enter command)");
System.out.println("Enter Q to exit");
Scanner sc= new Scanner(new InputStreamReader(System.in));
cadena=sc.nextLine();
if(cadena.toLowerCase().equals("q"))
break;
String[] command = str.split(" ");
if(comando.length!=0)
new Extractor().run(command);
}
}
How am I supposed to test this with JUnit?
This is what I've tried to do, but, well, It doesn't actually do anything:
@Test
public void testAutomatize_q() {
ByteArrayInputStream in = new ByteArrayInputStream("Q".getBytes());
System.setIn(in);
extractor.automatize();
System.setIn(System.in);
}