Implementation

Let us just add a try/catch block:

public boolean drop() { 
  try { 
    getMongoCollection().drop();
    return true; 
  } catch (Exception e) {
    return false; 
  } 
} 

With this implementation, we are finished with the TicTacToeCollection class that acts as a layer between our main class and MongoDB.

The source code can be found in the 02-save-move branch of the tdd-java-ch06-tic-tac-toe-mongo Git repository (https://bitbucket.org/vfarcic/tdd-java-ch06-tic-tac-toe-mongo/branch/02-save-move). The classes in particular are TicTacToeCollectionSpec and TicTacToeCollection.

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.