File tree 2 files changed +33
-2
lines changed
common/src/main/scala/org/mockito/matchers
scalatest/src/test/scala/user/org/mockito
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1
1
package org .mockito .matchers
2
2
3
- import org .mockito .{ ArgumentMatcher , ArgumentMatchers => JavaMatchers }
3
+ import org .mockito .{ArgumentMatcher , ArgumentMatchers => JavaMatchers }
4
+
5
+ import scala .util .Try
4
6
5
7
private [mockito] trait ThatMatchers {
6
8
@@ -16,7 +18,7 @@ private[mockito] trait ThatMatchers {
16
18
*/
17
19
def argThat [T ](f : T => Boolean , desc : => String = " argThat(<condition>)" ): T =
18
20
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 )
20
22
override def toString : String = desc
21
23
})
22
24
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