@@ -462,6 +462,87 @@ func Test_Mock_On_WithFuncTypeArg(t *testing.T) {
462
462
})
463
463
}
464
464
465
+ func Test_Mock_Unset (t * testing.T ) {
466
+ // make a test impl object
467
+ var mockedService = new (TestExampleImplementation )
468
+
469
+ call := mockedService .
470
+ On ("TheExampleMethodFuncType" , "argA" ).
471
+ Return ("blah" )
472
+
473
+ found , foundCall := mockedService .findExpectedCall ("TheExampleMethodFuncType" , "argA" )
474
+ require .NotEqual (t , - 1 , found )
475
+ require .Equal (t , foundCall , call )
476
+
477
+ call .Unset ()
478
+
479
+ found , foundCall = mockedService .findExpectedCall ("TheExampleMethodFuncType" , "argA" )
480
+ require .Equal (t , - 1 , found )
481
+
482
+ var expectedCall * Call
483
+ require .Equal (t , expectedCall , foundCall )
484
+
485
+ fn := func (string ) error { return nil }
486
+ assert .Panics (t , func () {
487
+ mockedService .TheExampleMethodFuncType (fn )
488
+ })
489
+ }
490
+
491
+ // Since every time you call On it creates a new object
492
+ // the last time you call Unset it will only unset the last call
493
+ func Test_Mock_Chained_UnsetOnlyUnsetsLastCall (t * testing.T ) {
494
+ // make a test impl object
495
+ var mockedService = new (TestExampleImplementation )
496
+
497
+ // determine our current line number so we can assert the expected calls callerInfo properly
498
+ _ , _ , line , _ := runtime .Caller (0 )
499
+ mockedService .
500
+ On ("TheExampleMethod1" , 1 , 1 ).
501
+ Return (0 ).
502
+ On ("TheExampleMethod2" , 2 , 2 ).
503
+ On ("TheExampleMethod3" , 3 , 3 , 3 ).
504
+ Return (nil ).
505
+ Unset ()
506
+
507
+ expectedCalls := []* Call {
508
+ {
509
+ Parent : & mockedService .Mock ,
510
+ Method : "TheExampleMethod1" ,
511
+ Arguments : []interface {}{1 , 1 },
512
+ ReturnArguments : []interface {}{0 },
513
+ callerInfo : []string {fmt .Sprintf ("mock_test.go:%d" , line + 2 )},
514
+ },
515
+ {
516
+ Parent : & mockedService .Mock ,
517
+ Method : "TheExampleMethod2" ,
518
+ Arguments : []interface {}{2 , 2 },
519
+ ReturnArguments : []interface {}{},
520
+ callerInfo : []string {fmt .Sprintf ("mock_test.go:%d" , line + 4 )},
521
+ },
522
+ }
523
+ assert .Equal (t , 2 , len (expectedCalls ))
524
+ assert .Equal (t , expectedCalls , mockedService .ExpectedCalls )
525
+ }
526
+
527
+ func Test_Mock_UnsetIfAlreadyUnsetFails (t * testing.T ) {
528
+ // make a test impl object
529
+ var mockedService = new (TestExampleImplementation )
530
+
531
+ mock1 := mockedService .
532
+ On ("TheExampleMethod1" , 1 , 1 ).
533
+ Return (1 )
534
+
535
+ assert .Equal (t , 1 , len (mockedService .ExpectedCalls ))
536
+ mock1 .Unset ()
537
+ assert .Equal (t , 0 , len (mockedService .ExpectedCalls ))
538
+
539
+ assert .Panics (t , func () {
540
+ mock1 .Unset ()
541
+ })
542
+
543
+ assert .Equal (t , 0 , len (mockedService .ExpectedCalls ))
544
+ }
545
+
465
546
func Test_Mock_Return (t * testing.T ) {
466
547
467
548
// make a test impl object
0 commit comments