|
Play Framework/Scala example source code file (BindersSpec.scala)
The BindersSpec.scala Play Framework example source code/* * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> */ package play.api.mvc import java.util.UUID import org.specs2.mutable._ object BindersSpec extends Specification { val uuid = UUID.randomUUID "UUID path binder" should { val subject = implicitly[PathBindable[UUID]] "Unbind UUID as string" in { subject.unbind("key", uuid) must be_==(uuid.toString) } "Bind parameter to UUID" in { subject.bind("key", uuid.toString) must be_==(Right(uuid)) } "Fail on unparseable UUID" in { subject.bind("key", "bad-uuid") must be_==(Left("Cannot parse parameter key as UUID: Invalid UUID string: bad-uuid")) } } "UUID query string binder" should { val subject = implicitly[QueryStringBindable[UUID]] "Unbind UUID as string" in { subject.unbind("key", uuid) must be_==("key=" + uuid.toString) } "Bind parameter to UUID" in { subject.bind("key", Map("key" -> Seq(uuid.toString))) must be_==(Some(Right(uuid))) } "Fail on unparseable UUID" in { subject.bind("key", Map("key" -> Seq("bad-uuid"))) must be_==(Some(Left("Cannot parse parameter key as UUID: Invalid UUID string: bad-uuid"))) } } "URL Path string binder" should { val subject = implicitly[PathBindable[String]] val pathString = "/path/to/some%20file" val pathStringBinded = "/path/to/some file" "Unbind Path string as string" in { subject.unbind("key", pathString) must equalTo(pathString) } "Bind Path string as string without any decoding" in { subject.bind("key", pathString) must equalTo(Right(pathString)) } } "QueryStringBindable.bindableString" should { "unbind with null values" in { import QueryStringBindable._ val boundValue = bindableString.unbind("key", null) boundValue must beEqualTo("key=") } } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework BindersSpec.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.