Last active
June 6, 2019 10:10
-
-
Save umbreak/6c2adaeb67c6488cc7f2438f9459af6f to your computer and use it in GitHub Desktop.
Mockito fails with Malformed class name when using java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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