@@ -19,11 +19,14 @@ package query.interpolator
1919
2020import java .nio .ByteBuffer
2121
22- import cats .MonadError
22+ import cats .{ ~> , MonadError }
2323import com .datastax .driver .core ._
2424import com .google .common .util .concurrent .ListenableFuture
25+ import freestyle .async .AsyncContext
2526import freestyle .cassandra .TestUtils ._
27+ import freestyle .cassandra .api .{apiInterpreter , SessionAPI }
2628import freestyle .cassandra .codecs .ByteBufferCodec
29+ import freestyle .cassandra .handlers .implicits .sessionAPIHandler
2730import org .scalamock .scalatest .MockFactory
2831import org .scalatest .{Matchers , OneInstancePerTest , WordSpec }
2932
@@ -36,23 +39,24 @@ class InterpolatorImplicitSpec
3639 with OneInstancePerTest
3740 with MockFactory {
3841
42+ import RuntimeCQLInterpolator ._
43+ import freestyle .cassandra .query .interpolator ._
44+
45+ import freestyle .async .implicits ._
46+ import scala .concurrent .ExecutionContext .Implicits .global
47+
48+ implicit val E : MonadError [Future , Throwable ] =
49+ cats.instances.future.catsStdInstancesForFuture
50+
3951 implicit val sessionMock : Session = stub[Session ]
4052
4153 val rsMock : ResultSet = stub[ResultSet ]
4254 (sessionMock.executeAsync(_ : Statement )).when(* ).returns(ResultSetFutureTest (rsMock))
4355
44- " InterpolatorImplicitDef asResultSet" should {
45-
46- import RuntimeCQLInterpolator ._
47- import freestyle .async .implicits ._
48- import freestyle .cassandra .query .interpolator ._
49- import scala .concurrent .ExecutionContext .Implicits .global
50-
51- implicit val E : MonadError [Future , Throwable ] =
52- cats.instances.future.catsStdInstancesForFuture
56+ " InterpolatorImplicitDef attemptResultSet" should {
5357
5458 " return a valid ResultSet" in {
55- val future : Future [ResultSet ] = cql " SELECT * FROM users " .asResultSet [Future ]
59+ val future : Future [ResultSet ] = cql " SELECT * FROM users " .attemptResultSet [Future ]
5660 Await .result(future, Duration .Inf ) shouldBe rsMock
5761 }
5862
@@ -67,11 +71,25 @@ class InterpolatorImplicitSpec
6771 implicit E : MonadError [M , Throwable ]): M [ByteBuffer ] =
6872 E .raiseError(serializeException)
6973 }
70- val name : String = " UserName"
71- val future : Future [ResultSet ] = cql " SELECT * FROM users WHERE name= $name" .asResultSet[Future ]
74+ val name : String = " UserName"
75+ val future : Future [ResultSet ] =
76+ cql " SELECT * FROM users WHERE name= $name" .attemptResultSet[Future ]
7277 Await .result(future.failed, Duration .Inf ) shouldBe serializeException
7378 }
7479
7580 }
7681
82+ " InterpolatorImplicitDef asResultSet" should {
83+
84+ implicit val interpreter = sessionAPIHandler[Future ] andThen apiInterpreter[Future , Session ](
85+ sessionMock)
86+
87+ " return a valid ResultSet from a FreeS" in {
88+ val future : Future [ResultSet ] =
89+ cql " SELECT * FROM users " .asResultSet[SessionAPI .Op ].interpret[Future ]
90+ Await .result(future, Duration .Inf ) shouldBe rsMock
91+ }
92+
93+ }
94+
7795}
0 commit comments