@@ -3,9 +3,9 @@ package user.org.mockito
3
3
import org .mockito .captor .ArgCaptor
4
4
import org .mockito .exceptions .verification ._
5
5
import org .mockito .invocation .InvocationOnMock
6
- import org .mockito .{ArgumentMatchersSugar , IdiomaticMockito }
7
- import org .scalatest .{Matchers , WordSpec }
8
- import user .org .mockito .matchers .{ValueCaseClass , ValueClass }
6
+ import org .mockito .{ ArgumentMatchersSugar , IdiomaticMockito }
7
+ import org .scalatest .{ Matchers , WordSpec }
8
+ import user .org .mockito .matchers .{ ValueCaseClass , ValueClass }
9
9
10
10
class IdiomaticMockitoTest extends WordSpec with Matchers with IdiomaticMockito with ArgumentMatchersSugar {
11
11
@@ -36,12 +36,16 @@ class IdiomaticMockitoTest extends WordSpec with Matchers with IdiomaticMockito
36
36
def valueCaseClass (n : Int , v : ValueCaseClass ): String = ???
37
37
38
38
def returnsValueCaseClass : ValueCaseClass = ???
39
+
40
+ def baz (i : Int , b : Baz ): String = ???
39
41
}
40
42
41
43
class Bar {
42
44
def iHaveDefaultArgs (v : String = " default" ): String = v
43
45
}
44
46
47
+ case class Baz (param1 : Int , param2 : String )
48
+
45
49
" StubbingOps" should {
46
50
" stub a return value" in {
47
51
val org = mock[Org ]
@@ -119,8 +123,8 @@ class IdiomaticMockitoTest extends WordSpec with Matchers with IdiomaticMockito
119
123
org.doSomethingWithThisInt(* ) shouldAnswer ((i : Int ) => i * 10 + 2 )
120
124
org.doSomethingWithThisIntAndString(* , * ) shouldAnswer ((i : Int , s : String ) => (i * 10 + s.toInt).toString)
121
125
org.doSomethingWithThisIntAndStringAndBoolean(* , * , * ) shouldAnswer ((i : Int ,
122
- s : String ,
123
- boolean : Boolean ) => (i * 10 + s.toInt).toString + boolean)
126
+ s : String ,
127
+ boolean : Boolean ) => (i * 10 + s.toInt).toString + boolean)
124
128
125
129
org.doSomethingWithThisInt(4 ) shouldBe 42
126
130
org.doSomethingWithThisIntAndString(4 , " 2" ) shouldBe " 42"
@@ -404,7 +408,7 @@ class IdiomaticMockitoTest extends WordSpec with Matchers with IdiomaticMockito
404
408
}
405
409
406
410
" work with a captor" in {
407
- val org = mock[Org ]
411
+ val org = mock[Org ]
408
412
val argCaptor = ArgCaptor [Int ]
409
413
410
414
org.doSomethingWithThisIntAndString(42 , " test" )
@@ -441,7 +445,7 @@ class IdiomaticMockitoTest extends WordSpec with Matchers with IdiomaticMockito
441
445
442
446
" mix arguments and raw parameters" should {
443
447
" create a mock where I can mix matchers, normal and implicit parameters" in {
444
- val org = mock[Org ]
448
+ val org = mock[Org ]
445
449
implicit val implicitValue : Implicit [Int ] = mock[Implicit [Int ]]
446
450
447
451
org.iHaveTypeParamsAndImplicits[Int , String ](* , " test" ) shouldReturn " mocked!"
@@ -505,6 +509,18 @@ class IdiomaticMockitoTest extends WordSpec with Matchers with IdiomaticMockito
505
509
org.valueCaseClass(* , ValueCaseClass (200 )) was called
506
510
}
507
511
512
+ " argMatching works with new syntax" in {
513
+ val org = mock[Org ]
514
+
515
+ org.baz(2 , argMatching({ case Baz (n, _) if n > 90 => })) shouldReturn " mocked!"
516
+ org.baz(2 , Baz (100 , " pepe" )) shouldBe " mocked!"
517
+ org.baz(2 , argMatching({ case Baz (_, " pepe" ) => })) was called
518
+
519
+ an[WantedButNotInvoked ] should be thrownBy {
520
+ org.baz(2 , argMatching({ case Baz (99 , " pepe" ) => })) was called
521
+ }
522
+ }
523
+
508
524
" anyVal works with new syntax" in {
509
525
val org = mock[Org ]
510
526
0 commit comments