Skip to content

Instantly share code, notes, and snippets.

@umbreak
Last active June 6, 2019 10:10
Show Gist options
  • Save umbreak/6c2adaeb67c6488cc7f2438f9459af6f to your computer and use it in GitHub Desktop.
Save umbreak/6c2adaeb67c6488cc7f2438f9459af6f to your computer and use it in GitHub Desktop.
Mockito fails with Malformed class name when using java 8
import ExampleSpec._
import org.mockito.IdiomaticMockito
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{Matchers, WordSpecLike}
import scala.concurrent.Future
// Mockito fails with 'Malformed class name' when using java 8
class ExampleSpec extends WordSpecLike with Matchers with IdiomaticMockito with ScalaFutures {
"A example" should {
val client = mock[Client]
"run" in {
val wrapper = new ClientWrapper(client)
implicit val allowedEvidence: Allowed = Permissions.Allowed
client[Future]("a") shouldReturn Future.successful("response")
wrapper.call[Future]("a").futureValue shouldEqual "response"
}
}
}
object ExampleSpec {
sealed trait Permissions
object Permissions {
final case object Allowed extends Permissions
final case object Denied extends Permissions
}
type Allowed = Permissions.Allowed.type
class ClientWrapper(client: Client) {
def call[F[_]](field: String)(implicit ev: Allowed): F[String] = client(field)
}
trait Client {
def apply[F[_]](field: String)(implicit ev: Allowed): F[String]
}
}
import ExampleSpec._
import org.mockito.IdiomaticMockito
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{Matchers, WordSpecLike}
import scala.concurrent.Future
// Making this change, it works
class ExampleSpec extends WordSpecLike with Matchers with IdiomaticMockito with ScalaFutures {
"A example" should {
val client = mock[Client]
"run" in {
val wrapper = new ClientWrapper(client)
implicit val allowedEvidence: Allowed = Allowed
client[Future]("a") shouldReturn Future.successful("response")
wrapper.call[Future]("a").futureValue shouldEqual "response"
}
}
}
object ExampleSpec {
sealed trait Permissions
final case object Allowed extends Permissions
final case object Denied extends Permissions
type Allowed = Allowed.type
class ClientWrapper(client: Client) {
def call[F[_]](field: String)(implicit ev: Allowed): F[String] = client(field)
}
trait Client {
def apply[F[_]](field: String)(implicit ev: Allowed): F[String]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment