File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
common/src/main/scala/org/mockito/matchers
scalatest/src/test/scala/user/org/mockito Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 11package org .mockito .matchers
22
3- import org .mockito .{ ArgumentMatcher , ArgumentMatchers => JavaMatchers }
3+ import org .mockito .{ArgumentMatcher , ArgumentMatchers => JavaMatchers }
4+
5+ import scala .util .Try
46
57private [mockito] trait ThatMatchers {
68
@@ -16,7 +18,7 @@ private[mockito] trait ThatMatchers {
1618 */
1719 def argThat [T ](f : T => Boolean , desc : => String = " argThat(<condition>)" ): T =
1820 JavaMatchers .argThat(new ArgumentMatcher [T ] with Serializable {
19- override def matches (argument : T ): Boolean = f(argument)
21+ override def matches (argument : T ): Boolean = Try ( f(argument)).fold(_ => false , identity )
2022 override def toString : String = desc
2123 })
2224
Original file line number Diff line number Diff line change 1+ package user .org .mockito
2+
3+ import org .scalatest .matchers .should .Matchers
4+ import org .scalatest .wordspec .AnyWordSpec
5+ import org .mockito .{ ArgumentMatchersSugar , IdiomaticMockito , MockitoScalaSession }
6+ import IdiomaticMockito ._
7+ import ArgumentMatchersSugar ._
8+
9+
10+
11+ class Issue256 extends AnyWordSpec with Matchers {
12+
13+ trait Foo {
14+ def test [A ](a : A ): A
15+ }
16+
17+ " mockito" should {
18+ " allow stubbing the same method multiple times" in {
19+ MockitoScalaSession ().run {
20+ val foo = mock[Foo ]
21+ foo.test[String ](argThat((s : String ) => s.startsWith(" foo" ))) returns " foo"
22+ foo.test[Int ](argThat((n : Int ) => n > 10 )) returns 42
23+
24+ foo.test(" fooSSS" ) shouldBe " foo"
25+ foo.test(11 ) shouldBe 42
26+ }
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments