Question: Refactor the ConsoleUI class to make it more reusable and testable. This can be achieved by separating the input and output streams from the business

Refactor the ConsoleUI class to make it more reusable and testable. This can be achieved by separating the input and output streams from the business logic. Consider passing in input and output streams as arguments to the constructor (see the next slide). - Write a JUnit test class named ConsoleUITest to test every public method, including the constructors. - In ConsoleUITest, use a ByteArrayinputStream to simulate user input and a ByteArrayOutputStream to capture the output from ConsoleUl. This will enable us to test ConsoleUI in isolation without relying on the actual console input and output (see next slide). II corverting a string to an InputStream String testinput = "7 8in" InputStream in = new ByteArraylnputStream(testinput getBytes()), ByteArrayOutputStream result = new ByteArrayOutputStream(). PrintStream out = new PrintStream(result, true); /I true for auto flushing ConsoleUI ui= new ConsoleUI(board, in, out): Read from testingut wi. printMessage("Welcome to Omokl"), Il print fo result and print ta resuit. II use result tosting0 to find out what is printed int index = ui.promptMove(player); ,ll read the string "7 8in " from testhout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
