@@ -3,6 +3,7 @@ package scalaoauth2.provider
3
3
import org .scalatest .Matchers ._
4
4
import org .scalatest ._
5
5
import org .scalatest .concurrent .ScalaFutures
6
+ import org .scalatest .time ._
6
7
7
8
import scala .concurrent .Future
8
9
import scala .concurrent .ExecutionContext .Implicits .global
@@ -22,12 +23,13 @@ class AuthorizationCodeSpec extends FlatSpec with ScalaFutures with OptionValues
22
23
override def createAccessToken (authInfo : AuthInfo [User ]): Future [AccessToken ] = Future .successful(AccessToken (" token1" , Some (" refreshToken1" ), Some (" all" ), Some (3600 ), new java.util.Date ()))
23
24
24
25
override def deleteAuthCode (code : String ): Future [Unit ] = {
26
+ Thread .sleep(300 )
25
27
codeDeleted = true
26
28
Future .successful(Unit )
27
29
}
28
30
})
29
31
30
- whenReady(f) { result =>
32
+ whenReady(f, timeout( Span ( 1 , Seconds )), interval( Span ( 50 , Millis )) ) { result =>
31
33
codeDeleted shouldBe true
32
34
result.tokenType shouldBe " Bearer"
33
35
result.accessToken shouldBe " token1"
@@ -57,4 +59,25 @@ class AuthorizationCodeSpec extends FlatSpec with ScalaFutures with OptionValues
57
59
result.scope shouldBe Some (" all" )
58
60
}
59
61
}
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
+ }
60
83
}
0 commit comments