Specification – clear state between games

This is a very simple application that, at least at this moment, can store only one game session. Whenever a new instance is created, we should start over and remove all data stored in the database. The easiest way to do this is to simply drop the MongoDB collection. Jongo has the MongoCollection.drop() method that can be used for that. We'll create a new method, drop, that will act in a similar way to saveMove.

If you haven't worked with Mockito, MongoDB, and/or Jongo, the chances are you were not able to do the exercises from this chapter by yourself, and just decided to follow the solutions we provided. If that's the case, this is the moment when you may want to switch gears and try to write the specifications and implementation by yourself.

We should verify that MongoCollection.drop() is invoked from our own method drop() inside the TicTacToeCollection class. Try it by yourself before looking at the following code. It should be almost the same as what we did with the save method:

@Test
public void whenDropThenInvokeMongoCollectionDrop() {
  doReturn(mongoCollection).when(collection).getMongoCollection();
  collection.drop();
  verify(mongoCollection).drop();
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.40.32