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
| public abstract class Comment | |
| { | |
| public static ProposedComment Parse(String proposedComment) | |
| { | |
| return new ProposedComment(proposedComment); | |
| } | |
| } | |
| public class ProposedComment : Comment | |
| { |
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
| lazy val form = Form(mapping( | |
| "name" -> nonEmptyText, | |
| "age" -> number, | |
| "favouriteColour" -> mandatoryIf( | |
| isEqual("name", "Francoise") and isEqual("age", "21"), | |
| nonEmptyText | |
| ) | |
| )(Model.apply)(Model.unapply)) |
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
| behavior of "conditional mappings" | |
| it should "contain field level errors for fields using conditional mappings" in { | |
| val data = Map("nonUkResident" -> "true") | |
| val res = form.bind(data) | |
| assert(res.errors.length == 2) | |
| assert(res.errors.head.key === "country") | |
| assert(res.errors.tail.head.key === "email") | |
| } |
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
| behavior of "vanilla play conditional mapping" | |
| it should "not contain an error for the conditional validation when there is a field-level error" in { | |
| val data = Map("nonUkResident" -> "true") | |
| val res = form.bind(data) | |
| assert(res.errors.length == 1) | |
| assert(res.errors.head.key === "email") | |
| } |
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
| class SetExample extends FreeSpec with Matchers { | |
| val userEmail = "abc@mailinator.com" | |
| var sentEmailTo = "NOTSENT" | |
| "When the winner is selected they are immediately notified by email" in { | |
| SelectWinnerOfCompetition(ret(userEmail), set(sentEmailTo = _))() | |
| assert(sentEmailTo === userEmail) | |
| } | |
| def ret[A](a: A): Unit => A = _ => a |
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
| def retF[A,B](a: A)(b: B): A => Future[B] = | |
| x => if (x == a) Future.successful(b) else throw ReturnFailed(s"$x did not equal $a") |
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
| // return the stubbed value if the actual arguments match the expected arguments | |
| def ret[A,B](a: A)(b: B): A => B = | |
| x => if (x == a) b else throw ReturnFailed(s"$x did not equal $a") | |
| def ret[A,B,C](a: A, b: B)(c: C): (A,B) => C = | |
| (x, y) => if (x == a && y == b) c else throw ReturnFailed(s"$x and $y did not equal $a and $b") |
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
| class TestWithoutMocks extends FreeSpec with Matchers with FutureAwaits with DefaultAwaitTimeout { | |
| val userId = "12345" | |
| val user = User(userId) | |
| val friend = User("friendId") | |
| val friendsDetails = NewAccountDetails("abc@mailinator.com", "abb", 1) | |
| val results = Seq(PromoteToGoldStatus(userId)) | |
| "When an existing user" - { | |
| "recommends a friend using details that validate" - { | |
| "the friend is created and the referral policy's decision is returned" in { |
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
| class RecommendAFriendSpecs extends FreeSpec with Matchers with FutureAwaits with DefaultAwaitTimeout { | |
| val repo = mock(classOf[UserRepository]) | |
| val validator = mock(classOf[NewAccountValidator]) | |
| val policy = mock(classOf[ReferralPolicy]) | |
| val userId = "12345" | |
| val user = User(userId) | |
| val friend = User("friendId") | |
| val friendsDetails = NewAccountDetails("abc@mailinator.com", "abb", 1) | |
| val results = Seq(PromoteToGoldStatus(userId)) |
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
| v(n) map { err } getOrElse { f(u) .. |
NewerOlder