October 2018
Intermediate to advanced
370 pages
9h 15m
English
The set method of the ToDoStorage class can throw ToDoAlreadyExistException:
operator fun set(name: String, todo: ToDo): Boolean { if (todos.contains(name)) { throw ToDoAlreadyExistException() } todos[name] = todo return true}
It is also important to make sure that this exception will be thrown when it is needed. For this, we can write one more test that checks whether ToDoAlreadyException is thrown when a user tries to store a todo with a key that already exists.
We need to add a dependency to the kotlintest library (https://github.com/kotlintest/kotlintest) to be able to use the shouldThrow function. After integrating this library, your dependencies section in the build.gradle file will look as follows:
dependencies ...Read now
Unlock full access