October 2016
Intermediate to advanced
198 pages
3h 52m
English
By including the EitherValue trait in our mixin, we get an implicit conversion of the Either monad. This implicit conversion adds a value method to both left and right of Either. This allows us to do a left.value and right.value. The value method either returns the selected value from a defined Either or alternatively throws a TestFailedException in case the Either is not defined.
Using this, we are able to test in a single expression, both that the Either should be left or right (that is, it is defined) and also that it has a certain expected value. Let's look at an example:
firstEither.right.value should be < 5
secondEither.left.value should be ("Big Ploblemo!")The same can be done using assertions:
assert(firstEither.right.value ...
Read now
Unlock full access