Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import ExampleSpec._
  2. import org.mockito.IdiomaticMockito
  3. import org.scalatest.concurrent.ScalaFutures
  4. import org.scalatest.{Matchers, WordSpecLike}
  5.  
  6. import scala.concurrent.Future
  7.  
  8. // Mockito fails with 'Malformed class name' when using java 8
  9. class ExampleSpec extends WordSpecLike with Matchers with IdiomaticMockito with ScalaFutures {
  10.  
  11. "A example" should {
  12. val client = mock[Client]
  13.  
  14. "run" in {
  15. val wrapper = new ClientWrapper(client)
  16. implicit val allowedEvidence: Allowed = Permissions.Allowed
  17. client[Future]("a") shouldReturn Future.successful("response")
  18. wrapper.call[Future]("a").futureValue shouldEqual "response"
  19. }
  20. }
  21. }
  22.  
  23. object ExampleSpec {
  24.  
  25. sealed trait Permissions
  26. object Permissions {
  27. final case object Allowed extends Permissions
  28. final case object Denied extends Permissions
  29. }
  30. type Allowed = Permissions.Allowed.type
  31.  
  32. class ClientWrapper(client: Client) {
  33. def call[F[_]](field: String)(implicit ev: Allowed): F[String] = client(field)
  34. }
  35.  
  36. trait Client {
  37. def apply[F[_]](field: String)(implicit ev: Allowed): F[String]
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement