Requirement 4 – the game's output

Next, we should let the player know the status of the game.

We want feedback when either an event or an error occurs within the game. The output shows the status of the board on every move.

As we are throwing exceptions when an error occurs, this is already covered, so we only need to implement these two tests. Furthermore, for the sake of testability, we need to introduce a parameter within the constructor. By introducing this parameter, the output becomes easier to test:

private OutputStream output; @Before public void beforeEachTest() { output = new ByteArrayOutputStream(); tested = new Connect4TDD(new PrintStream(output)); } @Test public void whenAskedForCurrentPlayerTheOutputNotice() { tested.getCurrentPlayer(); ...

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.