Created
August 17, 2020 16:35
-
-
Save Baztoune/e1b6ee98fbd4d013992355bc75faedad 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
import org.specs2.mock.Mockito | |
import org.specs2.mutable.Specification | |
class MyService { | |
def test(param1: String)(implicit param2: String = "ABCD"): String = s"$param1#$param2" | |
} | |
class MyServiceTest extends Specification with Mockito { | |
// DO NOT MIX MATCHERS AND LITERALS. Mockito fails with "Invalid use of argument matchers!" | |
// but default implicit curried values makes it hard to notice | |
// "Invalid use of argument matchers!" not printed because of currying+default+implicit ? | |
"mocked method" should { | |
"return expected value when arg matches literal value" in { | |
val service = mock[MyService] | |
service.test("match") returns "SUCCESS" | |
service.test("match") === "SUCCESS" // OK | |
} | |
"return expected value when arg matches any (default param matcher NOT defined)" in { | |
val service = mock[MyService] | |
service.test(anyString) returns "SUCCESS" | |
service.test("yolo") === "SUCCESS" // FAILS null != SUCCESS | |
} | |
"return expected value when arg matches any (default param matcher defined), using any[String]" in { | |
val service = mock[MyService] | |
service.test(any[String]())(any[String]()) returns "SUCCESS" | |
service.test("yolo")("123") === "SUCCESS" // Ok | |
service.test("yolo") === "SUCCESS" // OK | |
} | |
"return expected value when arg matches any (default param matcher defined), using anyString" in { | |
val service = mock[MyService] | |
service.test(anyString)(anyString) returns "SUCCESS" | |
service.test("yolo")("123") === "SUCCESS" // Ok | |
service.test("yolo") === "SUCCESS" // FAILS null != SUCCESS | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment