Created
October 27, 2016 21:01
-
-
Save agile-jordi/b585d76f01b30839e3c2da41f0326ecb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package ut | |
| import com.agilogy.talks.errorhandling.Email | |
| import com.agilogy.talks.errorhandling.extra._ | |
| import org.scalatest.FreeSpec | |
| import scala.util.{Failure, Success} | |
| class ChooseYourOwnStyleTest extends FreeSpec { | |
| val exceptionThrowingService = ChooseYourOwnStyleService(ExceptionsStyle) | |
| val tryService = ChooseYourOwnStyleService(TryStyle) | |
| val eitherService = ChooseYourOwnStyleService(EitherStyle) | |
| "ChooseYourOwnStyleService" - { | |
| "when using exception style" - { | |
| "should return unwrapped values in case of success" in { | |
| assert(exceptionThrowingService.parseEmail("[email protected]") === Email("foo","example.com")) | |
| } | |
| "shoud throw in case of an error" in{ | |
| val exc = intercept[IllegalEmail](exceptionThrowingService.parseEmail("foo")) | |
| assert(exc === IllegalEmail("foo")) | |
| } | |
| } | |
| "when using try style" - { | |
| "should return Success(value) in case of success" in { | |
| assert(tryService.parseEmail("[email protected]") === Success(Email("foo","example.com"))) | |
| } | |
| "shoud return Failure(error) in case of error" in{ | |
| assert(tryService.parseEmail("foo") === Failure(IllegalEmail("foo"))) | |
| } | |
| } | |
| "when using either style" - { | |
| "should return Right(value) in case of success" in { | |
| assert(eitherService.parseEmail("[email protected]") === Right(Email("foo","example.com"))) | |
| } | |
| "shoud return Left(error) in case of error" in{ | |
| assert(eitherService.parseEmail("foo") === Left(IllegalEmail("foo"))) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment