@@ -569,6 +569,80 @@ func Test_Mock_UnsetIfAlreadyUnsetFails(t *testing.T) {
569
569
assert .Equal (t , 0 , len (mockedService .ExpectedCalls ))
570
570
}
571
571
572
+ func Test_Mock_UnsetByOnMethodSpec (t * testing.T ) {
573
+ // make a test impl object
574
+ var mockedService = new (TestExampleImplementation )
575
+
576
+ mock1 := mockedService .
577
+ On ("TheExampleMethod" , 1 , 2 , 3 ).
578
+ Return (0 , nil )
579
+
580
+ assert .Equal (t , 1 , len (mockedService .ExpectedCalls ))
581
+ mock1 .On ("TheExampleMethod" , 1 , 2 , 3 ).
582
+ Return (0 , nil ).Unset ()
583
+
584
+ assert .Equal (t , 0 , len (mockedService .ExpectedCalls ))
585
+
586
+ assert .Panics (t , func () {
587
+ mock1 .Unset ()
588
+ })
589
+
590
+ assert .Equal (t , 0 , len (mockedService .ExpectedCalls ))
591
+ }
592
+
593
+ func Test_Mock_UnsetByOnMethodSpecAmongOthers (t * testing.T ) {
594
+ // make a test impl object
595
+ var mockedService = new (TestExampleImplementation )
596
+
597
+ _ , filename , line , _ := runtime .Caller (0 )
598
+ mock1 := mockedService .
599
+ On ("TheExampleMethod" , 1 , 2 , 3 ).
600
+ Return (0 , nil ).
601
+ On ("TheExampleMethodVariadic" , 1 , 2 , 3 , 4 , 5 ).Once ().
602
+ Return (nil )
603
+ mock1 .
604
+ On ("TheExampleMethodFuncType" , Anything ).
605
+ Return (nil )
606
+
607
+ assert .Equal (t , 3 , len (mockedService .ExpectedCalls ))
608
+ mock1 .On ("TheExampleMethod" , 1 , 2 , 3 ).
609
+ Return (0 , nil ).Unset ()
610
+
611
+ assert .Equal (t , 2 , len (mockedService .ExpectedCalls ))
612
+
613
+ expectedCalls := []* Call {
614
+ {
615
+ Parent : & mockedService .Mock ,
616
+ Method : "TheExampleMethodVariadic" ,
617
+ Repeatability : 1 ,
618
+ Arguments : []interface {}{1 , 2 , 3 , 4 , 5 },
619
+ ReturnArguments : []interface {}{nil },
620
+ callerInfo : []string {fmt .Sprintf ("%s:%d" , filename , line + 4 )},
621
+ },
622
+ {
623
+ Parent : & mockedService .Mock ,
624
+ Method : "TheExampleMethodFuncType" ,
625
+ Arguments : []interface {}{Anything },
626
+ ReturnArguments : []interface {}{nil },
627
+ callerInfo : []string {fmt .Sprintf ("%s:%d" , filename , line + 7 )},
628
+ },
629
+ }
630
+
631
+ assert .Equal (t , 2 , len (mockedService .ExpectedCalls ))
632
+ assert .Equal (t , expectedCalls , mockedService .ExpectedCalls )
633
+ }
634
+
635
+ func Test_Mock_Unset_WithFuncPanics (t * testing.T ) {
636
+ // make a test impl object
637
+ var mockedService = new (TestExampleImplementation )
638
+ mock1 := mockedService .On ("TheExampleMethod" , 1 )
639
+ mock1 .Arguments = append (mock1 .Arguments , func (string ) error { return nil })
640
+
641
+ assert .Panics (t , func () {
642
+ mock1 .Unset ()
643
+ })
644
+ }
645
+
572
646
func Test_Mock_Return (t * testing.T ) {
573
647
574
648
// make a test impl object
0 commit comments