@@ -3,6 +3,7 @@ package scalaoauth2.provider
33import org .scalatest .Matchers ._
44import org .scalatest ._
55import org .scalatest .concurrent .ScalaFutures
6+ import org .scalatest .time ._
67
78import scala .concurrent .Future
89import scala .concurrent .ExecutionContext .Implicits .global
@@ -22,12 +23,13 @@ class AuthorizationCodeSpec extends FlatSpec with ScalaFutures with OptionValues
2223 override def createAccessToken (authInfo : AuthInfo [User ]): Future [AccessToken ] = Future .successful(AccessToken (" token1" , Some (" refreshToken1" ), Some (" all" ), Some (3600 ), new java.util.Date ()))
2324
2425 override def deleteAuthCode (code : String ): Future [Unit ] = {
26+ Thread .sleep(300 )
2527 codeDeleted = true
2628 Future .successful(Unit )
2729 }
2830 })
2931
30- whenReady(f) { result =>
32+ whenReady(f, timeout( Span ( 1 , Seconds )), interval( Span ( 50 , Millis )) ) { result =>
3133 codeDeleted shouldBe true
3234 result.tokenType shouldBe " Bearer"
3335 result.accessToken shouldBe " token1"
@@ -57,4 +59,25 @@ class AuthorizationCodeSpec extends FlatSpec with ScalaFutures with OptionValues
5759 result.scope shouldBe Some (" all" )
5860 }
5961 }
62+
63+ it should " return a Failure Future" in {
64+ val authorizationCode = new AuthorizationCode ()
65+ val request = new AuthorizationRequest (Map (), Map (" client_id" -> Seq (" clientId1" ), " client_secret" -> Seq (" clientSecret1" ), " code" -> Seq (" code1" ), " redirect_uri" -> Seq (" http://example.com/" )))
66+ val f = authorizationCode.handleRequest(request, new MockDataHandler () {
67+
68+ override def findAuthInfoByCode (code : String ): Future [Option [AuthInfo [User ]]] = Future .successful(Some (
69+ AuthInfo (user = MockUser (10000 , " username" ), clientId = Some (" clientId1" ), scope = Some (" all" ), redirectUri = Some (" http://example.com/" ))
70+ ))
71+
72+ override def createAccessToken (authInfo : AuthInfo [User ]): Future [AccessToken ] = Future .successful(AccessToken (" token1" , Some (" refreshToken1" ), Some (" all" ), Some (3600 ), new java.util.Date ()))
73+
74+ override def deleteAuthCode (code : String ): Future [Unit ] = {
75+ Future .failed(new Exception ())
76+ }
77+ })
78+
79+ whenReady(f.failed) { e =>
80+ e shouldBe a[Exception ]
81+ }
82+ }
6083}
0 commit comments