There is nothing special about this implementation. We should simply overwrite the default constructor and assign a new instance to the ticTacToeCollection variable.
To begin with, we should add a local variable and a getter for TicTacToeCollection:
private TicTacToeCollection ticTacToeCollection; protected TicTacToeCollection getTicTacToeCollection() { return ticTacToeCollection; }
Now all that's left is to instantiate a new collection and assign it to the variable when the main class is instantiated:
public TicTacToe() throws UnknownHostException { this(new TicTacToeCollection()); } protected TicTacToe(TicTacToeCollection collection) { ticTacToeCollection = collection; }
We also created another way to instantiate the class by passing TicTacToeCollection as an argument. This will come in handy inside specifications as an easy way to pass a mocked collection.
Now let us go back to the specifications class and make use of this new constructor.