Created
June 1, 2021 14:33
-
-
Save xuwei-k/b6fe2a5491d90b5006d2080c9626b95c to your computer and use it in GitHub Desktop.
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
scalaVersion := "3.0.0" | |
libraryDependencies += "org.mockito" % "mockito-core" % "3.10.0" |
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 org.mockito.ArgumentMatchers | |
import org.mockito.Mockito | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val mock = Mockito.mock(classOf[Option[Int]]) | |
Mockito.when(mock.get).thenReturn("aaa") | |
val x = mock.get | |
println(x) | |
} | |
} |
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
Main.scala:7:39: type mismatch; | |
[error] found : String("aaa") | |
[error] required: Int | |
[error] Mockito.when(mock.get).thenReturn("aaa") | |
[error] ^ |
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
[info] running (fork) Main | |
[error] Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer | |
[error] at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:99) | |
[error] at Main$.main(Main.scala:8) | |
[error] at Main.main(Main.scala) | |
[error] Nonzero exit code returned from runner: 1 | |
[error] (Compile / run) Nonzero exit code returned from runner: 1 |
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
def main(args: Array[String]): Unit = | |
{ | |
val mock: Option[Int] = | |
org.mockito.Mockito.mock[Option[Int]](classOf[Option[Int]]) | |
org.mockito.Mockito.when[Matchable](mock.get).thenReturn("aaa") | |
val x: Int = mock.get | |
println(x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment